-
Notifications
You must be signed in to change notification settings - Fork 25
ci: request a Copilot review once CI first passes on a PR to main #1016
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
Open
alongd
wants to merge
1
commit into
main
Choose a base branch
from
copilot-review-on-green
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+66
−0
Open
Changes from all commits
Commits
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,66 @@ | ||
| # Request a Copilot code review the first time CI passes on a PR to main. | ||
| # | ||
| # Why workflow_run rather than a `copilot_code_review` branch ruleset: a ruleset can only fire on | ||
| # PR open or on every push, never "once CI is green". Gating on CI keeps Copilot off red PRs and | ||
| # off the quota until the branch actually builds, and the dedup below keeps it to a single pass. | ||
| name: Copilot review on green | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: ["CI"] # must match the `name:` of ci.yml | ||
| types: [completed] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| request-copilot: | ||
| # Only for a PR whose CI run went green. | ||
| if: >- | ||
| github.event.workflow_run.event == 'pull_request' && | ||
| github.event.workflow_run.conclusion == 'success' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Request Copilot review (once, on first green) | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| REPO: ${{ github.repository }} | ||
| PRS_JSON: ${{ toJSON(github.event.workflow_run.pull_requests) }} | ||
| HEAD_SHA: ${{ github.event.workflow_run.head_sha }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| # Resolve the PR: the workflow_run payload carries it for same-repo PRs; for fork PRs the | ||
| # array is empty, so fall back to a lookup by the run's head SHA. | ||
| pr=$(jq -r '.[0].number // empty' <<<"$PRS_JSON") | ||
| if [ -z "$pr" ]; then | ||
| pr=$(gh pr list --repo "$REPO" --state open --search "$HEAD_SHA" \ | ||
| --json number,baseRefName --jq '.[] | select(.baseRefName=="main") | .number' | head -1) | ||
| fi | ||
| if [ -z "$pr" ]; then | ||
| echo "No open PR to main for $HEAD_SHA — nothing to do." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Only PRs targeting main (CI already scopes to this, but be explicit). | ||
| base=$(gh pr view "$pr" --repo "$REPO" --json baseRefName --jq .baseRefName) | ||
| if [ "$base" != "main" ]; then | ||
| echo "PR #$pr targets '$base', not main — skip." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Dedup: skip if Copilot is already a requested reviewer or has already reviewed. This is | ||
| # what makes it "first green only" — later green runs find Copilot engaged and no-op. | ||
| engaged=$(gh pr view "$pr" --repo "$REPO" --json reviewRequests,reviews \ | ||
| --jq '[(.reviewRequests[].login), (.reviews[].author.login)] | ||
| | map(ascii_downcase) | map(test("copilot")) | any') | ||
| if [ "$engaged" = "true" ]; then | ||
| echo "Copilot already engaged on #$pr — skip." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # The reviewer login the request API expects (distinct from the review author's slug). | ||
| gh api --method POST "repos/$REPO/pulls/$pr/requested_reviewers" \ | ||
| -f 'reviewers[]=copilot-pull-request-reviewer[bot]' | ||
| echo "Requested Copilot review on #$pr." | ||
|
alongd marked this conversation as resolved.
|
||
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.