Skip to content

Commit

Permalink
fix: delete previous comments and update last one
Browse files Browse the repository at this point in the history
  • Loading branch information
gcharest authored Sep 10, 2024
1 parent 9620644 commit 34e86a2
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions .github/workflows/ci_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ env:
jobs:
tests:
runs-on: ubuntu-latest
env:
COMMENT_ID: ""
steps:
- name: Audit DNS requests
uses: cds-snc/dns-proxy-action@main
Expand Down Expand Up @@ -69,12 +71,23 @@ jobs:
issue_number: context.issue.number,
});
comments.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
const comment = comments.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes('Lint, format and test code results'));
return comment ? comment.id : null;
const filteredComments = comments.filter(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes('Lint, format and test code results'));
if (filteredComments.length > 0) {
core.exportVariable('COMMENT_ID', filteredComments[0].id);
const commentsToDelete = filteredComments.slice(1);
const deletePromises = commentsToDelete.map(comment => github.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
}));
const results = await Promise.all(deletePromises);
console.log('Number of comments deleted:', results.length);
} else {
console.log('No previous comments found');
}
- name: Update comment
if: steps.find-comment.outputs.result != 'null'
if: env.COMMENT_ID != ''
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
Expand All @@ -86,7 +99,7 @@ jobs:
});
- name: Create comment
if: steps.find-comment.outputs.result == 'null'
if: env.COMMENT_ID == ''
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
Expand Down

0 comments on commit 34e86a2

Please sign in to comment.