-
-
Notifications
You must be signed in to change notification settings - Fork 313
Remove duplicate pre-commit failure comments in CI/CD workflow #5300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Note Free review on us!CodeRabbit is offering free reviews until Wed Dec 17 2025 to showcase some of the refinements we've made. Comment |
Co-authored-by: DonnieBLT <[email protected]>
| if (existingComment) { | ||
| await github.rest.issues.deleteComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existingComment.id, | ||
| }); | ||
| core.info(`Deleted old pre-commit failure comment #${existingComment.id}`); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The deleteComment call for pre-commit failures lacks error handling. This will crash the workflow if the comment has already been deleted.
Severity: MEDIUM | Confidence: High
🔍 Detailed Analysis
The github.rest.issues.deleteComment() call, used to remove previous pre-commit failure comments, is not wrapped in a try-catch block. If the comment is deleted by another process or manually before this step runs, the GitHub API will return a 404 error. The octokit client will treat this as an unhandled exception, causing the workflow step to fail. This is inconsistent with other parts of the same workflow, such as the test failure comment deletion logic, which correctly handle this potential error by catching it and logging a warning.
💡 Suggested Fix
Wrap the github.rest.issues.deleteComment() call within a try-catch block. In the catch block, log a warning message, such as core.warning('Could not delete previous comment: ${error.message}'), to prevent the workflow from failing if the comment is already gone. This will make its behavior consistent with the existing test failure comment handling logic.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: .github/workflows/ci-cd.yml#L177-L184
Potential issue: The `github.rest.issues.deleteComment()` call, used to remove previous
pre-commit failure comments, is not wrapped in a `try-catch` block. If the comment is
deleted by another process or manually before this step runs, the GitHub API will return
a 404 error. The `octokit` client will treat this as an unhandled exception, causing the
workflow step to fail. This is inconsistent with other parts of the same workflow, such
as the test failure comment deletion logic, which correctly handle this potential error
by catching it and logging a warning.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7515487
|
👋 Hi @Copilot! This pull request needs a peer review before it can be merged. Please request a review from a team member who is not:
Once a valid peer review is submitted, this check will pass automatically. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds automatic management of pre-commit failure comments in the CI/CD workflow to prevent duplicate comments from accumulating on pull requests. The implementation follows the established pattern used by test failure comments and console.log checks: using HTML comment markers to identify automated comments, deleting stale ones before posting new failures, and automatically cleaning up when checks pass.
Key Changes
- Added
<!-- pre-commit-check -->HTML marker to identify pre-commit failure comments - Implemented deletion of old pre-commit comments before posting new failure messages
- Added automatic cleanup step to remove failure comments when pre-commit checks pass
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| per_page: 100, | ||
| }); | ||
| const existingComment = comments.find(comment => | ||
| comment.body && comment.body.includes(commentMarker) | ||
| ); | ||
| if (existingComment) { | ||
| await github.rest.issues.deleteComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existingComment.id, | ||
| }); | ||
| core.info(`Deleted old pre-commit failure comment #${existingComment.id}`); |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The per_page parameter is set to 100, which means if there are more than 100 comments on the PR, older pre-commit failure comments beyond the first 100 won't be found and deleted. This could lead to multiple stale comments accumulating on PRs with many comments. Consider either increasing per_page to the API maximum or implementing pagination to fetch all comments. The test failure comment deletion code at line 425 has the same limitation.
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| per_page: 100, | |
| }); | |
| const existingComment = comments.find(comment => | |
| comment.body && comment.body.includes(commentMarker) | |
| ); | |
| if (existingComment) { | |
| await github.rest.issues.deleteComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existingComment.id, | |
| }); | |
| core.info(`Deleted old pre-commit failure comment #${existingComment.id}`); | |
| // Paginate through all comments to find and delete old pre-commit failure comments | |
| let allComments = []; | |
| let page = 1; | |
| let fetched; | |
| do { | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| per_page: 100, | |
| page: page, | |
| }); | |
| allComments = allComments.concat(comments); | |
| fetched = comments.length; | |
| page += 1; | |
| } while (fetched === 100); | |
| const existingComments = allComments.filter(comment => | |
| comment.body && comment.body.includes(commentMarker) | |
| ); | |
| for (const comment of existingComments) { | |
| await github.rest.issues.deleteComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: comment.id, | |
| }); | |
| core.info(`Deleted old pre-commit failure comment #${comment.id}`); |
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner, | ||
| repo, | ||
| issue_number: pull_number, | ||
| per_page: 100, | ||
| }); |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The per_page parameter is set to 100, which means if there are more than 100 comments on the PR, older pre-commit failure comments beyond the first 100 won't be found and deleted. This could lead to multiple stale comments accumulating on PRs with many comments. Consider either increasing per_page to the API maximum or implementing pagination to fetch all comments.
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner, | |
| repo, | |
| issue_number: pull_number, | |
| per_page: 100, | |
| }); | |
| // Paginate through all comments to ensure we find all pre-commit failure comments | |
| let comments = []; | |
| let page = 1; | |
| let fetched; | |
| do { | |
| const { data } = await github.rest.issues.listComments({ | |
| owner, | |
| repo, | |
| issue_number: pull_number, | |
| per_page: 100, | |
| page, | |
| }); | |
| fetched = data.length; | |
| comments = comments.concat(data); | |
| page += 1; | |
| } while (fetched === 100); |
| await github.rest.issues.deleteComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existingComment.id, | ||
| }); | ||
| core.info(`Deleted old pre-commit failure comment #${existingComment.id}`); |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling for the deleteComment API call. If the comment deletion fails (e.g., comment was already deleted, permission issues), the workflow should handle it gracefully instead of failing. Consider wrapping the deletion in a try-catch block, similar to the pattern used in the test failure comment cleanup at line 524 or the console.log workflow at line 261.
| await github.rest.issues.deleteComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existingComment.id, | |
| }); | |
| core.info(`Deleted old pre-commit failure comment #${existingComment.id}`); | |
| try { | |
| await github.rest.issues.deleteComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existingComment.id, | |
| }); | |
| core.info(`Deleted old pre-commit failure comment #${existingComment.id}`); | |
| } catch (error) { | |
| core.warning(`Failed to delete old pre-commit failure comment #${existingComment.id}: ${error.message}`); | |
| } |
| await github.rest.issues.deleteComment({ | ||
| owner, | ||
| repo, | ||
| comment_id: existingComment.id, | ||
| }); | ||
| core.info(`Deleted pre-commit failure comment #${existingComment.id} since checks now pass`); |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling for the deleteComment API call. If the comment deletion fails (e.g., comment was already deleted, permission issues), the workflow should handle it gracefully instead of failing. Consider wrapping the deletion in a try-catch block, similar to the pattern used in the test failure comment cleanup at line 524 or the console.log workflow at line 261.
| await github.rest.issues.deleteComment({ | |
| owner, | |
| repo, | |
| comment_id: existingComment.id, | |
| }); | |
| core.info(`Deleted pre-commit failure comment #${existingComment.id} since checks now pass`); | |
| try { | |
| await github.rest.issues.deleteComment({ | |
| owner, | |
| repo, | |
| comment_id: existingComment.id, | |
| }); | |
| core.info(`Deleted pre-commit failure comment #${existingComment.id} since checks now pass`); | |
| } catch (error) { | |
| core.warning(`Failed to delete pre-commit failure comment #${existingComment.id}: ${error.message}`); | |
| } |
| } | ||
| } | ||
| - name: Remove pre-commit failure comment if pre-commit passes | ||
| if: github.event_name == 'pull_request_target' && steps.pre-commit.outputs.exit_code == '0' |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition should check if the pre-commit step was executed and did not fail, not if it has a specific exit code. With the current condition, this step only runs when the pre-commit step outputs exit_code of '0', but if the pre-commit step is skipped (e.g., on non-PR events), the step.pre-commit.outputs.exit_code will be empty, not '0'. Consider using steps.pre-commit.outcome == 'success' instead to handle all success cases correctly.
| if: github.event_name == 'pull_request_target' && steps.pre-commit.outputs.exit_code == '0' | |
| if: github.event_name == 'pull_request_target' && steps.pre-commit.outcome == 'success' |
Pre-commit failure comments were accumulating on PRs without deletion, creating noise and making it difficult to identify current status.
Changes
<!-- pre-commit-check -->to identify pre-commit failure commentsImplementation
New step added to remove failure comments when checks pass, following the pattern used by
check-console-log.ymland test failure comments.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.