Skip to content

Add Copilot agent to lint CI for automatic lint fix on PRs#2407

Open
Copilot wants to merge 2 commits intomainfrom
copilot/add-copilot-agent-to-lint
Open

Add Copilot agent to lint CI for automatic lint fix on PRs#2407
Copilot wants to merge 2 commits intomainfrom
copilot/add-copilot-agent-to-lint

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

  • Understand current lint.yml workflow structure
  • Add a copilot-fix-lint job that triggers when lint-python-format fails on a PR
  • Fix review comment 1: Use always() && needs.lint-python-format.result == 'failure' instead of failure() to gate explicitly on the lint job result
  • Fix review comment 2: Add issues: write permission since the script uses github.rest.issues.* APIs
  • Fix review comment 3: Use github.paginate instead of single listComments call to handle PRs with 100+ comments
  • Fix review comment 4: Add concurrency group to prevent race condition between concurrent workflow runs
  • Validate YAML syntax

Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/8ec606c9-d765-438a-9810-012c2033d057

Co-authored-by: xiaoyu-work <85524621+xiaoyu-work@users.noreply.github.com>
@xiaoyu-work xiaoyu-work marked this pull request as ready for review April 10, 2026 02:12
Copilot AI review requested due to automatic review settings April 10, 2026 02:12
Copy link
Copy Markdown
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

Adds a follow-up GitHub Actions job that, when linting fails on same-repo pull requests, posts a deduplicated PR comment mentioning @copilot with steps to reproduce and fix lint issues.

Changes:

  • Introduces a new copilot-fix-lint job in the lint workflow.
  • Adds logic to avoid duplicate “request Copilot” comments via an HTML marker.
  • Includes a link to the failed workflow run and local reproduction commands in the PR comment.

Comment on lines +83 to +85
# Only run when lint fails on pull requests from the same repo (not forks)
if: >-
failure()
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The job-level condition is broader than the PR description and may not run when intended. failure() can become true due to failures in other jobs (for example optional-lint), and dependent jobs are often skipped when needs fails unless you include always(). Prefer gating explicitly on the dependency result, for example checking needs.lint-python-format.result == 'failure' and combining with always() plus the pull_request and non-fork checks.

Suggested change
# Only run when lint fails on pull requests from the same repo (not forks)
if: >-
failure()
# Only run when lint-python-format fails on pull requests from the same repo (not forks)
if: >-
always()
&& needs.lint-python-format.result == 'failure'

Copilot uses AI. Check for mistakes.
&& github.event_name == 'pull_request'
&& github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
permissions:
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actions/github-script is calling github.rest.issues.* APIs (listComments/createComment), which require the issues permission. This job currently sets only pull-requests: write, and job-level permissions overrides other scopes to none, so the API calls can fail with 403. Add issues: write (and keep pull-requests: write only if needed).

Suggested change
permissions:
permissions:
issues: write

Copilot uses AI. Check for mistakes.
Comment on lines +99 to +105
// Avoid duplicate comments on workflow re-runs
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
per_page: 100,
});
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deduplication can miss prior markers because only the first 100 comments are fetched. If a PR has more than 100 comments, the marker could be on a later page and this job would post a duplicate request. Consider paginating through comments (or searching most-recent pages first), or updating an existing comment instead of creating a new one.

Suggested change
// Avoid duplicate comments on workflow re-runs
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
per_page: 100,
});
// Avoid duplicate comments on workflow re-runs by checking all comment pages
const comments = await github.paginate(
github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
per_page: 100,
},
);

Copilot uses AI. Check for mistakes.
Comment on lines +107 to +110
if (comments.some(c => c.body?.includes(marker))) {
core.info('Copilot lint fix already requested; skipping.');
return;
}
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a race window where two workflow runs (for example a re-run started before the prior run posts the comment) can both pass the "no marker" check and create duplicate comments. If duplicates are a concern, consider adding a workflow concurrency group for this job/workflow or switching to an idempotent update strategy (for example editing an existing marker comment).

Copilot uses AI. Check for mistakes.
Agent-Logs-Url: https://github.com/microsoft/Olive/sessions/950d51d5-2dc1-4df4-a471-7577bbadea9a

Co-authored-by: xiaoyu-work <85524621+xiaoyu-work@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants