Skip to content

Instantly share code, notes, and snippets.

@Vlatombe
Created June 16, 2020 15:05
Show Gist options
  • Save Vlatombe/b051e2d2e89b14b5af841e7f5c56b0a3 to your computer and use it in GitHub Desktop.
Save Vlatombe/b051e2d2e89b14b5af841e7f5c56b0a3 to your computer and use it in GitHub Desktop.
Linkify jira issues in Github
// ==UserScript==
// @name GitHub/Jira Links
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Link to Jira from Github
// @author Vincent Latombe
// @match https://github.com/**
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// run-at document-end
// @grant none
// @license MIT
// ==/UserScript==
function getJiraUrl(issueKey) {
if (issueKey.startsWith("JENKINS-")) {
return "https://issues.jenkins-ci.org"
} else {
return "https://cloudbees.atlassian.net"
}
}
function doIt(node) {
var regex = new RegExp('([A-Z][A-Z0-9]*\-[0-9]+)', 'g');
var regexNot = new RegExp('([A-Z][A-Z0-9]*\-[0-9]+)"', 'g');
$(".full-commit>p.commit-title, pre, h1").each(function(k,v) {
var text = $(this).html()
var issueKeys = []
var match = regex.exec(text)
var matchNot = regexNot.exec(text)
var currentText = text
while (match && !matchNot) {
//console.log(v)
//console.log(text)
issueKeys[issueKeys.length] = match[1]
currentText = currentText.substring(match.lastIndex)
match = regex.exec(text)
matchNot = regexNot.exec(text)
}
issueKeys.forEach(function(issueKey) {
text = text.replace(issueKey, '<a href="' + getJiraUrl(issueKey) + '/browse/' + issueKey + '">' + issueKey + "</a>");
})
$(this).html(text);
});
}
waitForKeyElements ("#commits_bucket, .commit-title, .commit-desc, #discussion_bucket, #files_bucket, .subnav", doIt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment