Skip to content

Instantly share code, notes, and snippets.

@mslattery-lilly
Last active May 10, 2020 20:30
Show Gist options
  • Save mslattery-lilly/91b2cf4bca89d32eb937b6927677de47 to your computer and use it in GitHub Desktop.
Save mslattery-lilly/91b2cf4bca89d32eb937b6927677de47 to your computer and use it in GitHub Desktop.
GitHub / Jira Integration
// ==UserScript==
// @name GitHub-Jira
// @version 0.1
// @description Light integration between GitHub and JIRA
// @grant none
// @include https://github.com/*
// @include <JIRA_URL>/*
// ==/UserScript==
JIRA_URL='<JIRA_URL>'
function classElements(className) {
return Array.from(document.getElementsByClassName('js-issue-title'));
}
if(location.href.startsWith('https://github.com')) {
var elements = []
.concat(classElements('js-issue-title'))
.concat(classElements('commit-title'))
.concat(classElements('branch-name'))
.concat(classElements('js-navigation-open'))
;
for(var element of elements) {
// Ticket ID link
element.innerHTML = element.innerHTML.replace(
/\b([A-Z][A-Z0-9]+\-[0-9]+)\b([^"])/,
'<a href="' + JIRA_URL + '/browse/$1">$1</a>$2');
}
}
function appendElement(parent, html) {
var child = document.createElement('div');
child.innerHTML = html;
child = child.firstChild;
parent.appendChild(child);
}
function appendLink(parent, caption, url) {
appendElement(parent, '<div><a href="' + url + '">' + caption + '</a></div>');
}
if( location.href.startsWith(JIRA_URL + '/browse/') ) {
var id=document.getElementById('key-val').innerText;
//var element = document.getElementsByClassName('mod-content')[11];
var element = document.getElementsByClassName('item-details')[5];
appendLink(element,
'Pull Request', 'https://github.com/pulls?q=is%3Apr+' + id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment