Skip to main content
Skip to content

Setting code coverage thresholds for pull requests

Prevent pull requests from being merged when uploaded code coverage falls below the 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.

How the code coverage rule works

The Restrict code coverage rule evaluates uploaded line coverage data against the configured thresholds. It does not wait for coverage uploads to complete.

To prevent a pull request from being merged before all expected coverage results are available, make each status check associated with an expected coverage upload a required status check. This includes coverage uploaded from separate jobs or workflows.

For more information about line coverage, see Code coverage reference.

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, planning, and automation", click Rulesets, then click Rulesets.

  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 line coverage percentage: enter a value to block pull requests where aggregated line coverage falls below this percentage.
    • Maximum line coverage drop: enter a value to block pull requests where line coverage drops by more than this many percentage points relative to the default branch.
  7. Click Create or Save changes.