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!

Hello,

We are currently considering removing the feature that allows searching issues by directory. Upon reflection, we believe this feature may not be addressing a significant user need. It seems it was initially implemented more because it was feasible than in response to a specific user requirement.

Would you be able to articulate what you are trying to achieve? Why do you need the “number of issues, bugs and code smells of my project per root folder”?

Thanks
Alex

Hello,

We have a big git repository; at the root we have 1 folder per team and below all sub-folders and files for that team:

Repo_root

Folder1 // For team 1

Sub-folders and files

Folder2 // For team 2

Sub-folders and files

My need is to extract number of issues, bugs and code smells for each team, so for Folder1, Folder2…

As the API was not recursive as expected, I generate the list of all sub-folders under Folder1 and run the API for each sub-folders, then again for Folder2…

I run this every month and store the values in an XLS sheet and I can see the evolution month per month.

So, my need is to get the values as shown in the attached screenshot.

Cordialement / Best Regards / 敬具 / Freundliche Grüße

Dominique Chabaud / Senior Principal R&D Engineer

Ansys

ZE de La Farlède – 60 rue Parmentier / 83210 La Farlède - FRANCE

dominique.chabaud@ansys.com / +33 494 086 690

www.ansys.com

Hello,

If I’m correct your big git repository is what we call a Monorepo.

I think your needs can be covered by these 2 SonarQube features:

  • Support of Monorepo: each folder is scanned separately as a SQ Project
  • The concept of Application: each folder is scanned separately and then aggregated into an Application

It looks like this:

Then, if you need to do extra reporting to any level of management, you can use the API to extract the measures at the Project or Application level without having to go down to the directory level.

Alex

We already use such concept but to separate language C++ and C# scan and dispatch issues in 2 different SonarQ projects, 1 for each language.

Cordialement / Best Regards / 敬具 / Freundliche Grüße

Dominique Chabaud / Senior Principal R&D Engineer

Ansys

ZE de La Farlède – 60 rue Parmentier / 83210 La Farlède - FRANCE

dominique.chabaud@ansys.com / +33 494 086 690

www.ansys.com