Skip to content

Instantly share code, notes, and snippets.

@lukepothier
Last active November 2, 2021 18:41
Show Gist options
  • Save lukepothier/5c02b3dcfaf502c8ad273e165cc7e4d6 to your computer and use it in GitHub Desktop.
Save lukepothier/5c02b3dcfaf502c8ad273e165cc7e4d6 to your computer and use it in GitHub Desktop.
Tampermonkey script which changes Jira ticket 'lozenges' to more accurately relay the state of the ticket based on the states of the subtasks. You may need to change the match or the text filters depending on your project set-up.
// ==UserScript==
// @name Jira Swimlane Status Helper
// @namespace http://tampermonkey.net/
// @version 1.0.0
// @description Change text and colour of Jira 'lozenges' on the Rapid Board to more accurately reflect the state of each ticket
// @author Luke Pothier <[email protected]>
// @match https://*.atlassian.net/jira*
// @grant none
// ==/UserScript==
(function() {
'use strict';
setInterval(() => {
let headerElements = document.getElementsByClassName('ghx-column-header-flex-1');
let headers = [];
for (let i = 0; i < headerElements.length; i++)
{
headers.push(headerElements[i].textContent.trim());
}
let pool = document.getElementById('ghx-pool');
let tickets = pool.querySelectorAll('div.ghx-swimlane');
let dict = {}
for (let i = 0; i < tickets.length; i++) {
let headerContainer = tickets[i].querySelector('div.ghx-swimlane-header').querySelector('.ghx-parent-key');
let lozenge = tickets[i].querySelector('span.jira-issue-status-lozenge');
if (!headerContainer || !lozenge) { break; }
let key = headerContainer.textContent.trim();
let columnsContainer = tickets[i].querySelector('ul.ghx-columns');
let lanes = columnsContainer.childNodes;
dict[key] = [];
for (let j = 0; j < lanes.length; j++)
{
let count = lanes[j].querySelector('div.ghx-wrap-issue').childNodes.length;
if (count > 0) {
dict[key].push(headers[j]);
}
}
if (dict[key].includes('In Progress')) {
updateLozenge(lozenge, 'In Progress', '#0D47A1', '#90CAF9');
} else if (dict[key].includes('To Do')) {
if (dict[key].length === 1) {
updateLozenge(lozenge, 'To Do', '#424242', '#E0E0E0');
} else {
// When some tasks are To Do and others aren't, the ticket is In Progress
updateLozenge(lozenge, 'In Progress', '#0D47A1', '#90CAF9');
}
} else if (dict[key].includes('In Review')) {
updateLozenge(lozenge, 'In Review', '#6A1B9A', '#CE93D8');
} else if (dict[key].includes('Blocked')) {
updateLozenge(lozenge, 'Blocked', '#D50000', '#EF9A9A');
} else if (dict[key].includes('Done')) {
updateLozenge(lozenge, 'Done', '#1B5E20', '#00C853');
}
}
}, 2000);
})();
function updateLozenge(lozenge, text, dark, light) {
lozenge.textContent = text;
lozenge.setAttribute('data-tooltip', '<span class=&quot;jira-issue-status-tooltip-title&quot;>' + text.toUpperCase() + '</span>');
lozenge.style.color = dark;
lozenge.style.borderColor = dark;
lozenge.style.backgroundColor = light;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment