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