Repository navigation
Add workflow that limits Copilot reviews to 3 per PR #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| name: Copilot review cap | ||
|
|
||
| # Org ruleset reviews each PR once when it opens. This workflow requests a new Copilot review on | ||
| # each push until the PR has MAX_REVIEWS Copilot reviews, then asks the author to work locally. | ||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened, ready_for_review] | ||
|
Comment on lines
+5
to
+7
|
||
|
|
||
| permissions: {} | ||
|
|
||
| concurrency: | ||
| group: copilot-review-cap-${{ github.repository }}-${{ github.event.pull_request.number }} | ||
| # Never cancel: a cancelled run on a required workflow blocks the merge. | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| copilot-review: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| permissions: | ||
| pull-requests: write | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| ACTION: ${{ github.event.action }} | ||
| DRAFT: ${{ github.event.pull_request.draft }} | ||
| FORK: ${{ github.event.pull_request.head.repo.full_name != github.repository }} | ||
| REPO: ${{ github.repository }} | ||
| PR: ${{ github.event.pull_request.number }} | ||
| AUTHOR: ${{ github.event.pull_request.user.login }} | ||
| MAX_REVIEWS: "3" | ||
| COPILOT: copilot-pull-request-reviewer[bot] | ||
| MARKER: "<!-- copilot-review-cap -->" | ||
| steps: | ||
| - name: Request a Copilot review or ask the author to work locally | ||
| run: | | ||
| set -euo pipefail | ||
| # Fork PRs get a read-only token, so skip them instead of failing a required check. | ||
| if [[ "$ACTION" != "synchronize" || "$DRAFT" == "true" || "$FORK" == "true" ]]; then | ||
| echo "Nothing to do for action=$ACTION draft=$DRAFT fork=$FORK" | ||
| exit 0 | ||
| fi | ||
|
|
||
| reviews=$(gh api --paginate --slurp "repos/$REPO/pulls/$PR/reviews" | | ||
| jq --arg bot "$COPILOT" '[.[][] | select(.user.login == $bot)] | length') | ||
| echo "Copilot reviews on #$PR: $reviews of $MAX_REVIEWS" | ||
|
|
||
| if (( reviews < MAX_REVIEWS )); then | ||
| if out=$(gh api -X POST "repos/$REPO/pulls/$PR/copilot-code-review" 2>&1); then | ||
| echo "Requested Copilot review" | ||
| elif grep -q "HTTP 409" <<<"$out"; then | ||
| echo "A Copilot review is already pending" | ||
| else | ||
| echo "::error::Copilot review request failed for $REPO#$PR: $out" | ||
| exit 1 | ||
| fi | ||
| exit 0 | ||
| fi | ||
|
|
||
| posted=$(gh api --paginate --slurp "repos/$REPO/issues/$PR/comments" | | ||
| jq --arg m "$MARKER" '[.[][] | select(.body | contains($m))] | length') | ||
| if (( posted > 0 )); then | ||
| echo "Cap comment already posted" | ||
| exit 0 | ||
| fi | ||
| body="$MARKER | ||
| @$AUTHOR Copilot has reviewed this PR $MAX_REVIEWS times, which is our limit per PR. More rounds rarely find new problems, and each one costs AI units. Take a step back: pull the branch, run it locally and go through the full diff with Claude Code or a teammate. You can still request a Copilot review by hand if you really need one." | ||
| gh api -X POST "repos/$REPO/issues/$PR/comments" -f body="$body" | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.