Api/qualityprofiles/projects does not return projects for default profile

q_profiles
web_api
sonarqube

(Hubert Kooij) #1

Hi, I’m running SonarQube 6.7.1 (build 35068) and I think I found an issue with the “api/qualityprofiles/projects” endpoint.
I need to retrieve all projects that are using a specific Quality Profile. The Quality Profiles can be a specific profile, or the default one. Image top part.

When I retrieve the QualtiyProfiles via “api/qualityprofiles/search” I do get back the default profile.

When I then try to retrieve all projects that are linked to a Quality Profile via “api/qualityprofiles/projects?key=…”
The return for the specifically linked Quality Profiles (E.g. MultiOne High/Medium/Low) return a list of projects associated with the Quality Profile.
When I try to do the same with the default Quality Profile no projects are returned. However when I go to specific projects that do use the default Quality Profile, I can see that it is linked. Image lower part

I would expect that all projects that are linked to the default Quality Profile are being retrieved.

So far I have not been able to work around this issue. I tried to use the selected parameter, but then I would get back all projects also not related the the Quality Gate.

I merged the two images together since I was only allowed to upload one…


(Julien Lancelot) #2

Hi @Hubert,

The goal of api/qualityprofiles/projects is to returned the list of projects that have been explicitly associated to a given quality profile.
By definition, a quality profile set as default on a language have no associated project.

So, as your need is to

retrieve all projects that are using a specific Quality Profile

If this quality profile is not set as default, then the list of projects returned by api/qualityprofiles/projects is exactly what you need !

Regards


(Hubert Kooij) #3

Hi @julienlancelot,

Maybe by stating

a specific Quality Profile

it was not clear enough that for me the default profile also is a specific profile.

But that would mean that there is no way to retrieve all projects that are using the default Quality Profile?

Regards


(Julien Lancelot) #4

In this case, it will not be easy indeed to get the list of projects that will use the default quality profile…
May I ask you which use case is requiring to get this information ?


(Hubert Kooij) #5

We are working on a tool that contains a lot of legacy code, which has lower code coverage.
We identified via PRISMA which components are most important for our customer and then decided on 3 different quality profiles based on the outcome… (High Medium Low) These profiles have for example different requirements for code coverage. High at least 60% vs Low at least 20%. All new components that we develop are linked to the “default profile” which has a minimum coverage of 70%.

The quality department of the customer now wants to know how many of the components reach the intended coverage target.
Since I do not want to figure this out manually for over 100 projects. I tried to lookup which projects are in which quality profile and then for each project retrieve the line_coverage metric.
This works for all the non default quality profiles, however I now mis about 40 projects because they are linked to the default profile.


(Julien Lancelot) #9

Hi @Hubert,

I’m sorry, but the use case you’re describing is not a common use cases, so except if we receive other feedbacks about this, nothing will be done on our side.

The only thing I could see is that you could use tags to categorize your projects.

Regards


(Hubert Kooij) #10

Hi @julienlancelot,

Thats unfortunate.
I still find it strange you can’t retrieve the quality profiles used for all projects but only for a specific set. In my opinion that makes no sense. If you can’t do it for all then why can you do it for some.

Regarding your suggestion

The only thing I could see is that you could use tags to categorize your projects.

I guess in essence that is the same as assigning the projects that use the default quality profile a specific one. Which would mean a manual action anyway. So I’ll guess I’ll assign all projects a non default quality profile.

Thanks for your support!

Regards


(G Ann Campbell) #11

Hi,

Well, that’s because:

Explicitly, the nature of a default is that it’s what you get when you don’t make a choice. So there’s no good way to retrieve the list of projects where no choice was made.

Still, if you really want to do this, start with a list of all projects. Then get a list of profiles, and on a per-profile basis you can remove from the “all projects” list the ones that are specifically assigned to profiles. When you’ve iterated all the profiles, what’s left in “all projects” are the ones using the default profile.

All that said, I really don’t understand why you’re talking about managing coverage requirements using profiles. It seems to me that you should be using Quality Gates for this instead. Of course, the same default/specific assignment setup exists there too.

Ann


(Hubert Kooij) #14

Hi @ganncamp

All that said, I really don’t understand why you’re talking about managing coverage requirements using profiles. It seems to me that you should be using Quality Gates for this instead. Of course, the same default/specific assignment setup exists there too

I completely agree with you on the fact that we should check if a project matches the code coverage with a quality gate. We have made one for each of our projects and our builds also fail if a quality gate is not met.

However we also implemented the “water leak principle” and therefor if we say the minimum should be 60% and a project has already 65% coverage the quality gate minimum coverage is set to 65% otherwise we would allow new code to lower the overall coverage.

The 60% is defined in the Quality Profile. Hence for me to check if the code coverage is high enough for a profile, I need to know to which profile the project belongs.

Maybe we are abusing the Quality Profiles for something that they are not meant to be used for. That is also a possibility.

Hubert