Hi @Dinesh_Deva
We sort of have a similar need - we want to capture the issues that caused a PR or branch analysis to fail. Sometimes engineers will have some problem with an analysis, report it to us, but find a workaround and fix the problem.
By the time we look at it, there has been a new analysis and Sonar does not provide a way to “look back” at historic analyses to see what the problems were, so we had to come up with our own workaround which is this:
If an analysis fails, capture all of the new issues and all hotspots that contributed to the failure.
We use the qualitygates/project_status endpoint to determine which gates have failed, and then retrieve what we want from the issues/list and hotspots/list end points, depending on which things failed.
We use the list rather than search end points because those might fail with a 503 if issue indexing is in progress whereas the list ones will not. The downside is they do not have as rich a feature set for filtering, but they are good enough for our needs.
You may be able to get what you need e.g. from issues/list with inNewPeriod=true and resolved=true - I believe that should gives you all issues that were created and resolved in the new code period - which is essentially “the PR” for PR analyses. I have not tested this though so you would need to check if my reasoning is sound.
Or if you want all issues resolved, new or not (perhaps a better indicator of improving quality) then remove inNewPeriod=true and just have the resolved=true filter.
One limitation of this is that you need to do it immediately the analysis ends because it can only capture the issues at a point in time, so your builds will need to wait for the analysis to complete rather than running in the background.
Finally though, consider if this is giving you any real value at all - you want to report only on the issues that were raised and fixed in a PR. I could “game” the system by deliberately causing loads of issues in my PR and then fixing them - yah for me, I caused and fixed 100 issues in my PR, aren’t I great and isn’t Sonar adding lots of value? What does that even mean - that I am a terrible coder or good for me for fixing them? If the number goes down over time and next PR I only cause and fix 50 issues, have I improved as an Engineer? Is the PR smaller than the last one? Maybe it is simply less complex?
Why not simply show management the activity graphs which show the number of issues over time going down as existing issues are resolved and showing that the number of issues is not continuing to increase. You may be able to tie in then with a decrease in build (or test) failures or hotfixes as the devs produce better quality code.
That way you can show the trend over time towards quality…
anyway just a few ideas, hth.