Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,59 @@ jobs:
sarif_file: lintrunner.sarif
category: lintrunner
checkout_path: ${{ github.workspace }}

copilot-fix-lint:
name: Copilot Fix Lint Errors
needs: lint-python-format
# 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.
pull-requests: write
steps:
- name: Request Copilot to fix lint errors
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const marker = '<!-- copilot-lint-fix -->';

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

if (comments.some(c => c.body?.includes(marker))) {
core.info('Copilot lint fix already requested; skipping.');
return;
}
Comment on lines +114 to +117
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.

const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;

const body = [
marker,
'@copilot The lint check failed for this PR. Please fix all the lint errors and push the fixes to this branch.',
'',
`Failed workflow run: ${runUrl}`,
'',
'To reproduce and fix:',
'1. Run `lintrunner --all-files` to see all lint errors',
'2. Run `lintrunner --all-files -a` to auto-fix formatting issues',
Comment on lines +128 to +129
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

The instructions in the PR comment recommend running full lintrunner --all-files locally, but this repo’s developer guidance recommends lintrunner --all-files -a --skip PYLINT for faster iteration and running PYLINT only when changes are PR-ready (see AGENTS.md). Consider updating steps 1–2 in the generated comment to reflect that convention so developers are not encouraged to run the slowest option by default.

Suggested change
'1. Run `lintrunner --all-files` to see all lint errors',
'2. Run `lintrunner --all-files -a` to auto-fix formatting issues',
'1. Run `lintrunner --all-files -a --skip PYLINT` to auto-fix issues and check the faster local lint path',
'2. When the changes are PR-ready, run `lintrunner --all-files` to include PYLINT and any remaining checks',

Copilot uses AI. Check for mistakes.
'3. Manually fix any remaining lint errors that cannot be auto-fixed',
'4. Commit and push the fixes',
].join('\n');

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body,
});

core.info(`Requested Copilot to fix lint errors on PR #${prNumber}`);
Loading