JIRA JQL Query Script: Easily Search and View Issues in Your JIRA Instance

This script allows the user to run a JIRA JQL (Jira Query Language) query and display the results. The script prompts the user to enter a JQL query, or it uses a default query that searches for all issues assigned to the current user that are not closed or marked as "Done" or "Development Done", and orders the results by the date they were created. The script then uses the JIRA API to perform the search and display the results in a list format. The user can select one of the issues from the list and the script will open the selected issue in the browser. The script requires the user to set the JIRA_HOST, JIRA_USERNAME, and JIRA_PWD environment variables to connect to their JIRA instance

Open with ScriptKIT

// Name: JIRA
// Description: Run JQL query
// Author: Orhan Erday
// Twitter: @orhan_erday
import "@johnlindquist/kit"
let jql = await arg("Enter the JQL, or press enter if you want to get Your work.")
if (jql == "") {
jql = `assignee=currentUser() and status != Closed and status != "Done" and status != "Development Done" order by created DESC`
}
let jira = {
host: await env("JIRA_HOST", "example.atlassian.net"),
jql: jql
}
let response = await get(`https://${jira.host}/rest/api/2/search?jql=${jira.jql}`, {
auth: {
username: await env("JIRA_USERNAME"),
password: await env("JIRA_PWD")
}
})
// inspect(response.data.issues)
let key = await arg(
`Select JIRA:`,
response.data.issues.map(({
fields,
key
}) => {
return {
name: key,
description: fields.summary,
value: key,
preview: async () => {
return md(
`
# ${fields.summary}
## Description
${fields.description}
## Issue Type
${fields.parent.fields.status.name}
## Status
${fields.parent.fields.issuetype.name} `)
},
}
})
)
await $`start https://${jira.host}/browse/${key}`