Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 15, 2025

Pre-commit failure comments were accumulating on PRs without deletion, creating noise and making it difficult to identify current status.

Changes

  • Added comment marker <!-- pre-commit-check --> to identify pre-commit failure comments
  • Delete stale comments before posting new failure messages when checks fail
  • Auto-remove comments when pre-commit checks pass

Implementation

# Before posting new failure comment
const { data: comments } = await github.rest.issues.listComments({...});
const existingComment = comments.find(c => c.body?.includes(commentMarker));
if (existingComment) {
  await github.rest.issues.deleteComment({comment_id: existingComment.id});
}

New step added to remove failure comments when checks pass, following the pattern used by check-console-log.yml and test failure comments.

Original prompt

On the sction remove all of the ❌ Pre-commit checks failed before continuing to run it again


💡 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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 15, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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 @coderabbitai help to get the list of available commands and usage tips.

Copilot AI changed the title [WIP] Remove pre-commit checks before retrying Remove duplicate pre-commit failure comments in CI/CD workflow Dec 15, 2025
Copilot AI requested a review from DonnieBLT December 15, 2025 10:35
@DonnieBLT DonnieBLT marked this pull request as ready for review December 15, 2025 10:42
Copilot AI review requested due to automatic review settings December 15, 2025 10:42
@github-actions github-actions bot added the pre-commit: passed Pre-commit checks passed label Dec 15, 2025
Comment on lines +177 to +184
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}`);
}
Copy link

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

@github-actions
Copy link
Contributor

👋 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:

  • The PR author
  • DonnieBLT
  • coderabbitai
  • copilot

Once a valid peer review is submitted, this check will pass automatically. Thank you!

@github-actions github-actions bot added the needs-peer-review PR needs peer review label Dec 15, 2025
Copy link
Contributor

Copilot AI left a 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

Comment on lines +166 to +183
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}`);
Copy link

Copilot AI Dec 15, 2025

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.

Suggested change
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}`);

Copilot uses AI. Check for mistakes.
Comment on lines +212 to +217
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number: pull_number,
per_page: 100,
});
Copy link

Copilot AI Dec 15, 2025

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
Comment on lines +178 to +183
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}`);
Copy link

Copilot AI Dec 15, 2025

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.

Suggested change
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}`);
}

Copilot uses AI. Check for mistakes.
Comment on lines +224 to +229
await github.rest.issues.deleteComment({
owner,
repo,
comment_id: existingComment.id,
});
core.info(`Deleted pre-commit failure comment #${existingComment.id} since checks now pass`);
Copy link

Copilot AI Dec 15, 2025

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.

Suggested change
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}`);
}

Copilot uses AI. Check for mistakes.
}
}
- name: Remove pre-commit failure comment if pre-commit passes
if: github.event_name == 'pull_request_target' && steps.pre-commit.outputs.exit_code == '0'
Copy link

Copilot AI Dec 15, 2025

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.

Suggested change
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'

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot added tests: passed Django tests passed last-active: 0d PR last updated 0 days ago last-active: 1d PR last updated 1 day ago and removed last-active: 0d PR last updated 0 days ago labels Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

files-changed: 1 last-active: 1d PR last updated 1 day ago needs-peer-review PR needs peer review pre-commit: passed Pre-commit checks passed tests: passed Django tests passed

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants