Tech Bridge Log
Tech BridgeLog
🤖

How to Configure Copilot Automated Code Review with GitHub Rulesets

4 min read

This article explains how to use GitHub Rulesets to enable automated code reviews by GitHub Copilot for pull requests targeting specific branches.

GitHub has a feature that automatically requests a code review from GitHub Copilot when a pull request (PR) is created.
Leveraging this feature reduces the effort of manually assigning reviewers, streamlining the development flow and standardizing code quality.

This article explains the steps to enable Copilot's automated review for PRs targeting specific branches using Rulesets.

What is a Ruleset?

A Ruleset is a mechanism for applying protection rules and workflow constraints to a GitHub repository in bulk.
It allows for more flexible configuration than traditional Branch protection rules and can manage rules such as:

  • Merge restrictions for specific branches
  • Enforcement of commit signing
  • Mandatory status checks
  • Requesting automated code reviews by Copilot

In this article, we will focus on configuring "Automated code reviews by Copilot".

Prerequisites for Automated Review

Before configuring, please ensure the following conditions are met:

  • You have administrator privileges (Admin) for the repository.
  • "Copilot Code Review" is enabled in your GitHub Copilot plan.
  • The target branches (e.g., main or develop) are decided.

Configuration Steps

Create a Ruleset step-by-step from the repository settings screen.

1. Open the Ruleset Creation Screen

Open the Settings tab of the target repository and select Code and automation > Rules > Rulesets from the left sidebar.
Click the New ruleset button in the upper right corner of the screen to start creating a new ruleset.

new-ruleset

2. Enter Basic Information

Configure the basic settings for the ruleset.

  • Ruleset Name: Enter a name that is easy to manage (e.g., copilot-review-for-main).
  • Enforcement Status: Set to Active. This ensures the rule is applied immediately after saving.
  • Target branches: Select Include default branch or specify target branches like main using Include by pattern.

setting

3. Add Automated Review Rule

Find Automatically request Copilot code review in the list of settings and check the box to enable it.
With this setting, Copilot will be automatically added as a reviewer when a PR is created targeting the specified branch.

Consider the following options based on your operation:

  • Review new pushes: Set whether to re-review every time a new commit is pushed to the PR. Enable this if continuous quality checks are required.
  • Review draft pull requests: Set whether to review PRs in Draft state. Useful if you want early feedback.

4. Save Settings

Once all settings are complete, click the Create button at the bottom of the page to save the ruleset.
The configuration is now complete. From next time onwards, Copilot reviews will automatically start when a PR is created for the target branch.

Improving Review Quality: copilot-instructions.md

To align the accuracy and perspective of automated reviews with your project's policy, creating a .github/copilot-instructions.md file is recommended.
By placing this file in the root directory of the repository, you can provide review guidelines to Copilot.

Example Description:

  • Focus on checking for security vulnerabilities.
  • Point out complex logic that reduces readability.
  • Check if the project's naming conventions (camelCase, etc.) are followed.
  • Suggest adding test code if it is missing.

By giving specific instructions, you can expect practical reviews that align with team standards, rather than just simple syntax checks.

Summary

Configuring Copilot automated reviews using Rulesets is highly effective for automating the development process.

  • Reduced Effort: Automating reviewer assignment allows developers to focus on coding.
  • Stable Quality: Entrusting mechanical checks to Copilot allows for early detection of issues that humans might overlook.
  • Ensured Consistency: By combining with copilot-instructions.md, you can apply unified review standards across the entire team.

This feature is useful for maintaining code quality and improving development efficiency, from individual development to large-scale team development. Please consider introducing it.

Related Articles