From 83da3fefef36c9341513244af33ee2a11c59e48c Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Wed, 17 Aug 2016 22:55:52 +0200 Subject: [PATCH] Added JIRA agile sprint completion --- server.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ try.html | 7 +++++++ 2 files changed, 63 insertions(+) diff --git a/server.js b/server.js index a58e1d7..60e167a 100644 --- a/server.js +++ b/server.js @@ -352,6 +352,62 @@ cache(function (data, match, sendBadge, request) { }); })); +// JIRA agile sprint completion integration +camp.route(/^\/jira\/sprint\/(http(?:s)?)\/(.+)\/([^\/]+)\.(svg|png|gif|jpg|json)$/, +cache(function (data, match, sendBadge, request) { + var protocol = match[1]; // eg, https + var host = match[2]; // eg, jira.spring.io + var sprintId = match[3]; // eg, 94 + var format = match[4]; // eg, png + + var options = { + method: 'GET', + json: true, + uri: protocol + '://' + host + '/rest/api/2/search?jql=sprint='+sprintId+'%20AND%20type%20IN%20(Bug,Improvement,Story,"Technical%20task")&fields=resolution&maxResults=500' + }; + if (serverSecrets && serverSecrets.jira_username) { + options.auth = { + user: serverSecrets.jira_username, + pass: serverSecrets.jira_password + }; + } + + var badgeData = getBadgeData('completion', data); + request(options, function (err, res, json) { + if (err != null) { + badgeData.text[1] = 'inaccessible'; + sendBadge(format, badgeData); + return; + } + try { + if (json && json.total >= 0) { + var issuesDone = json.issues.filter(function (el) { + if (el.fields.resolution != null) { + return el.fields.resolution.name !== "Unresolved"; + } + }).length; + badgeData.text[1] = Math.round(issuesDone * 100 / json.total) + "%"; + switch(issuesDone) { + case 0: + badgeData.colorscheme = 'red'; + break; + case json.total: + badgeData.colorscheme = 'brightgreen'; + break; + default: + badgeData.colorscheme = 'orange'; + } + } else { + badgeData.text[1] = 'invalid'; + } + sendBadge(format, badgeData); + } catch (e) { + badgeData.text[1] = 'invalid'; + sendBadge(format, badgeData); + } + }); +})); + // Travis integration camp.route(/^\/travis(-ci)?\/([^\/]+\/[^\/]+)(?:\/(.+))?\.(svg|png|gif|jpg|json)$/, cache(function(data, match, sendBadge, request) { diff --git a/try.html b/try.html index c3f502c..617b39d 100644 --- a/try.html +++ b/try.html @@ -834,6 +834,10 @@ Pixel-perfect   Retina-ready   Fast   Consistent   Hackable https://img.shields.io/jira/issue/https/issues.apache.org/jira/KAFKA-2896.svg + JIRA sprint completion: + + https://img.shields.io/jira/sprint/https/jira.spring.io/94.svg + Maintenance: https://img.shields.io/maintenance/yes/2016.svg @@ -1149,6 +1153,9 @@ is where the current server got started. to add Shields as a GitHub application on your GitHub account.

+
+

To get the Sprint ID, go to your Backlog view in your project, right click on your sprint name and get the value of data-sprint-id.

+