注意
自定义编码准则功能仅适用于 Copilot Enterprise 计划,目前仅限选定客户使用。 See Adding repository custom instructions for GitHub Copilot.
About coding guidelines
You can provide Copilot with a set of coding guidelines, written in natural language, that will help it review your code in a way that aligns with your organization's coding style and best practices. For more information—including examples of coding guidelines—see About coding guidelines for GitHub Copilot code review.
Creating a coding guideline
-
在 GitHub 上,导航到存储库的主页面。
-
在存储库名称下,单击 “设置”。 如果看不到“设置”选项卡,请选择“”下拉菜单,然后单击“设置”。
-
In the "Code & automation" section of the sidebar, click Copilot, then Code review.
-
Click Create guideline.
-
Under "Name," give the coding guideline a name.
-
Under "Description," provide a description of the coding guideline up to 600 characters long. This will be used by Copilot to understand your coding style and to decide when to leave a comment.
How you write your description has a big impact on the quality of comments that Copilot will generate. For help with writing effective coding guidelines, see About coding guidelines for GitHub Copilot code review.
-
Optionally, limit the coding guideline to specific file types or paths by clicking Add file path and adding path patterns.
You can use
fnmatch
syntax to define paths to target, with*
as a wildcard to match any string of characters.由于 GitHub 对
File.fnmatch
语法使用File::FNM_PATHNAME
标记,因此*
通配符与目录分隔符 (/
) 不匹配。 例如,qa/*
将匹配以qa/
开头并包含单个斜杠的所有分支,但不会匹配qa/foo/bar
。 可以使用qa/**/*
在qa
后面包含任意数量的斜杠,这将匹配qa/foo/bar/foobar/hello-world
。 还可以使用qa**/**/*
扩展qa
字符串,以使规则更具包容性。有关语法选项的详细信息,请参阅 fnmatch 文档。
-
Test your coding guideline to make sure it works as expected.
- Click Add sample.
- Add your own sample, or press Generate code sample to automatically generate a code sample based on your title and description.
- Click Save to save the code sample.
- Test the coding guideline against your sample by pressing Run.
-
Save your coding guideline, and turn it on, by clicking Save guideline.