Skip to content

Commit

Permalink
Added two yml file to check and migrate PR release notes comment
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpojer committed Jan 19, 2024
1 parent 6539bf2 commit 610b5b2
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/check_pr_release_note_comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Check Release Notes in PR comment

on:
pull_request:
types: [opened, synchronize, reopened, edited, labeled, unlabeled]
branches: [ master ]

jobs:
check-release-notes-comments:
runs-on: ubuntu-latest
steps:
- name: Fetch all PR comments
id: get-comments
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issueNumber = context.issue.number;
const repoName = context.repo.repo;
const repoOwner = context.repo.owner;
const comments = await github.rest.issues.listComments({
owner: repoOwner,
repo: repoName,
issue_number: issueNumber,
});
return comments.data.map(comment => comment.body);
- name: Check for 'Release Notes' in comments
uses: actions/github-script@v7
with:
script: |
const comments = ${{ steps.get-comments.outputs.result }};
const releaseNotesRegex = /release notes/i;
const hasReleaseNotes = comments.some(comment => releaseNotesRegex.test(comment));
if (!hasReleaseNotes) {
console.log('No "Release notes" found in PR comments');
core.setFailed('No "Release notes" found in PR comments')
} else {
console.log('"Release notes" found in comments');
}
94 changes: 94 additions & 0 deletions .github/workflows/release_notes_comments_migration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Copy Release Notes to Related Issues

on:
pull_request:
types: [closed]
branches: [ main ]

jobs:
copy_release_notes:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Fetch PR Comments
id: get-comments
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const prNumber = context.payload.pull_request.number;
const repoName = context.repo.repo;
const repoOwner = context.repo.owner;
const releaseNotesRegex = /release notes/i;
const comments = await github.rest.issues.listComments({
owner: repoOwner,
repo: repoName,
issue_number: prNumber,
});
const releaseNoteComment = comments.data.find(comment => releaseNotesRegex.test(comment.body));
const releaseNoteBody = releaseNoteComment ? releaseNoteComment.body : '';
console.log(`Release Note Body: ${releaseNoteBody}`);
core.setOutput('releaseNoteBody', releaseNoteBody);
- name: Print Extracted releaseNoteBody
run: |
echo "Extracted Release Note Body:"
echo "${{ steps.get-comments.outputs.releaseNoteBody }}"
echo "RELEASE_NOTE_BODY<<EOF" >> $GITHUB_ENV
echo "${{ steps.get-comments.outputs.releaseNoteBody }}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Parse PR Description for Related Issues
id: find-issues
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const description = context.payload.pull_request.body;
const issueNumbers = [];
const regexPattern = /([Cc]los(e|es|ed)|[Ff]ix(es|ed)?|[Rr]esolv(e|es|ed))\s*#\s*([0-9]+)/g;
let match;
while ((match = regexPattern.exec(description)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (match.index === regexPattern.lastIndex) {
regexPattern.lastIndex++;
}
// The actual issue number is in the last group of the match
const issueNumber = match[match.length - 1];
if (issueNumber) {
issueNumbers.push(issueNumber);
}
}
core.setOutput('issueNumbers', issueNumbers.join(', '));
- name: Print Extracted Issue Numbers
run: |
echo "Extracted Issue Numbers: ${{ steps.find-issues.outputs.issueNumbers }}"
echo "ISSUE_NUMBERS=${{ steps.find-issues.outputs.issueNumbers }}" >> $GITHUB_ENV
- name: Post Comment to Issues
if: ${{ steps.get-comments.outputs.releaseNoteBody }} && ${{ steps.find-issues.outputs.issueNumbers }}
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issueNumbers = process.env.ISSUE_NUMBERS;
const commentBody = process.env.RELEASE_NOTE_BODY;
const repoName = context.repo.repo;
const repoOwner = context.repo.owner;
for (const issueNumber of issueNumbers.split(', ')) {
if (issueNumber && commentBody) {
await github.rest.issues.createComment({
owner: repoOwner,
repo: repoName,
issue_number: issueNumber,
body: commentBody
});
}
}

0 comments on commit 610b5b2

Please sign in to comment.