我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

此版本的 GitHub Enterprise 将停止服务 此版本的 GitHub Enterprise 已停止服务 2020-08-20. 即使针对重大安全问题,也不会发布补丁。 要获得更好的性能、改进的安全性和新功能,请升级到 GitHub Enterprise 的最新版本。 如需升级方面的帮助,请联系 GitHub Enterprise 支持

文章版本: Enterprise Server 2.18

关于代码所有者

您可以使用 CODEOWNERS 文件定义负责仓库代码的个人或团队。

您可以在具有 GitHub Free 和组织的 GitHub Free 的公共仓库以及具有 GitHub Pro、GitHub Team、GitHub Enterprise Cloud 和 GitHub Enterprise Server 的公共和私有仓库中定义代码所有者。

本文内容

具有管理员或所有者权限的人员可以在仓库中创建 CODEOWNERS 文件。

您选择作为代码所有者的人员必须具有仓库的写入权限。 当代码所有者是团队时,该团队必须拥有写入权限,即使团队的所有成员都已经直接通过组织成员资格或通过另一个团队成员资格直接拥有写入权限。

关于代码所有者

当有人打开修改代码的拉取请求时,将自动请求代码所有者进行审查。 不会自动请求代码所有者审查拉取请求草稿。 有关拉取请求草稿的更多信息,请参阅“关于拉取请求”。将拉取请求草稿标记为可供审查时,代码所有者会自动收到通知。 如果将拉取请求转换为草稿,则已订阅通知的用户不会自动取消订阅。 更多信息请参阅“更改拉取请求的阶段”。

当具有管理员或所有者权限的人员启用必需审查时,他们也可选择性要求代码所有者批准后,作者才可合并仓库中的拉取请求。 更多信息请参阅“启用拉取请求的必需审查”。

CODEOWNERS 文件位置

要使用 CODEOWNERS 文件,请在仓库中您要添加代码所有者的分支的根目录 docs/.github/ 中,创建一个名为 CODEOWNERS 的新文件。

每个 CODEOWNERS 文件将为仓库中的一个分支分配代码所有者。 因此,您可以为不同的分支分配不同的代码所有者,例如为 master 分支的代码基础分配 @octo-org/codeowners-team,为 gh-pages 分支的 GitHub Pages 站点分配 @octocat

为使代码所有者接收审查请求,CODEOWNERS 文件必须在拉取请求的基本分支上。 例如,如果您将 @octocat 分配为仓库 gh-pages 分支上 .js 文件的代码所有者,则在头部分支与 gh-pages 之间打开更改 .js 文件的拉取请求时,@octocat 将会收到审查请求。

CODEOWNERS 语法

CODEOWNERS 文件使用遵循 gitignore 文件中所用规则的模式。 模式后接一个或多个使用标准 @username@org/team-name 格式的 GitHub 用户名或团队名称。 您也可以通过已经添加到其 GitHub Enterprise 帐户的电子邮件地址来指代用户,如 user@example.com

If any line in your CODEOWNERS file contains invalid syntax, the file will not be detected and will not be used to request reviews. Invalid syntax includes inline comments and user or team names that do not exist on GitHub Enterprise.

CODEOWNERS 文件示例

# This is a comment.
# Each line is a file pattern followed by one or more owners.

# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.
*       @global-owner1 @global-owner2

# Order is important; the last matching pattern takes the most
# precedence. When someone opens a pull request that only
# modifies JS files, only @js-owner and not the global
# owner(s) will be requested for a review.
*.js    @js-owner

# You can also use email addresses if you prefer. They'll be
# used to look up users just like we do for commit author
# emails.
*.go docs@example.com

# In this example, @doctocat owns any files in the build/logs
# directory at the root of the repository and any of its
# subdirectories.
/build/logs/ @doctocat

# The `docs/*` pattern will match files like
# `docs/getting-started.md` but not further nested files like
# `docs/build-app/troubleshooting.md`.
docs/*  docs@example.com

# In this example, @octocat owns any file in an apps directory
# anywhere in your repository.
apps/ @octocat

# In this example, @doctocat owns any file in the `/docs`
# directory in the root of your repository.
/docs/ @doctocat

延伸阅读

问问别人

找不到要找的内容?

联系我们