Skip to content

Automated CI linter failure monitoring and copilot engagement#63

Open
Copilot wants to merge 5 commits intomasterfrom
copilot/fix-linter-error-in-pr
Open

Automated CI linter failure monitoring and copilot engagement#63
Copilot wants to merge 5 commits intomasterfrom
copilot/fix-linter-error-in-pr

Conversation

Copy link

Copilot AI commented Jan 25, 2026

Monitors CI check runs via GitHub webhooks and automatically engages copilot to fix linter failures. Tracks retry attempts per check to prevent infinite loops when fixes fail repeatedly.

Implementation

Database Model (object/pr_check.go)

  • PrCheck table tracks check status, failure details, and fix attempt count per PR/check
  • IncrementFixAttempts() returns updated record to eliminate redundant queries
  • ShouldAttemptFix() enforces configurable retry limit (default: 3)

Webhook Handler (controllers/webhook.go)

  • Routes events by X-GitHub-Event header: check_run, check_suite, pull_request
  • HandleCheckRunEvent() / HandleCheckSuiteEvent() process completed checks
  • Filters for linter checks via pattern matching (golangci-lint, eslint, prettier, etc.)
  • Tags @copilot in PR comments with failure details when attempts remain

GitHub API (util/check_api.go)

const (
    MaxFixAttempts = 3              // configurable retry limit
    CopilotUsername = "copilot"     // bot username
    MaxCheckFailureTextLength = 500
)

// Pattern-match check names to identify linters
func IsLinterCheck(checkName string) bool

// Extract and format failure details for PR comment
func CommentOnPRWithCopilotTag(owner, repo string, prNumber int, 
    failureDetails string, attemptNumber int) error

API Endpoints (controllers/pr_check.go)

  • GET /api/get-pr-checks - query all checks for a PR
  • GET /api/get-pr-check - query specific check details

Automatic Review

  • PullRequestOpen() requests @copilot review on all human-created PRs

Webhook Configuration

Subscribe to: pull_request, check_run, check_suite events
Payload URL: https://<domain>/api/webhook

Full setup documentation in CI_MONITORING.md.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/orgs/casbin/repos
    • Triggering command: /tmp/go-build1171290187/b447/util.test /tmp/go-build1171290187/b447/util.test -test.testlogfile=/tmp/go-build1171290187/b447/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true g_.a 2124738/b141/ ux_amd64/vet /tmp/ccqUyMVU.s -c=4 (http block)
  • location-readonly.aliyuncs.com
    • Triggering command: /tmp/go-build1171290187/b434/cloud.test /tmp/go-build1171290187/b434/cloud.test -test.testlogfile=/tmp/go-build1171290187/b434/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true --64 2124738/b141/ ux_amd64/vet /tmp/ccCEbeex.s -c=4 -nolocalimports ux_amd64/vet x64/�� ache/go/1.24.12/x64/src/os/user =0 ux_amd64/compile --gdwarf-5 --64 -o ux_amd64/compile-buildtags (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[feature] fix the linter error in PR automatically</issue_title>
<issue_description>sometimes the AI code has failed CI checks like linter error in PR: apache/casbin#1691

we need to monitor such failed CI checks for each PR in the github repos of the monitored github orgs

if the CI failed, then reply in the PR and "AT" the copilot and provide the details, so let copilot fix it

it needs to monitor the fix process. if we found this bug is fixed, then next error happens, then we fix the next error

if the same error cannot be fixed by AI like for 3 times, then AI should stop, or it will run endlessly without progress.

for all human-created PR, it should automatically let copilot review the code</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

- Add PrCheck database model for tracking CI check status
- Add check_api utility functions for GitHub check runs
- Update webhook handler to process check_run and check_suite events
- Implement automatic copilot tagging on linter failures
- Add retry tracking (max 3 attempts)
- Enable automatic code review for human-created PRs

Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
@hsluoyz hsluoyz marked this pull request as ready for review January 25, 2026 03:26
Copilot AI and others added 3 commits January 25, 2026 03:27
- Add API endpoints to query PR check records
- Add comprehensive documentation in CI_MONITORING.md
- Document webhook setup, configuration, and usage examples

Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
- Define MaxCheckFailureTextLength, CopilotUsername, and MaxFixAttempts as constants
- Update all usages to reference the constants
- Update documentation to reflect configurability
- Improve code maintainability

Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
- Modify IncrementFixAttempts to return updated PrCheck object
- Eliminate redundant GetPrCheck calls after IncrementFixAttempts
- Initialize result variable to false in WebhookOpen
- Reduce database round trips for better performance

Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix linter error handling in pull requests Automated CI linter failure monitoring and copilot engagement Jan 25, 2026
Copilot AI requested a review from hsluoyz January 25, 2026 03:34
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.

[feature] fix the linter error in PR automatically

3 participants