Skip to content

Instantly share code, notes, and snippets.

@rayburgemeestre
Last active February 17, 2021 12:54
Show Gist options
  • Save rayburgemeestre/e2a4ed179d0820c0e8d4 to your computer and use it in GitHub Desktop.
Save rayburgemeestre/e2a4ed179d0820c0e8d4 to your computer and use it in GitHub Desktop.
Tampermonkey jira priority
// ==UserScript==
// @name Visualize issue ranks in the Jira Agile board
// @namespace http://cppse.nl
// @version 2.0
// @description It will search for the ranks using an Ajax Jira API call with two seconds in between
// and update the board with colored rank indicators.
// @author Ray Burgemeetre
// @match https://*.atlassian.net/secure/RapidBoard.jspa*
// @grant none
// ==/UserScript==
(function () {
var // Your project settings
jiraDomain = 'persgroep.atlassian.net',
jiraProject = 'AT'.replace(/'/g, "\\'"),
// The JQL for fetching the ranks
jql = "project = '" + jiraProject + "' and sprint in openSprints() and status != 'Done' order by Rank",
// Only fetch top X issues, you can cap this if performance is too slow for your project
maxIssues = 999,
// Other settings
colors = ['red', 'orange', 'yellow'],
fallbackColor = '#ededed';
function updateRanksInBoard()
{
$.ajax({
url : "//" + jiraDomain + "/rest/api/latest/search?jql=" + escape(jql) + "&startAt=0&maxResults=" + parseInt(maxIssues),
type : "GET",
dataType : "json",
contentType : "application/json",
success : function(response)
{
var ranks = {}, issues = document.querySelectorAll('.ghx-issue'), key, color, rankBoxEl, rankEl, tmp;
// Create lookup for ranks per issue key
for (var i in response['issues']) {
ranks[response['issues'][i]['key']] = parseInt(i) + 1;
}
// Visualize them in a small box for each issue
for (var i=0; i<issues.length; i++) {
key = issues[i].getAttribute('data-issue-key');
if (!ranks[key]) continue;
color = colors[ranks[key] - 1] || fallbackColor;
// Create rank cornered indicator if it doesn't exist yet
rankEl = issues[i].querySelector('.ghx-end').querySelector('.my-rank');
if (!rankEl) {
rankBoxEl = document.createElement('div');
rankBoxEl.className = 'ghx-corner';
rankEl = document.createElement('span');
rankEl.className = 'aui-badge my-rank';
rankBoxEl.appendChild(rankEl);
issues[i].querySelector('.ghx-end').appendChild(rankBoxEl);
}
// Populate indicator
rankEl.style.backgroundColor = color;
rankEl.innerHTML = ranks[key];
// Squeeze them to fit
tmp = issues[i].querySelector('.ghx-end').querySelectorAll('.ghx-corner');
for (var j=0; j<tmp.length; j++) {
tmp[j].style.float = 'left';
}
}
// Periodically update ranks
setTimeout(updateRanksInBoard, 2000);
},
error : function(jqXHR, textStatus, errorThrown)
{
console.log(textStatus + " : " + errorThrown);
// Periodically update ranks
setTimeout(updateRanksInBoard, 2000);
}
});
}
window.onload = function ()
{
updateRanksInBoard();
}
})();
@EightArmCode
Copy link

Hey Ray! I had to add a line to import jquery, because this script broke over here at AT. If you feel like updating it, add the following at ln 12:

// @require https://code.jquery.com/jquery-1.11.3.min.js

@EightArmCode
Copy link

FYI ->Actually, this fix apparently doesn't work in FF with grease monkey. I'll update you with further changes if I can find them.

@rayburgemeestre
Copy link
Author

Hi Kat, Thanks! I've refactored out the $.ajax() call, hopefully that will work better. Thanks :)

@rayburgemeestre
Copy link
Author

I also made it a little more generic/robust hopefully (and project independant, hope it still works for AutoTrack?) updating should be possible via Tampermonkey itself. I needed a few changes to get it to work on another Jira 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment