-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jira GitHub Links.js
executable file
·92 lines (80 loc) · 3.42 KB
/
Jira GitHub Links.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// ==UserScript==
// @name Jira GitHub links
// @namespace urn://https://www.georgegillams.co.uk/api/greasemonkey/jira_github_links
// @include *github.com*
// @include *github.skyscannertools.net*
// @include *gojira.skyscanner.net*
// @exclude none
// @version 10.0.2
// @grant none
// @description Creates links from GitHub PRs to their respective Jira ticket and vice-versa
// ==/UserScript==
function makeGHLink() {
const allElements = document.getElementsByTagName('H1');
for (let i = 0; i < allElements.length; i += 1) {
const element = allElements[i];
const elementMatch = element.innerText.match(/\[KOA-[0-9]+\]/g);
if (elementMatch && elementMatch.length > 0) {
const text = elementMatch[0]
.split('[')
.join('')
.split(']')
.join('');
const url = `https://gojira.skyscanner.net/browse/${text}`;
const newElement = document.createElement('a');
newElement.innerText = `View ${text} ticket on Jira`;
newElement.href = url;
newElement.style.color = 'var(--color-text-link, #0770E3)';
newElement.style.fontSize = '1rem';
newElement.id = 'jira_github_links_result';
element.appendChild(document.createElement('br'));
element.appendChild(newElement);
}
}
}
function makeJiraLink() {
const allElements = document.getElementsByTagName('LI');
const viewIssueSidebar = document.getElementById('viewissuesidebar');
for (let i = 0; i < allElements.length; i += 1) {
const element = allElements[i];
const elementMatch = element.innerText.match(/^KOA-[0-9]+$/g);
if (elementMatch && elementMatch.length > 0) {
const text = element.innerText;
const url1 = `https://github.com/pulls?utf8=%E2%9C%93&q=is%3Apr+repo%3ASkyscanner%2Fbackpack+repo%3ASkyscanner%2Fbackpack-react-native+repo%3ASkyscanner%2Fbackpack-docs+repo%3ASkyscanner%2Fbackpack-react-scripts+repo%3ASkyscanner%2Fbackpack-node-sass+repo%3ASkyscanner%2Feslint-plugin-backpack+repo%3ASkyscanner%2Feslint-config-skyscanner+repo%3ASkyscanner%2Feslint-config-skyscanner+repo%3ASkyscanner%2Fbackpack-ios+repo%3ASkyscanner%2Fbackpack-android+%22${text}%22`;
const url2 = `https://github.skyscannertools.net/pulls?utf8=%E2%9C%93&q=is%3Apr+repo%3Aapps-tribe%2Fskyscanner-app+%22${text}%22`;
const newElement1 = document.createElement('a');
newElement1.innerText = `View PRs for ${text} on GitHub (Public)`;
newElement1.href = url1;
newElement1.style.color = '#0770E3';
newElement1.style.marginLeft = '10px';
newElement1.id = 'jira_github_links_result';
const newElement2 = document.createElement('a');
newElement2.innerText = `View PRs for ${text} on GitHub (Internal)`;
newElement2.href = url2;
newElement2.style.color = '#0770e3';
newElement2.style.marginLeft = '10px';
newElement2.id = 'jira_github_links_result';
viewIssueSidebar.appendChild(document.createElement('br'));
viewIssueSidebar.appendChild(newElement1);
viewIssueSidebar.appendChild(document.createElement('br'));
viewIssueSidebar.appendChild(newElement2);
}
}
}
function makeLinks() {
const addedLink = document.getElementById('jira_github_links_result');
if (addedLink) {
return;
}
makeGHLink();
makeJiraLink();
}
function worker() {
try {
makeLinks();
} catch (e) {
// eslint-disable-next-line no-console
console.log(e);
}
}
setInterval(worker, 2000);