Skip to content

Commit a5176ee

Browse files
committed
ci(pr): link tracking issues in metadata triage
Refs #1 Refs #19
1 parent 89757cc commit a5176ee

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## What & why
44

5-
<!-- What does this change and why? Link issues with "Closes #123". -->
5+
<!-- What does this change and why? Use "Closes #123" for GitHub Development linking. Auto-close is disabled for the long-running tracking issues. -->
66

77
## Source
88

.github/workflows/pr-metadata.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,38 @@ jobs:
101101
break;
102102
}
103103
104+
const trackingIssuesByLabel = new Map([
105+
['data', 1],
106+
['site', 19],
107+
]);
108+
const trackingIssues = [];
109+
for (const [label, issueNumber] of trackingIssuesByLabel) {
110+
if (labels.has(label)) trackingIssues.push(issueNumber);
111+
}
112+
if (trackingIssues.length) {
113+
let body = pr.body || '';
114+
let updatedBody = body;
115+
for (const issueNumber of trackingIssues) {
116+
const closingLine = `Closes #${issueNumber}`;
117+
const closingPattern = new RegExp(`\\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\\s+#${issueNumber}\\b`, 'i');
118+
const refsPattern = new RegExp(`\\bRefs\\s+#${issueNumber}\\b`, 'i');
119+
if (closingPattern.test(updatedBody)) continue;
120+
if (refsPattern.test(updatedBody)) {
121+
updatedBody = updatedBody.replace(refsPattern, closingLine);
122+
} else {
123+
updatedBody = `${updatedBody.trimEnd()}\n\n${closingLine}`;
124+
}
125+
}
126+
if (updatedBody !== body) {
127+
await github.rest.pulls.update({
128+
owner,
129+
repo,
130+
pull_number: issue_number,
131+
body: updatedBody,
132+
});
133+
}
134+
}
135+
104136
const changedLines = files.reduce((sum, file) => sum + file.additions + file.deletions, 0);
105137
let priority = 'Medium';
106138
if (labels.has('data') && (files.length >= 25 || changedLines >= 1000)) {

0 commit comments

Comments
 (0)