注意
The rule to require secret scanning alerts to be resolved before merging is in 公开预览 and subject to change.
The Require secret scanning alerts are resolved rule is available for rulesets that target branches in repositories. You can use the rule to block a pull request from merging when either of these conditions applies:
- A secret scanning scan has not completed for the head commit of the pull request.
- A commit in the pull request introduced an open secret scanning alert that matches a secret type selected in the ruleset.
The rule supports provider, custom, and generic patterns. It does not support AI-detected secrets.
Prerequisites
The repositories that you want to protect must have:
- Either GitHub Secret Protection or GitHub Advanced Security enabled
- Secret scanning enabled. See 为存储库启用机密扫描.
Creating a merge protection ruleset for a repository
-
在 GitHub 上,导航到存储库的主页面。
-
在仓库名称下,单击 “Settings”****。 如果看不到“设置”选项卡,请选择“”下拉菜单,然后单击“设置”。

-
在左侧边栏中的“代码和自动化”下,单击 “规则集”,然后单击“ 规则集”。
-
Click New ruleset.
-
Click New branch ruleset.
-
在“规则集名称”下,键入规则集的名称。
-
(可选)若要更改默认强制实施状态,请单击 “Disabled”,并选择强制实施状态****。 若要定位分支或标记,在“目标分支”或“目标标记”部分,选择“添加目标”****,然后选择包含或排除分支或标记的方式。 可以使用
fnmatch语法基于模式包含或排除分支或标记。 有关详细信息,请参阅“使用fnmatch语法”。
可以将多个目标条件添加到同一规则集。 例如,可以包含默认分支,包含与模式 *feature* 匹配的任何分支,然后专门排除与模式 not-a-feature 匹配的分支。
- Under "Branch protections", select Require secret scanning alerts are resolved.
- Under "Secret types", select one or more types of secrets that should block merging:
- Provider patterns
- Custom patterns
- Generic patterns 单击“创建****”即可完成规则集的创建。 如果规则集的强制执行状态设置为“活动”,规则集会立即生效。
可以查看规则集的见解,了解规则如何影响参与者。 如果强制执行状态设置为“评估”,则可以看到规则集处于活动状态时已经传递或失败的操作。 有关规则集见解的详细信息,请参阅“管理存储库的规则集”。
For information about configuring bypass permissions and other ruleset settings, see 创建存储库的规则集.
Creating a merge protection ruleset for repositories in an organization or enterprise
You can create this ruleset for repositories in your organization, or create it for an enterprise to apply merge protection consistently across repositories in multiple organizations.
Accessing organization ruleset settings
-
在 GitHub 的右上角,单击个人资料图片,然后单击“ Your organizations”****。
-
单击以选择一个组织。
-
在组织名称下,单击 “Settings”****。 如果看不到“设置”选项卡,请选择“”下拉菜单,然后单击“设置”********。

-
在边栏中的“代码、规划和自动化”下,单击 “存储库”,然后单击“规则集”。
Accessing enterprise ruleset settings
- 导航到您的企业。 例如,从 GitHub.com 上的 公司 页面。
- 在页面顶部,单击“ 策略”。
- Under "Policies", click Code.
Configuring the ruleset
-
Click New ruleset.
-
Click New branch ruleset.
-
在“规则集名称”下,键入规则集的名称。
-
(可选)若要更改默认强制实施状态,请单击 “Disabled”,并选择强制实施状态****。
-
If you are creating an enterprise-level ruleset, under "Target organizations", choose the organizations that the ruleset will apply to.
-
Under "Target repositories", choose the repositories that the ruleset will apply to. 若要定位分支或标记,在“目标分支”或“目标标记”部分,选择“添加目标”****,然后选择包含或排除分支或标记的方式。 可以使用
fnmatch语法基于模式包含或排除分支或标记。 有关详细信息,请参阅“使用fnmatch语法”。
可以将多个目标条件添加到同一规则集。 例如,可以包含默认分支,包含与模式 *feature* 匹配的任何分支,然后专门排除与模式 not-a-feature 匹配的分支。
- Under "Branch protections", select Require secret scanning alerts are resolved.
- Under "Secret types", select one or more types of secrets that should block merging:
- Provider patterns
- Custom patterns
- Generic patterns 单击“创建****”即可完成规则集的创建。 如果规则集的强制执行状态设置为“活动”,规则集会立即生效。
可以查看规则集的见解,了解规则如何影响参与者。 如果强制执行状态设置为“评估”,则可以看到规则集处于活动状态时已经传递或失败的操作。 有关规则集见解的详细信息,请参阅“管理存储库的规则集”。
For information about configuring bypass permissions and other ruleset settings, see 创建组织中存储库的规则集 and 使用规则集在企业中强制实施代码治理.
Unblocking a pull request
When this rule blocks a pull request because of open alerts, you must resolve each alert that matches the secret types selected in the ruleset. See 解决机密扫描产生的警报.