Last active
November 5, 2024 23:53
-
-
Save M-r-A/8bfa49a76b31a3d6099ef5066f21ea81 to your computer and use it in GitHub Desktop.
Tampermonkey script that converts references to JIRA on GitHub PR title
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Add link to Lasso Jira on GitHub | |
// @namespace io.lassomarketing.js | |
// @version 1.0.0.1 | |
// @description Converts references to Lasso JIRA issues on GitHub into clickable link | |
// @author Alexey Nikitin | |
// @homepage https://github.com/M-r-A | |
// @updateURL https://gist.githubusercontent.com/M-r-A/8bfa49a76b31a3d6099ef5066f21ea81/raw/github-link-lasso-jira.user.js | |
// @downloadURL https://gist.githubusercontent.com/M-r-A/8bfa49a76b31a3d6099ef5066f21ea81/raw/github-link-lasso-jira.user.js | |
// @match https://github.com/Lasso-Marketing/* | |
// @run-at document-end | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
const jiraUrl = "https://iqviadigital.atlassian.net/browse/"; | |
const jiraKeyRegex = /([A-Z][A-Z0-9]{1,9}-[0-9]+)/g; | |
const classMarker = "jira-link" | |
const setLink = titleElement => { | |
let jiraReference = titleElement.innerHTML.match(jiraKeyRegex); | |
if (jiraReference != null) { | |
titleElement.innerHTML = titleElement.innerHTML.replace(jiraKeyRegex, function (jiraRef) { | |
return `<a href="${jiraUrl}${jiraRef}">${jiraRef}</a>`; | |
}); | |
} | |
titleElement.classList.add(classMarker); | |
}; | |
var observer = new MutationObserver(function (mutations, me) { | |
const titleElement = document.getElementsByClassName('js-issue-title')[0]; | |
if (titleElement && !titleElement.classList.contains(classMarker)) { | |
setLink(titleElement); | |
return; | |
} | |
}); | |
observer.observe(document, { | |
childList: true, | |
subtree: true | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment