Sub topic 9
Setting up automatic reviews
This chapter assumes you can already request a Copilot review by hand from the Reviewers menu. It also assumes you can read Copilot's comments and know what repository instruction files do. It covers how to make Copilot review pull requests without anyone asking, which settings control that, and what can go wrong.
Why automate the request
A manual request depends on someone remembering to make it. Reviews also tend to get requested late, after a human reviewer has already spent time on the pull request. Automatic reviews remove the step. Copilot's comments are usually there by the time a person opens the pull request, so the human reviewer can skip the mechanical issues Copilot already flagged.
Automation also has costs. Every pull request gets a review whether or not it is useful. Teams that ignore the comments can build a habit of dismissing all of them. The sections below describe the controls so you can decide where automation fits.
The two ways to turn it on
GitHub offers two separate mechanisms. They differ in who configures them and which pull requests they cover.
| Mechanism | Who configures it | What it covers | Typical use |
|---|---|---|---|
| Personal setting | Each user, in their own Copilot settings | Pull requests that user creates | An individual who wants a review on every pull request they open |
| Repository or organization ruleset | A repository admin, or an organization owner | Pull requests that target the branches the ruleset matches | A team policy that applies to everyone |
A ruleset is the better tool for team consistency, because it does not depend on each person changing a personal setting. The personal setting suits solo work, or a team that has not agreed on a policy yet.
The menu labels and the plans that include each option change over time. Check the current GitHub documentation for exact names and availability before you write them into a team guide.
The personal setting
The personal setting lives in your own Copilot settings on GitHub, not in any repository. You turn on automatic code review there, and Copilot then reviews pull requests you create without being requested.
Points to know:
- It follows you, not the repository. A pull request opened by a teammate who has not enabled the setting gets no automatic review from your choice.
- It requires a Copilot plan that includes code review. If your plan does not include the feature, the option is missing or disabled.
- It covers pull requests you create. It does not cover a pull request you were only asked to review.
This setting is useful for trying automation before you propose a team policy.
Repository rulesets
A ruleset is a GitHub feature for applying rules to branches or tags. One rule in a branch ruleset asks Copilot to review pull requests automatically.
To set it up in a repository:
- Open the repository on GitHub and go to Settings.
- Open Rules, then Rulesets.
- Select New ruleset and choose New branch ruleset.
- Give the ruleset a name, for example
copilot-review. - Set Enforcement status to Active. A ruleset left on Disabled does nothing.
- Under Target branches, add the branches whose pull requests should get reviews. The default branch is the usual choice.
- Under Branch rules, enable Automatically request Copilot code review.
- Choose the sub-options described in the next section.
- Select Create.
Organization owners can create the same kind of ruleset at the organization level and target many repositories at once. That is the practical route when a company wants one policy across dozens of repositories.
Target branches matter
The ruleset applies to a pull request based on the branch the pull request merges into. A ruleset that targets main will not review a pull request whose base is release/2.x, unless you add that pattern. If automatic reviews seem to be missing on some pull requests, the base branch is the first thing to check.
The review options
The rule has options that control when Copilot reviews. Their labels have been close to the following:
- Review new pushes. Without this option, Copilot reviews a pull request once, when it opens. With it, Copilot reviews again each time someone pushes new commits.
- Review draft pull requests. Without this option, Copilot skips drafts and reviews when the pull request is marked ready for review. With it, Copilot reviews drafts too.
Each option has a trade-off.
| Option | Benefit | Cost |
|---|---|---|
| Review new pushes | Fixes get checked without a manual re-request | More comments on long-running pull requests, and more noise from repeated or similar findings |
| Review draft pull requests | Early feedback while the work is still changing | Comments on unfinished code that the author already knows is incomplete |
A reasonable starting point for most teams is to leave both off, then enable Review new pushes once people trust the comments. Turn on draft reviews only if your team routinely uses drafts for work that is mostly done.
What an automatic review is, and is not
An automatic review is the same review you get from a manual request. Three consequences follow.
- It posts a "Comment" review. It never approves and never requests changes. It does not satisfy a rule that requires approving reviews, and it does not block a merge.
- It uses your instruction files. The repository-wide file at
.github/copilot-instructions.mdand any path-specific files under.github/instructions/guide automatic reviews the same way they guide manual ones. Automation without good instructions produces generic comments, so write the instructions first. - It is non-deterministic. Two reviews of the same diff can differ. Do not treat a clean automatic review as proof that the code is correct.
A minimal instruction file to pair with automation
Because automatic reviews run on every pull request, noisy output costs more than it does with manual requests. A short instruction file keeps the comments focused. This is a repository-wide file saved as .github/copilot-instructions.md:
# Review guidelines
- Flag any new database query that is built by string concatenation.
- Point out public functions that have no tests in the same pull request.
- Prefer comments about correctness and security over style; formatting is enforced by the linter.
- Keep each comment short and say why the change is needed.The third line matters most for automation. It tells Copilot to leave formatting to the linter, which removes a large class of repetitive comments.
Checking that it worked
After you create a ruleset, open a new pull request that targets a matched branch. Then check these things:
- Copilot appears in the Reviewers list without anyone adding it.
- A review from Copilot appears with the "Comment" status.
- If you enabled Review new pushes, push another commit and confirm that a second review appears.
You can also check from the command line with the GitHub CLI. This command lists the reviews on pull request 42 whose author login starts with copilot:
gh pr view 42 --json reviews \
--jq '.reviews[] | select(.author.login | startswith("copilot")) | {state, submittedAt}'An empty result means no Copilot review has been posted yet. The review can take a short while to appear, so wait a minute before you decide something is broken.
Troubleshooting
When automatic reviews do not appear, work through the causes in this order:
- The ruleset is not active. Confirm the enforcement status is Active, not Disabled.
- The base branch is not targeted. Compare the pull request's base branch to the ruleset's target patterns.
- The pull request is a draft. Without Review draft pull requests, nothing happens until the pull request is marked ready.
- No new review after a push. Without Review new pushes, only the first review happens. Re-request manually, or enable the option.
- Plan or seat problems. The pull request author or the organization may lack a plan that includes code review. Ask an administrator to check the Copilot plan and policies.
- Overlapping rulesets. Several rulesets can apply to the same branch. Rules from all of them combine, so a disabled ruleset elsewhere does not cancel an active one.
- Content Copilot cannot review. Very large diffs, or files of types it does not review, may get a partial review or fewer comments. A missing comment on a file does not mean the file is fine.
Keeping automation useful
Automatic reviews can turn into background noise. Three habits prevent that:
- Tune instructions based on what you dismiss. If reviewers keep dismissing the same kind of comment, add a line to the instruction file that tells Copilot to skip it.
- Resolve or dismiss every comment. An unresolved thread from Copilot left on a pull request confuses the next reader about what was handled.
- Keep humans in the loop. Treat the automatic review as a first pass. A teammate still decides whether the change is correct, fits the design, and is ready to merge.
Exercise
Your team enabled a ruleset with "Automatically request Copilot code review" on the main branch, with both sub-options off. A developer opens a draft pull request against main, pushes two more commits, then marks it ready for review. A second developer opens a pull request against release/2.x. What reviews does Copilot post on each, and which settings would you change to get a review on every push of the first pull request?
Show answer
On the first pull request, Copilot does not review while it is a draft, because "Review draft pull requests" is off. The two commits pushed during the draft get no review. When the pull request is marked ready, Copilot posts one review. Later pushes get none, because "Review new pushes" is off. On the release/2.x pull request, Copilot posts nothing, because the ruleset targets only main. To get a review on each push of the first pull request, enable "Review new pushes". To also get reviews while it is a draft, enable "Review draft pull requests". To cover the second pull request, add release/2.x (or a pattern such as release/**) to the ruleset's target branches. Even with all of this, the reviews have the "Comment" status and do not replace the required human approval.