Skip to content
Open
Changes from all commits
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
63 changes: 63 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,66 @@ 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-python-format fails on pull requests from the same repo (not forks)
if: >-
always()
&& needs.lint-python-format.result == 'failure'
&& github.event_name == 'pull_request'
&& github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
concurrency:
group: copilot-fix-lint-pr-${{ github.event.pull_request.number }}
cancel-in-progress: true
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.
issues: 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 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,
},
);

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',
'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