Last active
March 28, 2023 07:06
-
-
Save nathanmarcos/189ba35bec598f835a35088381903ffe to your computer and use it in GitHub Desktop.
Tampermonkey - Add link to Jira on Github PR
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 Jira on Github PR | |
| // @version 0.3.0 | |
| // @author Nathan Marcos | |
| // @match https://github.com/trivago/*/pull/* | |
| // @run-at document-end | |
| // ==/UserScript== | |
| (function () { | |
| 'use strict'; | |
| const setLink = titleElement => { | |
| const title = titleElement.innerText; | |
| const taskIdMatch = title.match(/([a-z\|A-Z]+[-\|\s][0-9]+)/g)[0]; | |
| const taskId = taskIdMatch.replace(' ', '-').concat(' '); | |
| const newTitle = title.replace(taskIdMatch, '').trim(); | |
| titleElement.innerText = ''; | |
| const linkElement = document.createElement("a"); | |
| linkElement.href = `https://trivago.atlassian.net/browse/${taskId}`; | |
| linkElement.text = taskId; | |
| linkElement.target = '_blank'; | |
| titleElement.classList.add("jira-link"); | |
| titleElement.append(linkElement); | |
| const spanElement = document.createElement("span"); | |
| spanElement.innerText = newTitle; | |
| titleElement.append(spanElement); | |
| }; | |
| var observer = new MutationObserver(function (mutations, me) { | |
| const titleElement = document.getElementsByClassName('js-issue-title')[0]; | |
| if (titleElement && !titleElement.classList.contains('jira-link')) { | |
| 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