Jira sprint query sample


Just remember to add ‘includeFutureSprints=true‘ if you need to find out the future Sprint. By default, it is only up to current Active sprint. Here is a nodejs 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)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s