-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshilling-tracking-issue-creator.user.js
57 lines (51 loc) · 1.89 KB
/
shilling-tracking-issue-creator.user.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
// ==UserScript==
// @name Shilling Tracking Issue Creator
// @namespace https://github.com/sirbrillig/shilling-tracking-issue-creator
// @version 1.1.0
// @description Adds a Shilling Github Tracking issue for a GitHub Enterprise PR
// @author Payton Swick <[email protected]>
// @match https://github.a8c.com/Automattic/*/pull/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=a8c.com
// @grant none
// ==/UserScript==
(function () {
'use strict';
// If this PR is already tracked (and has the tracking issue listed like
// "Tracked by https://github.com/..."), don't do anything.
const commentBody = document.querySelector('.comment-body');
if (!commentBody) {
return;
}
const hasTrackedBy = /Tracked \w+:? https:/i.test(commentBody.textContent);
if (hasTrackedBy) {
return;
}
const titleArea = document.querySelector(
'.gh-header-title .js-issue-title',
);
if (!titleArea) {
return;
}
const titleAreaText = titleArea.innerText;
if (titleAreaText.length < 2) {
return;
}
// This is the Shilling project board:
// https://github.com/orgs/Automattic/projects/655/views/1
const project = 'Automattic/655';
const trackingLabel = 'github.a8c%20Tracking%20Issue';
const githubUrl = `https://github.com/Automattic/payments-shilling/issues/new?title=${encodeURIComponent(
titleAreaText,
)}&body=${encodeURIComponent(
document.location.href,
)}&projects=${project}&labels=${trackingLabel}`;
// Create a button that makes the tracking issue.
const button = document.createElement('button');
button.appendChild(document.createTextNode('Create tracking issue'));
button.addEventListener('click', () => {
window.open(githubUrl, '_blank');
});
button.className = 'flex-md-order-3 Button--secondary Button--small Button';
// Add the button to the DOM of the current page.
document.querySelector('.gh-header-actions').appendChild(button);
})();