-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitbucket.js
55 lines (40 loc) · 1.36 KB
/
bitbucket.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
'use strict';
function copyBranchName(){
const branchNameEl = document.querySelector('.branch-name');
const range = document.createRange();
const selection = window.getSelection();
range.selectNode(branchNameEl);
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
selection.removeAllRanges();
}
function isValidPage(){
const isAPr = window.location.href.match(/\/pull-requests\/(\d+)/);
return isAPr;
}
function addCopyButtons(){
const container = document.createElement('div');
const header = document.querySelector('#pull-request-header');
const button = document.createElement('button');
button.textContent = "Copy Branch Name";
button.style = "margin-right: 20px;cursor:pointer;"
button.onclick = copyBranchName;
// add button
container.appendChild(button);
const jiraTicketNum = document.querySelector('.branch-name')
.textContent
.split("/")
.find(text => ["ENG", "BUG", "PUG", "PROD", "FE"].includes(text.split("-")[0]));
if(jiraTicketNum){
const jiraLink = document.createElement('a');
jiraLink.target= '_blank';
jiraLink.setAttribute('href',`https://eigentech.atlassian.net/browse/${jiraTicketNum}`);
jiraLink.innerText = `View ${jiraTicketNum} in JIRA`;
container.appendChild(jiraLink);
}
header.prepend(container);
}
if(isValidPage()){
addCopyButtons()
}