-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathadd-jira-links-to-description.js
43 lines (35 loc) · 1.03 KB
/
add-jira-links-to-description.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
chrome.storage.local.get({ tagRegex: "" }, (options) => {
if (options.tagRegex === "") {
return;
}
const $title = document.querySelector('#pull_request_title');
const $description = document.querySelector('#pull_request_body');
if (!$title || !$description) {
return;
}
const idSet = new Set();
document.querySelectorAll('.TimelineItem .Details').forEach((commitMessage) => {
match = commitMessage.textContent.match(new RegExp(options.tagRegex, 'g'));
if (match) {
match.forEach((id) => idSet.add(id));
}
});
if (idSet.size > 0) {
const ids = [];
let anyIdsInTitle = false;
let description = "";
idSet.forEach((id) => {
ids.push(id);
description += `[${id}](https://buildout.atlassian.net/browse/${id})\n`;
if ($title.value.indexOf(id) > -1) {
anyIdsInTitle = true;
}
});
if (!anyIdsInTitle) {
$title.value = `${ids.join(", ")}: `;
}
if ($description.textLength === 0) {
$description.value = `${description}\n`;
}
}
});