Skip to content

Commit c7983a1

Browse files
Added two yml file to check and migrate PR release notes comment (#30)
* Added two yml file to check and migrate PR release notes comment
1 parent 6539bf2 commit c7983a1

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Check Release Notes in PR comment
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, edited, labeled, unlabeled]
6+
branches: [ master ]
7+
8+
jobs:
9+
check-release-notes-comments:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Fetch all PR comments
13+
id: get-comments
14+
uses: actions/github-script@v7
15+
with:
16+
github-token: ${{secrets.GITHUB_TOKEN}}
17+
script: |
18+
const issueNumber = context.issue.number;
19+
const repoName = context.repo.repo;
20+
const repoOwner = context.repo.owner;
21+
22+
const comments = await github.rest.issues.listComments({
23+
owner: repoOwner,
24+
repo: repoName,
25+
issue_number: issueNumber,
26+
});
27+
28+
return comments.data.map(comment => comment.body);
29+
30+
- name: Check for 'Release Notes' in comments
31+
uses: actions/github-script@v7
32+
with:
33+
script: |
34+
const comments = ${{ steps.get-comments.outputs.result }};
35+
const releaseNotesRegex = /release notes/i;
36+
const hasReleaseNotes = comments.some(comment => releaseNotesRegex.test(comment));
37+
38+
if (!hasReleaseNotes) {
39+
console.log('No "Release notes" found in PR comments');
40+
core.setFailed('No "Release notes" found in PR comments')
41+
} else {
42+
console.log('"Release notes" found in comments');
43+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Copy Release Notes to Related Issues
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches: [ main ]
7+
8+
jobs:
9+
copy_release_notes:
10+
if: github.event.pull_request.merged == true
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Fetch PR Comments
14+
id: get-comments
15+
uses: actions/github-script@v7
16+
with:
17+
github-token: ${{secrets.GITHUB_TOKEN}}
18+
script: |
19+
const prNumber = context.payload.pull_request.number;
20+
const repoName = context.repo.repo;
21+
const repoOwner = context.repo.owner;
22+
const releaseNotesRegex = /release notes/i;
23+
24+
const comments = await github.rest.issues.listComments({
25+
owner: repoOwner,
26+
repo: repoName,
27+
issue_number: prNumber,
28+
});
29+
30+
const releaseNoteComment = comments.data.find(comment => releaseNotesRegex.test(comment.body));
31+
const releaseNoteBody = releaseNoteComment ? releaseNoteComment.body : '';
32+
console.log(`Release Note Body: ${releaseNoteBody}`);
33+
core.setOutput('releaseNoteBody', releaseNoteBody);
34+
35+
- name: Print Extracted releaseNoteBody
36+
run: |
37+
echo "Extracted Release Note Body:"
38+
echo "${{ steps.get-comments.outputs.releaseNoteBody }}"
39+
echo "RELEASE_NOTE_BODY<<EOF" >> $GITHUB_ENV
40+
echo "${{ steps.get-comments.outputs.releaseNoteBody }}" >> $GITHUB_ENV
41+
echo "EOF" >> $GITHUB_ENV
42+
43+
- name: Parse PR Description for Related Issues
44+
id: find-issues
45+
uses: actions/github-script@v7
46+
with:
47+
github-token: ${{secrets.GITHUB_TOKEN}}
48+
script: |
49+
const description = context.payload.pull_request.body;
50+
const issueNumbers = [];
51+
const regexPattern = /([Cc]los(e|es|ed)|[Ff]ix(es|ed)?|[Rr]esolv(e|es|ed))\s*#\s*([0-9]+)/g;
52+
53+
let match;
54+
while ((match = regexPattern.exec(description)) !== null) {
55+
// This is necessary to avoid infinite loops with zero-width matches
56+
if (match.index === regexPattern.lastIndex) {
57+
regexPattern.lastIndex++;
58+
}
59+
60+
// The actual issue number is in the last group of the match
61+
const issueNumber = match[match.length - 1];
62+
if (issueNumber) {
63+
issueNumbers.push(issueNumber);
64+
}
65+
}
66+
67+
core.setOutput('issueNumbers', issueNumbers.join(', '));
68+
69+
- name: Print Extracted Issue Numbers
70+
run: |
71+
echo "Extracted Issue Numbers: ${{ steps.find-issues.outputs.issueNumbers }}"
72+
echo "ISSUE_NUMBERS=${{ steps.find-issues.outputs.issueNumbers }}" >> $GITHUB_ENV
73+
74+
- name: Post Comment to Issues
75+
if: ${{ steps.get-comments.outputs.releaseNoteBody }} && ${{ steps.find-issues.outputs.issueNumbers }}
76+
uses: actions/github-script@v7
77+
with:
78+
github-token: ${{secrets.GITHUB_TOKEN}}
79+
script: |
80+
const issueNumbers = process.env.ISSUE_NUMBERS;
81+
const commentBody = process.env.RELEASE_NOTE_BODY;
82+
const repoName = context.repo.repo;
83+
const repoOwner = context.repo.owner;
84+
85+
for (const issueNumber of issueNumbers.split(', ')) {
86+
if (issueNumber && commentBody) {
87+
await github.rest.issues.createComment({
88+
owner: repoOwner,
89+
repo: repoName,
90+
issue_number: issueNumber,
91+
body: commentBody
92+
});
93+
}
94+
}

0 commit comments

Comments
 (0)