Search code examples
githubjestjsgit-mergepull-request

How to restrict PR merge if code coverage is less?


Is there any way that let's me restrict merging two branches if one has less code coverage than what is expected? I use jest and added coverageThreshold in package.json file. But even though the coverage was less when I ran coverage, the branch was allowed to merge.

Couldn't find anything in Github settings for branch protection as well.


Solution

  • Branch protection rules are under Settings>Branches for the repo.

    To add code coverage requirements, like anything else, you need to add pass/fail statuses to the github actions (or if you use a separate system like Jenkins, that needs to register statuses) and then say that the statuses are required in the rule. Not sure if you can do that on all github plans.