Sonarqube Web API to filter NOSONAR rule from INFO severities

Greetings,
Sonarqube version - v7.9.1

Please find below code using Web API, this works well and displays below output. The INFO Rules should display only NOSONAR and ignore other Rules. Please suggest what filter has to be added in API to fetch only this 1 Rule (java:NoSonar) from INFO. Other severities works as expected.
metricsResponse = httpRequest( url: "${sonarReportUrl}/api/issues/search?componentKeys=${componentKey}&analysisId=${taskId}&branch=${branch}&statuses=${statuses}&severities=BLOCKER,CRITICAL,MAJOR,MINOR,INFO&s=SEVERITY&asc=false&ps=100", authentication: config.credentialsId )

NOSONAR rule is added as INFO in Sonar profile. It displays all open rules of all severities (INFO, MINOR, MAJOR, CRITICAL, BLOCKER), so NOSONAR is also part of big list of INFO.

Output Format -
{
“AXOl7zv5y-oe8ivwwcpI”: [{
“Rule”: [“pmd:ImmutableField”],
“Severity”: [“MINOR”],
“Component”: [“my-project:service/src/main/java/my-project/service/ResourceTransferServiceController.java”],
“line”: [90],
“Status”: [“OPEN”]
}],
“AXOl7zz0y-oe8ivwwcpj”: [{
“Rule”: [“pmd:NullAssignment”],
“Severity”: [“INFO”],
“Component”: [“my-project:service/src/main/java/my-project/service/ResourceTransferServiceController.java”],
“line”: [218],
“Status”: [“OPEN”]
}],
“AXOl7z06y-oe8ivwwcps”: [{
“Rule”: [“java:NoSonar”],
“Severity”: [“INFO”],
“Component”: [“my-project:service/src/main/java/my-project/service/ResourceTransferServiceController.java”],
“line”: [185],
“Status”: [“OPEN”]
}]
}

Thank you.
Prashanth

To clarify - The new output shouldn’t display - “AXOl7zz0y-oe8ivwwcpj” section.
Hope the question is clear.

Thanks for suggestions.

Hi,

If you want to restrict which records are returned, you should take a look at the rules parameter you’ll find included in the on-board web service documentation (link in page footer).

You’re not going to be able to alter the web service output except with the use of the facets parameter, which adds data.

 
Ann

yes, I tried rules parameters, like below earlier. The problem is it displays only this particular rule. Along with this, I also want other severities rules to be displayed. Is there a way to add a filter only on INFO severity.

def rules = ‘java:NoSonar’

url: "${sonarReportUrl}/api/issues/search?componentKeys=${componentKey}&analysisId=${taskId}&branch=${branch}&statuses=${statuses}&rules=${rules}"

Thanks,
Prashanth

Hi Prashanth,

Which of the parameters listed in the on-board web services documentation have you tried for this?

 
Ann

Hi Ann,
Thanks for assisting. I tried below parameters in API query. My INFO displays 10+ count, i need just 1 which is that NOSONAR rule. The problem with below query is - it is not showing other severities for which I don’t want to apply this filter.

Please recommend how to pass such a criteria in this query.

url: “{sonarReportUrl}/api/issues/search?componentKeys={componentKey}&analysisId={taskId}&branch={branch}&statuses={statuses}&rules={rules}&s=SEVERITY&asc=false”

Thank you.

Hi,

I’m not understanding what you want.

In an earlier post you said

Followed immediately by

And then in your most recent post

So:

  • do you want all severities or just INFO?
  • do you want all rules or just //NOSONAR?

 
Ann

1 Like

Thanks Ann for assisting.
By Severities, I mean - Critical, Major, Minor, Info.
The NoSonar rule has been added as Info in Sonar profile.

The current or actual output is - displays only NoSonar results since the rules parameter is passed with that particular rule. The current Info contains many rules output.

The expected output is - all open issues in Critical, Major, Minor. And from Info only NoSonar results.

The rules parameter in just above query applies filter on all severities mentioned. What I ask for is how to pass a filter on Info only, is this possible.

My latest query as below -

url: "${sonarReportUrl}/api/issues/search?componentKeys=${componentKey}&analysisId=${taskId}&branch=${branch}&statuses=${statuses}&rules=${rules}"

Where componentKey = name of the project, branch = git branch name, statuses = OPEN, rules = java:NoSonar

Trust this adds clarity. Please suggest.

Thank you.
Prashanth

Hi Prashanth,

Okay! Now we get to it!

For this you’re going to have to make two different calls: one for Critical, Major, and Minor issues. And another for //NOSONAR issues. The web service simply isn’t sophisticated enough to handle both of those sets in one call.

 
HTH,
Ann