注意
存储库策略目前为 公共预览版,可能会随时更改。 每个组织最多可以有 75 个策略和规则集,每个企业最多可以有 75 个策略和规则集。
若要控制仓库生命周期中的关键事件(例如谁可以创建或删除仓库),可以创建仓库策略。 仓库策略是一系列限制,可让你灵活控制影响的用户和目标仓库。
在仓库策略中,可以限制:
- 允许哪些可见性用于新仓库和可见性变更****。
- 谁可以创建仓库****。
- 谁可以删除仓库****。
- 谁可以从组织中转移仓库****。
- 人员如何命名仓库****。
Examples
可以使用仓库策略执行以下操作:
- 确保所有新仓库都使用特定的命名约定,例如
kebab-case。 - 防止删除仓库(组织管理员除外)。
- 只允许在企业的“开放源代码”组织中创建公共仓库。
- 防止将公共仓库更改为专用仓库,以避免潜在的元数据丢失。
Creating a repository policy
- 在 GitHub 的右上角,单击你的个人资料图片。
- 根据环境,单击“你的企业”,或单击“你的企业”,然后单击要查看的企业********。
- 在页面顶部,单击“ Policies”。
- Under "Policies", click Repository.
- Click New policy.
- Configure your new policy, then click Create. For help, consult the following subsections.
Policy name
Use something descriptive to communicate the purpose of the policy. Organization owners can view the policy, so good names help add clarity. For example: Prevent public repos on production.
Enforcement status
如果不想在创建时执行策略,请设置为“Disabled”。 否则设置为“Active”。
Allow list
选择哪些角色可绕过此策略中的限制。****
Targets
Choose which organizations and repositories the policy applies to.
Target organizations
Select all organizations, choose a selection of existing organizations, or set a dynamic list by name. If you use Enterprise Managed Users, you can also choose to target all repositories owned by users in your enterprise.
If you set a dynamic list, you'll add one or more naming patterns using fnmatch syntax. For example, the string *open-source would match any organization with a name that ends with open-source. For syntax details, see 创建存储库的规则集.
Target repositories
Choose which repositories (current or future) to target in the selected organizations. You can select all repositories or set a dynamic list by custom property.
Policies
选择包含哪些限制。 当策略处于活动状态时,这些限制适用于所有目标仓库,但允许列表中的用户或团队可以绕过这些限制。
如果选择“限制名称”策略,则必须使用正则表达式语法来设置仓库名称必须匹配或不得匹配的模式****。 例如,执行 kebab-case 命名的模式看起来像 ^([a-z][a-z0-9]*)(-[a-z0-9]+)*$。
- 模式支持 RE2 语法。 请参阅 Google 的语法指南。
- 若要验证表达式,请单击“Test pattern”,然后输入模式和测试值****。
Delegating bypass of policies
注意
仓库策略委托绕过功能目前处于公共预览版阶段,后续可能发生变更。
仓库策略的委托绕过功能使你可以控制哪些人员可以绕过仓库删除和可见性更改的仓库策略。
通过委托绕过机制,仓库管理员必须提交请求才能更改仓库可见性或删除仓库。 该请求将被发送至指定的评审组,由评审人员决定是批准还是拒绝绕过仓库策略的请求。
如果绕过仓库策略的请求获得批准,所请求的更改将立即执行。 如果请求被拒绝,则不会执行请求的更改,但允许重新提交请求。
要配置委托绕过功能,企业所有者或组织所有者需先创建"绕过列表"。 绕过列表应包含特定角色和团队(如团队或仓库管理员),这些人员将负责监督绕过仓库策略的请求。 有关详细信息,请参阅“治理人员如何在企业中使用仓库”。
Next steps
Create rulesets to consistently govern important branches in your enterprise's repositories. See Protecting branches in your enterprise with rulesets.