Created
February 2, 2024 13:37
-
-
Save ryan-nauman/3dd945d8657e3192039a76e7f4d0b245 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Name: Jira Search | |
import '@johnlindquist/kit'; | |
import { adfConvert } from '../lib/adf-convert'; | |
import { encodeToBase64Node } from '../lib/base64'; | |
import { Jira } from '../lib/jira'; | |
const ATLASSIAN_EMAIL = await env('ATLASSIAN_EMAIL', async () => { | |
return await arg('Enter your jira email address'); | |
}); | |
const ATLASSIAN_TOKEN = await env('ATLASSIAN_TOKEN', async () => { | |
return await arg('Enter your jira api token'); | |
}); | |
const BROWSE_ISSUE_URL_PREFIX = 'https://studio-x.atlassian.net/browse/'; | |
const SEARCH_API_PREFIX = 'https://studio-x.atlassian.net/rest/api/3/search'; | |
const searchMethod = await arg('How would you like to search jira?', [ | |
{ name: 'Text search', value: 'text' }, | |
{ name: 'Key (e.g. VOLT-1)', value: 'key' }, | |
{ name: 'JQL (e.g. project = VOLT)', value: 'jql' }, | |
]); | |
const searchQuery = await arg('Enter the search value'); | |
let jql; | |
switch (searchMethod) { | |
case 'text': | |
jql = `text ~ "${searchQuery}"`; | |
break; | |
case 'key': | |
jql = `key = ${searchQuery}`; | |
break; | |
case 'jql': | |
jql = searchQuery; | |
break; | |
} | |
let { data } = await post<Jira>( | |
`${SEARCH_API_PREFIX}`, | |
{ | |
jql, | |
maxResults: 10, | |
fields: ['summary', 'assignee', 'creator', 'description'], | |
fieldsByKeys: false, | |
}, | |
{ | |
headers: { | |
Authorization: `Basic ${encodeToBase64Node( | |
`${ATLASSIAN_EMAIL}:${ATLASSIAN_TOKEN}`, | |
)}`, | |
}, | |
}, | |
); | |
let issueKey = await arg( | |
`Select Issue:`, | |
data.issues.map(({ fields, key }) => { | |
return { | |
name: key, | |
description: fields.summary, | |
value: key, | |
preview: () => { | |
const adf = adfConvert(fields?.description); | |
return md(`# ${key} ${fields?.summary} | |
🧑🍳 ${fields?.assignee?.displayName || 'Unassigned'} | |
📖 ${fields?.creator?.displayName || 'Unknown'} | |
#### Description | |
${adf} | |
`); | |
}, | |
}; | |
}), | |
); | |
await $`open ${BROWSE_ISSUE_URL_PREFIX}${issueKey}`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment