Search issues in a specific folder of a project

Hello,
I am using SonarQ 10.1, Enterprise edition with a commercial licence.

I have a SonarQ project (key=MyProjectKey) with some folders under the root (FolderA, FolderB…)
Then I would like to get the number of issues of this project but only for files in FolderA and all its sub-folders.

With .../api/issues/search?branch=main&resolved=false&ps=1&componentKeys=MyProjectKey and I got the same total number of issues as reported on the SonarQ dashboard.

But when I try:

  • .../api/issues/search?branch=main&resolved=false&ps=1&componentKeys=MyProjectKey:FolderA I got 0 issues (I have no files in FolderA, only in sub-folders).
  • .../api/issues/search?branch=main&resolved=false&ps=1&componentKeys=MyProjectKey:FolderA/% I got all issues ofall SonarQ projects.
  • .../api/issues/search?branch=main&resolved=false&ps=1&componentKeys=MyProjectKey,FolderA I got all issues of my project (including those in FolderB).
  • .../api/issues/search?branch=main&resolved=false&ps=1&componentKeys=MyProjectKey,FolderA/% I got all issues of all SonarQ projects.

Any idea which request to use to only have issues of my project only in FolderA?
Thanks a lot

Hey there.

It’s not possible to filter down to a specific folder. :frowning: Hopefully SONAR-12271 eventually helps you out to find issues per directory, when it’s implemented :slight_smile:

It keeps getting pushed back, but I’ll link this post to the ticket in an attempt (however futile) to gain traction.

1 Like

Thanks Colin for your response. I want to get the number of issues, bugs and code smells of my project per root folder (including their sub-subfolders respectively), about ten root folders.

  • My first idea was to use many requests with paging and check each component path but unfortunately my project has much more than 10K issues.
  • I also have more than 10K code smell, so I cannot use paging and filter per type of issues.
  • This is why I tried to request per root folder but as you confirm, it only returns issues in the requested folder but not in its sub-folders.
  • Due to the 10K limitation I also cannot request all folders using facets=directories, I can only have folders of the first 10K issues.
  • Same with facets=cwe. Due to the 10K limitation I cannot reteive all cwe in my project then use a request per cwe.

So this is the snake that dies its tail…

A last idea I will try: using a loop on rules, expecting that there is no more than 10K for each… It’s horrible!