Skip to content

ci: add Copilot auto-review on new PRs#70

Merged
imran-siddique merged 2 commits intomainfrom
feat/copilot-auto-review
Mar 7, 2026
Merged

ci: add Copilot auto-review on new PRs#70
imran-siddique merged 2 commits intomainfrom
feat/copilot-auto-review

Conversation

@imran-siddique
Copy link
Copy Markdown
Member

Adds a GitHub Actions workflow that automatically requests Copilot as a reviewer when PRs are opened or marked ready for review. Draft PRs are skipped.

Once merged, every new PR will get an automatic Copilot code review.

Automatically requests GitHub Copilot as a reviewer when PRs are
opened or marked ready for review. Skips draft PRs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions bot added the ci/cd CI/CD and workflows label Mar 7, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 7, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions github-actions bot added the size/S Small PR (< 50 lines) label Mar 7, 2026
The gh CLI --add-reviewer flag treats 'copilot' as a regular user.
Use the REST API /requested_reviewers endpoint instead, which
properly handles the Copilot reviewer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a GitHub Actions workflow to automatically request a Copilot review when pull requests are opened or marked ready for review (skipping drafts).

Changes:

  • Introduces .github/workflows/copilot-review.yml to request a reviewer via gh api on pull_request events.
  • Skips running the job for draft PRs via a job-level if condition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

name: Copilot Auto-Review

on:
pull_request:
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the pull_request event means this job will run with a read-only GITHUB_TOKEN for PRs opened from forks, so the reviewer request will fail for external contributors. If the intent is “every new PR”, consider switching to pull_request_target (no checkout in this workflow, so the usual security concern is minimal) or add an explicit guard to only run for same-repo PRs (e.g., compare head.repo.full_name to github.repository) and document that limitation.

Suggested change
pull_request:
pull_request_target:

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +24
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-f "reviewers[]=copilot"
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gh api call will exit non-zero if the reviewer is already requested (GitHub returns a 422 validation error), which can make the workflow flaky if the PR is toggled draft/ready multiple times or the reviewer is added manually. Consider making the step idempotent (check existing requested reviewers first) or handle the “already requested” response without failing the job.

Suggested change
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-f "reviewers[]=copilot"
PR_NUMBER=${{ github.event.pull_request.number }}
REPO=${{ github.repository }}
# Check if "copilot" is already a requested reviewer for this PR.
if ! gh pr view "$PR_NUMBER" --repo "$REPO" --json reviewRequests --jq '.reviewRequests[].login' 2>/dev/null | grep -qx "copilot"; then
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/$REPO/pulls/$PR_NUMBER/requested_reviewers" \
-f "reviewers[]=copilot"
fi

Copilot uses AI. Check for mistakes.
@imran-siddique imran-siddique merged commit 5ecb31f into main Mar 7, 2026
28 checks passed
@imran-siddique imran-siddique deleted the feat/copilot-auto-review branch March 7, 2026 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/cd CI/CD and workflows size/S Small PR (< 50 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants