Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.