Skip to content

Commit

Permalink
add steps to auto-post comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rezrah committed Dec 4, 2024
1 parent a53845e commit 67ddb36
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/new_release_issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
- name: Create new release issue
if: success()
id: created-issue
uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -41,3 +42,53 @@ jobs:
with:
update_existing: true
search_existing: true

- name: Get comments from last release
if: success()
id: get_pr_comments
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prs = await github.rest.pulls.list({
owner: 'primer',
repo: 'brand',
state: 'closed',
sort: 'updated',
direction: 'desc',
per_page: 1,
head: 'changeset-release/main'
});
if (prs.data.length === 0) {
core.setFailed('No closed PR found with branch changeset-release/main.');
} else {
const pr = prs.data[0];
console.log('Found PR:', pr);
const comments = await github.rest.issues.listComments({
owner: 'primer',
repo: 'brand',
issue_number: pr.number
});
const filteredComments = comments.data.filter(comment => comment.user.login !== 'github-actions');
console.log('Filtered comments:', filteredComments);
core.setOutput('comments', JSON.stringify(filteredComments));
}
- name: Post comments to issue
if: success()
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const comments = JSON.parse('${{ steps.get_pr_comments.outputs.comments }}');
const issue_number = ${{ steps.created-issue.outputs.number }};
console.log('Posting comments to issue number:', issue_number);
for (const comment of comments) {
console.log('Posting comment:', comment.body);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: comment.body
});
}

0 comments on commit 67ddb36

Please sign in to comment.