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.

Who can use this feature?

Repository owners, organization owners, and users with the admin role

Note

This feature is in public preview and subject to change.

Prerequisites

Creating a coverage threshold rule

  1. On GitHub, navigate to the main page of the repository.

  2. Under your repository name, click Settings. If you cannot see the "Settings" tab, select the dropdown menu, then click Settings.

    Screenshot of a repository header showing the tabs. The "Settings" tab is highlighted by a dark orange outline.

  3. In the left sidebar, under "Code and automation," click Rules, then click Rulesets.

    Screenshot of the sidebar of the "Settings" page for a repository. The "Rules" sub-menu is expanded, and the "Rulesets" option is outlined in orange.

  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.