Last active
August 6, 2020 03:22
-
-
Save nearbycoder/939171ac8851232560fa2a6befc483b9 to your computer and use it in GitHub Desktop.
Espanso Jira Ticket Expander
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
const fetch = require('node-fetch'); | |
require('dotenv').config({ path: `${__dirname}/.env` }); | |
/* | |
* .yml setup | |
* - trigger: ":jira" | |
replace: "{{output}}" | |
passive_only: true | |
vars: | |
- name: output | |
type: script | |
params: | |
inject_args: true | |
args: | |
- node | |
- :pathToScript | |
* | |
* Usage | |
* | |
* :jira/:ticketNumber/ | |
* or | |
* :jira/:ticketNumber/d | |
* ^ includes description | |
* | |
*/ | |
const args = process.argv.slice(2); | |
const domain = 'https://domain.atlassian.net'; | |
const board = 'BLAH'; | |
const pointsField = 'customfield_10023'; | |
function jiraTicket(data) { | |
const ticket = `${board}-${args[0]}`; | |
const points = `${ | |
data.field[pointsField] ? `(${data.fields[pointsField]}pts)` : '' | |
}`; | |
const ticketUrl = `${domain}/browse/${board}-${args[0]}`; | |
const showDescription = `${args[1] === 'd' ? data.fields.description : ''}`; | |
return `${ticket} ${data.fields.summary} ${points}\n${ticketUrl}\n\n${showDescription}`; | |
} | |
fetch(`${domain}/rest/api/latest/issue/${board}-${args[0]}`, { | |
headers: { | |
Authorization: `Basic ${Buffer.from( | |
`${process.env.USERNAME}:${process.env.PASSWORD}` | |
).toString('base64')}`, | |
}, | |
}) | |
.then((res) => res.json()) | |
.then((data) => { | |
console.log(jiraTicket(data)); | |
}) | |
.catch((err) => console.log('ticket not found')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment