Skip to content

Commit 7f52d4a

Browse files
add github action that will add a 'waiting for release' label and comment (#486)
1 parent 3592040 commit 7f52d4a

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

.github/workflows/pr-merge.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: PR Merge - Update Related Issues with the 'waiting for release' label and comment
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
update-issue:
9+
if: github.event.pull_request.merged == true
10+
runs-on: ubuntu-latest
11+
permissions:
12+
issues: write
13+
pull-requests: read
14+
15+
steps:
16+
- name: Extract issue number from PR
17+
id: extract-issue
18+
uses: actions/github-script@v7
19+
with:
20+
script: |
21+
const prBody = context.payload.pull_request.body || '';
22+
const prNumber = context.payload.pull_request.number;
23+
24+
let issueNumbers = new Set();
25+
26+
// pattern 1: Related issue: #123
27+
const relatedPattern = /Related issue:\s*#(\d+)/gi;
28+
let match;
29+
while ((match = relatedPattern.exec(prBody)) !== null) {
30+
issueNumbers.add(match[1]);
31+
}
32+
33+
// pattern 2: Closes #123, Fixes #123, Resolves #123
34+
const closingPattern = /(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?):?\s*#(\d+)/gi;
35+
while ((match = closingPattern.exec(prBody)) !== null) {
36+
issueNumbers.add(match[1]);
37+
}
38+
39+
const issues = Array.from(issueNumbers);
40+
console.log('Found related issues:', issues);
41+
42+
if (issues.length === 0) {
43+
console.log('No related issues found');
44+
return null;
45+
}
46+
47+
return issues;
48+
49+
- name: Add label and comment to issues
50+
if: steps.extract-issue.outputs.result != null
51+
uses: actions/github-script@v7
52+
with:
53+
script: |
54+
const issues = ${{ steps.extract-issue.outputs.result }};
55+
56+
if (!issues || issues.length === 0) {
57+
console.log('No issues to update');
58+
return;
59+
}
60+
61+
const prNumber = context.payload.pull_request.number;
62+
const prTitle = context.payload.pull_request.title;
63+
const prUrl = context.payload.pull_request.html_url;
64+
const prAuthor = context.payload.pull_request.user.login;
65+
const mergedBy = context.payload.pull_request.merged_by.login;
66+
67+
for (const issueNumber of issues) {
68+
try {
69+
const { data: issue } = await github.rest.issues.get({
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
issue_number: parseInt(issueNumber)
73+
});
74+
75+
// check label `bug` to show in comment `this feature ...` or `this bug ...`
76+
const isBug = issue.labels.some(label =>
77+
(typeof label === 'string' ? label : label.name).toLowerCase() === 'bug'
78+
);
79+
const changeType = isBug ? 'fix' : 'feature';
80+
console.log(`Issue #${issueNumber} is a ${changeType}`);
81+
82+
// add label "waiting for release"
83+
await github.rest.issues.addLabels({
84+
owner: context.repo.owner,
85+
repo: context.repo.repo,
86+
issue_number: parseInt(issueNumber),
87+
labels: ['waiting for release']
88+
});
89+
90+
console.log(`Added label "waiting for release" to issue #${issueNumber}`);
91+
92+
// add comment to issue
93+
const comment = `
94+
🎉 The pull request #${prNumber} that addresses this issue has been merged!
95+
96+
**PR Details:**
97+
- **Title:** ${prTitle}
98+
- **Author:** @${prAuthor}
99+
- **Merged by:** @${mergedBy}
100+
- **Link:** ${prUrl}
101+
102+
This ${changeType} will be included in the next release.
103+
`;
104+
105+
await github.rest.issues.createComment({
106+
owner: context.repo.owner,
107+
repo: context.repo.repo,
108+
issue_number: parseInt(issueNumber),
109+
body: comment
110+
});
111+
112+
console.log(`Added comment to issue #${issueNumber}`);
113+
} catch (error) {
114+
console.error(`Error processing issue #${issueNumber}:`, error.message);
115+
}
116+
}

0 commit comments

Comments
 (0)