Skip to main content

Using GitHub Copilot code review

Learn how to request a code review from GitHub Copilot.

About Copilot 代码评审

GitHub Copilot can review your code and provide feedback. Where possible, Copilot's feedback includes suggested changes which you can apply with a couple of clicks.

Two types of Copilot 代码评审 are available:

  • Review selection: Highlight code and ask for an initial review (only available in VS Code)
  • Review changes: Request a deeper review of all your changes (available in VS Code and the GitHub website)

This version of the article relates to Copilot 代码评审 on the GitHub website. To see information about the review selection type of Copilot 代码评审, click the "Visual Studio Code" tool switcher at the top of the page.

Availability

Copilot 代码评审 on the GitHub website is a premium feature, available with the Copilot 专业版, Copilot Pro+, Copilot Business, and Copilot Enterprise plans.

Code review monthly quota

The review changes type of Copilot 代码评审 is a premium feature with a per-person monthly quota.

When you assign Copilot as a reviewer for a pull request, one premium request is deducted from your monthly quota each time Copilot posts comments to the pull request. See Understanding and managing requests in Copilot.

If a repository is configured to automatically request a code review from Copilot for all new pull requests, the premium request usage is applied to the quota of the pull request author. If a pull request is created by GitHub Actions or by a bot, the usage will apply to the user who triggered the workflow (if identifiable), or to a designated billing owner.

When you reach your monthly quota you will not be able to get a code review from Copilot until your quota resets—unless you upgrade your Copilot plan or enable additional premium requests.

Language support

Copilot 代码评审 on the GitHub website supports all languages.

Validating Copilot code reviews

警告

Copilot isn't guaranteed to spot all problems or issues in a pull request, and sometimes it will make mistakes. Always validate Copilot's feedback carefully, and supplement Copilot's feedback with a human review.

For more information, see 负责任地使用 GitHub Copilot 代码评审.

Requesting a review from Copilot

These instructions explain how to use Copilot 代码评审 in the GitHub website. To see instructions for other popular coding environments, use the tool switcher at the top of the page.

Requesting a pull request review from Copilot

  1. On GitHub.com, create a pull request or navigate to an existing pull request.

  2. Open the Reviewers menu, then select Copilot.

    Screenshot of selecting 'Copilot' from the 'Reviewers' menu.

  3. Wait for Copilot to review your pull request. This usually takes less than 30 seconds.

  4. Scroll down and read through Copilot's comments.

    Screenshot of a code review left by Copilot.

    Copilot always leaves a "Comment" review, not an "Approve" review or a "Request changes" review. This means that Copilot's reviews do not count toward required approvals for the pull request, and Copilot's reviews will not block merging changes. For more details, see 批准需要审查的拉取请求.

  5. Copilot's review comments behave like review comments from humans. You can add reactions to them, comment on them, resolve them and hide them.

    Any comments you add to Copilot's review comments will be visible to humans, but they won't be visible to Copilot, and Copilot won't reply.

Working with suggested changes provided by Copilot

Where possible, Copilot's feedback includes suggested changes which you can apply with a couple of clicks.

If you're happy with the changes, you can accept a single suggestion from Copilot and commit it, or accept a group of suggestions together in a single commit. For more information, see 在拉取请求中加入反馈.

Providing feedback on Copilot's reviews

You can provide feedback on Copilot's comments directly within each comment. We use this information to improve the product and the quality of Copilot's suggestions.

  1. On a pull request review comment from Copilot, click the thumbs up (👍) or thumbs down (👎) button.

    Screenshot showing a Copilot 代码评审 comment with the thumbs up and thumbs down buttons.

  2. If you click the thumbs down button, you're asked to provide additional information. You can, optionally, pick the reason for your negative feedback and leave a comment before clicking Submit feedback.

    Screenshot of the form for providing additional information when you give negative feedback on a comment from Copilot.

Requesting a re-review from Copilot

When you push changes to a pull request that Copilot has reviewed, it won't automatically re-review your changes.

To request a re-review from Copilot, click the button next to Copilot's name in the Reviewers menu. For more information, see 请求拉取请求审查.

注意

When re-reviewing a pull request, Copilot may repeat the same comments again, even if they have been dismissed with the "Resolve conversation" button or downvoted with the thumbs down (👎) button.

Enabling automatic reviews

By default, you manually request a review from Copilot on each pull request, in the same way you would request a review from a human. However, you can set up Copilot to automatically review all pull requests. See Configuring automatic code review by Copilot.

Customizing Copilot's reviews with custom instructions

注意

Copilot 代码评审 的自定义指令目前处于公共预览版阶段,未来可能会有所变动。

该功能适用于 Copilot 专业版、Copilot Pro+、Copilot Business 和 Copilot Enterprise 计划。

在公共预览版期间,如果你使用 Copilot Business 或 Copilot Enterprise 计划,则为你提供计划的组织或企业必须已启用“Opt in to preview features”设置****。 请参阅“Managing policies for Copilot in your organization”或“Managing policies and features for Copilot in your enterprise

你可以通过添加一个自定义指令文件,来自定义 Copilot 代码评审 的行为。 为此,请在仓库中创建一个 .github/copilot-instructions.md 文件,并添加你希望 Copilot 在评审代码时考虑的自然语言文本内容。 此文件与 Copilot Chat 使用的 copilot-instructions.md 文件相同。 请参阅“Adding repository custom instructions for GitHub Copilot”。

要启用或禁用代码评审的自定义指令,请前往仓库的设置,然后导航到 Copilot 下的“Code Review”,切换“Use custom instructions when reviewing pull requests”选项的开关********。

示例

以下是一个 .github/copilot-instructions.md 文件的示例,其中包含三条指令,这些指令将应用于仓库中所有 Copilot 代码评审。

When performing a code review, respond in Spanish.

When performing a code review, follow our internal security checklist.

When performing a code review, focus on readability and avoid nested ternary operators.

Customizing Copilot's reviews with coding guidelines

注意

自定义编码准则功能仅适用于 Copilot Enterprise 计划,目前仅限选定客户使用。

使用 Copilot 代码评审 查看 Visual Studio Code 或 GitHub 网站中的更改时,可以使用以自然语言编写的自定义编码准则来自定义 Copilot 的评审。 Copilot 在评审代码时将根据编码准则提供反馈。 有关详细信息,请参阅“Configuring coding guidelines for GitHub Copilot code review”。

基于编码准则生成的注释将包含一条消息,并突出显示了其源。