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.

Copilot 代码评审 in Visual Studio Code supports two types of review:

  • Review selection: Highlight code and ask for an initial review
  • Review changes: Request a deeper review of all your changes

The current functionality and availability of the two types of review is summarized in the following table:

Review selectionReview changes
Available inVisual Studio CodeVisual Studio Code and the GitHub website
Premium/standard featureStandard feature available to all Copilot subscribersPremium feature. Available with the Copilot 专业版, Copilot Pro+, Copilot Business, and Copilot Enterprise plans. Per-person monthly quota applies.
DescriptionInitial review of a highlighted section of code with feedback and suggestionsDeeper review of all changes
Language supportAllAll
Custom coding guidelines supportNoYes, see Customizing Copilot's reviews with coding guidelines

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.

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”。

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

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

注意

Copilot 代码评审 is only available in Visual Studio Code with version 0.22 or later of the GitHub Copilot Chat extension.

Reviewing a selection of code

You can request an initial review of a highlighted selection of code in Visual Studio Code.

  1. In Visual Studio Code, select the code you want to review.

  2. Open the VS Code Command Palette

    • For Mac:
      • Use: Shift+Command+P
    • For Windows or Linux:
      • Use Ctrl+Shift+P
  3. In the command palette, search for and select GitHub Copilot: Review and Comment.

    Screenshot of the command palette in Visual Studio Code with the GitHub Copilot: Review and Comment command selected.

  4. Wait for Copilot to review your changes. This usually takes less than 30 seconds.

    Screenshot of the progress indicator when Copilot is performing a review in Visual Studio Code.

  5. If Copilot has any comments, they will be shown inline in your file, and in the Problems tab.

    Screenshot of a comment from Copilot in Visual Studio Code.

Reviewing changes

You can request a review for your staged or unstaged changes in Visual Studio Code.

  1. In VS Code, switch to the Source Control tab.

  2. To request a review on your unstaged changes, hover over Changes in the sidebar, and then click the Copilot 代码评审 - Changes button.

    Screenshot of the "Copilot 代码评审 - Changes" button in Visual Studio Code. The code review button is outlined in dark orange.

  3. To request a review on your staged changes, hover over Staged Changes in the sidebar, and then click the Copilot 代码评审 - Staged Changes button.

  4. Wait for Copilot to review your changes. This usually takes less than 30 seconds.

    Screenshot of the progress indicator when Copilot is performing a review in Visual Studio Code.

  5. If Copilot has any comments, they will be shown inline in your file(s), and in the Problems tab.

    Screenshot of a comment from Copilot in Visual Studio Code.

Working with suggested changes provided by Copilot

Where possible, Copilot's feedback includes suggested changes which you can apply with a single click.

Screenshot of a comment from Copilot in Visual Studio Code with a suggested change.

If you're happy with the change, you can accept a suggestion from Copilot by clicking the Apply and Go To Next button. Any changes you apply will not be automatically committed.

If you don't want to apply Copilot's suggested change, click the Discard and Go to Next button.

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.

To provide feedback, hover over the comment and click the thumbs up or thumbs down button.

Screenshot of a comment from Copilot in Visual Studio Code with feedback buttons displayed. The buttons are outlined in dark orange.

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”。

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

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

To use Copilot 代码评审, you must use Visual Studio version 17.14 or later. See the Visual Studio downloads page.

  1. In the Git Changes window, click Review changes with Copilot. This button appears as a comment icon with a sparkle.

  2. Copilot will begin reviewing your changes. After a few moments, a link showing the number of code review comments appears in the Git Changes window.

  3. Click the link to view and navigate the comments. If no issues are found, you’ll see the message: Copilot did not comment on any files.

  4. Copilot displays comments in your code with a summary of each potential issue. You can:

    • Review and make changes based on the suggestions.
    • Dismiss a comment using the downward arrow in the top-right corner of the comment box.
  5. To remove all review comments, click next to the code review link in the Git Changes window.

For more information on enabling and configuring Copilot 代码评审 in Visual Studio, see Review local changes with Copilot Chat in the Visual Studio documentation.