What you're looking for is Coverage on New Code which is included in the default Quality Gate with an 80% requirement.
Unfortunately, since you're looking to head-off merging low-coverage branches into master, that means you're after robust branch analysis. It's in the plans, but we're not there yet. Further, PR analysis (always a first candidate when you're dealing with branches) won't help either because a) it doesn't look at coverage b) it doesn't check the branch's quality gate status (technically there is no QG status for a PR)
As a (somewhat painful altho likely automate-able) workaround:
- seed an extra SQ project for the branch with an analysis of master from just before the branch split.
- Use a
sonar.version value of "master"*. This establishes your leak baseline
- Be sure to use the
sonar.branch analysis property to distinguish it from your analysis of master.
- configure the branch project's leak period to be
since_previous_version
- update your branch project analysis job to point to the branch and reset
sonar.version to "branch"*
- institute a process to check branch QG status before merge
- delete the branch SQ project after branch deletion
*Or whatever value makes you happy
For the record, "new code" in this context means both lines added and (old) lines modified since the Leak Period started. Leak Period can be defined as the last X days (sub-optimal), since a given date (better but still not perfect), since a specific version, or since previous_version which will give you a floating leak period that follows version changes. To make sure that new code going into production meets your quality requirements, this last one is recommended but it means that the version string fed into your analysis needs to be kept up to date.
Edit 21June21
Measurement of Coverage on New Code is now available for both branches and PRs in all commercial editions.