fix: reduce wasted Copilot code review credit usage - #86
Open
lihsaa591 wants to merge 5 commits into
Open
Conversation
The org exhausted its entire monthly Copilot Pro Plus credit allotment this month, almost all of it (98%+) from the Code Review model. Three changes to the shared assign-copilot/request-review logic: - Skip drafts: a PR opened as draft isn't ready for review yet, but the trigger fired anyway, spending a review on code likely to change before it's ready. - Skip bot-authored PRs (dependabot etc.): these don't need an AI review. tg-autopilot's own PRs are unaffected -- it's a User account, not a Bot. - copilot_present() now uses curl instead of `gh api`, which can serve a cached GET right after our own mutation and falsely report "not present yet" -- a false negative here causes the retry step to re-issue a second real review request on a PR that was already reviewed. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Confirmed for real: a PR created with --draft still triggered the job with github.event.pull_request.draft == false in the opened event, so the job-level if: check let it through. Moved the check inside the step instead, re-fetched live via `gh pr view`, before any Copilot API call happens. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Same caching pattern as gh api -- gh pr view served a stale (non-draft) result for a PR created with --draft, confirmed for real: the previous fix's re-check still let a draft PR through. curl bypasses it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…erified Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The org exhausted its entire monthly Copilot Pro Plus credit allotment this month, with 98%+ of usage from the Code Review model. Three changes to the shared
assign-copilot/request-reviewlogic:openedevent's own payload.tg-autopilot's own PRs are unaffected since it's aUseraccount, not aBot— no special-casing needed.copilot_present()now usescurlinstead ofgh api, consistent with this repo's existing pattern elsewhere, to avoid a stale cached GET right after our own mutation causing an unnecessary duplicate review request.Important testing note for future changes here
pull_request_target-triggered workflows always read the triggering workflow file from the base/default branch, never from the PR's own branch — confirmed for real after four failed attempts to test this change via a temporary caller-branch trick, which silently kept running the oldmastercode every time. Any future change toassign-copilotneeds to be verified after merging tomaster, not via a caller pointed at a test branch.Test plan
colormag(or similar) after merging, since pre-merge testing isn't reliable for this trigger type