Skip to content

Instantly share code, notes, and snippets.

@jc1518
Created July 8, 2019 12:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jc1518/8c0605f9620b976d6ceede659d5b280c to your computer and use it in GitHub Desktop.
Jira sprint query sample
/*
* Jira sprint query sample
* Find out current sprint and next sprint
*/
'use strict'
const Promise = require('promise')
const request = require('request')
const lodash = require('lodash')
let options = {
headers: { "Content-Type": "application/json" },
auth: {
user: process.env.USERNAME,
password: process.env.PASSWORD
}
};
function findSprints (jiraURL, rapidViewId) {
return new Promise(function (resolve, reject) {
options.url = jiraURL + '/rest/greenhopper/1.0/sprintquery/' + rapidViewId + '?includeFutureSprints=true'
request.get (options, function(err, res, sprints) {
if (err) {
reject(err)
} else {
resolve(sprints)
}
})
})
}
async function printSprints (jiraURL, rapidViewId) {
const sprints = await findSprints(jiraURL, rapidViewId)
const activeSprint = lodash.filter(sprints.sprints, { state: 'ACTIVE' })
const activeSprintId = activeSprint[0].id
const activeSprintName = activeSprint[0].name
const nextSprintId = sprints.sprints[sprints.sprints.indexOf(activeSprint[0]) + 1].id
const nextSprintName = sprints.sprints[sprints.sprints.indexOf(activeSprint[0]) + 1].name
console.log('Current sprint is:', activeSprintId, activeSprintName)
console.log('Next sprint is:', nextSprintId, nextSprintName)
}
const jiraURL = process.env.JIRA
const rapidViewId = '12345'
printSprints(jiraURL, rapidViewId)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment