I’m looking to apply the SonarCloud quality gates within a more limited, dynamic scope. In particular, I’d like to understand if it’s possible to limit the quality gate (and therefore the static code analysis) to a non-root directory within a monorepo.
For example, consider that we have the following folder structure:
In my PR, I added some new functions in /root/app1/app.py. As a result, I’d like my code coverage condition (e.g. >80% test coverage) in my quality gate to only look at the overall code coverage in root/app1 and not in app2 and app3. This rule should be applicable to other conditions as well like security, code smell, duplicated, etc.
Would this be possible with the current platform? If not, do others have experience with similar use-cases and how did you guys tackle it?
Unfortunately, AFAIK, you can only exclude files and folders from the coverage requirement but not have different levels of coverage requirements per folder.
Since Sonar can have a different gate for coverage on New Code, you could use that to require new code to have a certain level. The problem is that when you refactor legacy code, the refactoring is seen as ‘New Code’ so that can be a problem.
This is what I’m observing as well. It’s a shame because SonarCloud does collect the metrics (the bulk of it is reported in the coverage files sent to SonarCloud) and make it accessible via the UI.
The new code approach doesn’t quite fit because I’d like to enable flexibility for the application owners. If they’re already at a high standard, they should have a buffer that enables them to come back to the code to coverage later.