Unable to integrate automatic PR comments for newly changed code using SonarCloud

Hi Team,

We’re integrating SonarCloud with Azure DevOps for clean code and coding standardization. To achieve this, we have configured automatic PR comments in Azure DevOps with the help of SonarCloud analysis. However, the problem is that we are receiving PR comments for only old code changes, while our expectation is that the comments should apply only to the current PR, not the entire source code.

We need your help to resolve this issue. We have already gone through your community questions and answers, but nothing has helped us.

Thank you.

Hey there.

Have you already analyzed the main branch of your project? This typically happens when the main branch (the branch these PRs are targeting) hasn’t been analyzed.

Yes, the ‘main’ branch has not been analyzed yet, but we’re trying to configure it through another branch. Consider that we have the ‘main’ branch as the development branch, and from the development branch, we created a new branch called ‘sonarcloud-configuration.’ All our configuration setup is in this branch, not in development.

Thanks. This is ringing a bell, and I’m going to try and reproduce this. However in the meantime, can you double check that shallow cloning is turned off?

1 Like

I’m not receiving any comments after disabling shallow cloning with the setting of fetchDepth: 0. Could you please share any other suggestions or provide me with a solution if you find one?

It sounds like you’re on the right track if you’re no longer receiving PR comments for old code.

Have you tried intentionally introducing an issue in a PR (our rules site should give you inspiration, make sure it’s a rule enabled in your Quality Profile!)?

1 Like

Thank you, the issue has been fixed based on your suggestion. However, PR comments are not working for a few files. We’ll resolve that; I think it may be related to the Quality Gate.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.