First, your version is past EOL. You should upgrade at your earliest convenience. Your upgrade path is:
8.7 → 8.9.1 → 9.0 (last step optional)
Regarding your questions, generally it’s best to keep it to one topic per thread. These are related, so I’ll try to address both, but if there are followups, I reserve the right to pick which fork to follow and ignore the other.
First, you want to set your Quality Gate up to fail for Issues on New Code. I don’t like to think that you would fail it for any issues (surely a new TODO comment shouldn’t cause a pipeline failure?) so I’ll just point out that you have multiple metrics at your disposal to make this work. And specifically, I’d really recommend you focus on ratings, so Reliability Rating on New Code, Security Rating on New Code & Maintainability Rating on New Code.
Once you’ve configured your QG, you’ll need to set up the pipeline failure. That’s well documented and I’ll go ahead & ask you to open a new thread if you have specific questions about it.
In fact, it sounds like you’re either looking for PR analysis or the “Reference Branch” setting for the New Code Period. I guess you want to set the project-level New Code Period to use the main branch as the reference branch - newly created branches will get that setting by default - and then set the main branch separately.
I have attempted to implement this solution and I have two follow-up questions as a result, please.
With regards to setting the New Code Period at the project level
Must it be the Main Branch that is used as the baseline or can any other branch that has been previously analyzed be used?
Also, when you say that newly created branches will get that setting by default, what happens to already existing branches that have already been scanned once before the change was made? What setting will they inherit on their second scan?
In my case, I have set the New Code Period and used an already existing branch Not Main as the Reference Branch. But when other already existing branches are scanned, nothing appears under New Code.
Then they’ll get the new project setting. But if they’ve been explicitly set to something else, they’ll retain that.
To be honest, I’ve never made time to play around with this setting. However, I believe there’s an element of chronology here. When was your Not Main created relative to the other branches in question?