Automatically request CoPilot reviews

Automatically request CoPilot reviews

..using GitHub branch rulesets

Automatically request CoPilot reviews

Rulesets are the new, more powerful way of enforcing branch protection and automation policies in GitHub

You can use branch rulesets to automatically request a review from GitHub CoPilot (assuming you are licensed). Let’s walk through how to do it, then I’ll show you what it looks like on one of my latest projects!

Rulesets vs branch protection

Branch protection without CoPilot can be set in two ways, if you’ve been in GitHub for a while, you’ll likely be familiar with this:

alt text { caption=“If you click “add branch ruleset”, it’ll take you to Settings -> Rules -> Rulesets (+ start the creation step)”}

Classic branch protection is slightly simpler, but Rulesets do branch protection and more, I recommend always using this in favour of the classic approach. For background info, check out the advantages as described in the GitHub documentation.

CoPilot review only works with Rulesets.

Add a branch ruleset

There are two ways to get there:

  • Your repository -> Settings -> Branches -> Add branch ruleset
  • Your repository -> Settings -> Rulesets -> Rules -> New ruleset -> New branch ruleset

Even though it may seem the classic way in, I prefer the first - less clicking!

Configuring the rule

Give it a name, set the enforcement to Active, and optionally specify who can bypass it:

alt text { caption=“If you click “The bypass functionality is one of the benefits over branch protection, it allows you to specify groups of people or bots that can bypass the set rules.”}

Set the branches to be targeted - I usually just do “include default branch” here - that will cover ‘main’ - or whatever you use as your default branch name.

alt text

Scroll down to rules - here’s where you enable CoPilot!

alt text

This works fine for solo developers β€” after all, you can’t require a review if there’s no one else to do it! If you’re in a team, you should consider stricter settings to ensure code is reviewed:

alt text

Above are some suggested defaults for the team scenario. And if you use CODEOWNERS to manage repository ownership, that setting should be enabled too.

The PR experience

So, here’s a PR I just raised:

alt text

“Copilot” is in the reviewers in the right and can be ‘requested’ (& re-requested) just like a person.

One of the things I like, is CoPilot will write a description of the change for you, saving you having to summarise the changes yourself:

alt text

The review process doesn’t support all languages and changes.

Sometimes it gets a bit confused too - it does support yml workflows, but in the above example that file was deleted. Occasionally it will also call out changes that it considered but did not include in the review.

Suggested changes

Like a human reviewer, Copilot will use inline comments, providing context to suggestions and a mechanism to “resolve”

alt text

Closing Thoughts

Having CoPilot review my PRs just makes sense. Sure, it’s not perfect, but it regularly catches details that both I and even CoPilot in the IDE miss.

If you’re working in GitHub, it’s a smart addition β€” give it a try today!

This post is licensed under CC BY 4.0 by the author.