Skip to main content

此版本的 GitHub Enterprise Server 将于以下日期停止服务 2026-03-17. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

代码扫描合并保护

代码扫描规则可防止含有潜在漏洞的拉取请求被合并。

谁可以使用此功能?

Repository administrators and organization owners

Rulesets are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, and GitHub Enterprise Cloud.

Rulesets for code scanning merge protection

A ruleset is a named list of rules that control how people can interact with branches and tags in your repositories. You can add code scanning rules to rulesets to prevent pull requests from being merged when any of the following conditions are met:

  • A required tool finds a code scanning alert of a severity that is defined in the ruleset.
  • A required tool's analysis is still in progress.
  • A required tool is not configured for the repository.

Typically, you should use code scanning merge protection on long-lived feature branches, where you want to guarantee code has been analyzed before pull requests can be merged.

Configuring a code scanning rule will not automatically enable code scanning. To learn how to enable code scanning, see Configuring default setup for code scanning.

注意

  • Merge protection with rulesets is not related to status checks. For more information about status checks, see About status checks.

Availability

You can set code scanning merge protection with rulesets:

  • At the repository level
  • At the organization level (GitHub Enterprise plans only)

Exceptions and limitations

Merge protection with rulesets will not apply to:

  • Merge queue groups
  • Dependabot pull requests analyzed by default setup

Additionally, all the lines of code identified by an alert must exist in the pull request diff. For more information, see SARIF support for code scanning.

Next steps

To configure a ruleset that requires code scanning results, see Set code scanning merge protection.