Skip to main content

Restricting code coverage on pull requests

Protect your test coverage by automatically blocking pull requests that fall below the coverage levels your team requires.

谁可以使用此功能?

具有 管理员 角色的存储库所有者、组织所有者和用户

在本文中

注意

This feature is in 公开预览 and subject to change.

Prerequisites

Creating a coverage threshold rule

  1. 在 GitHub 上,导航到存储库的主页面。

  2. 在仓库名称下,单击 “Settings”****。 如果看不到“设置”选项卡,请选择“”下拉菜单,然后单击“设置”。

    存储库标头的屏幕截图,其中显示了选项卡。 “设置”选项卡以深橙色边框突出显示。

  3. 在左侧边栏的“代码和自动化”下,单击“规则”,然后单击“规则集” 。

    存储库“设置”页边栏的屏幕截图。 “规则”子菜单已展开,“规则集”选项以橙色轮廓突出显示。

  4. Create a new branch ruleset or click an existing one to edit it.

  5. Under "Branch rules", select Restrict code coverage.

  6. Expand Additional settings to configure thresholds. A value of 0 means that the threshold is disabled.

    • Minimum coverage percentage: enter a value to block pull requests where aggregated coverage falls below this percentage.
    • Maximum coverage drop: enter a value to block pull requests where coverage drops by more than this many percentage points relative to the default branch.
  7. Click Create or Save changes.