2

I am trying to find a way to get a list of all Sonarqube rules from a particualar Profile complete with Descriptions and export it as an Excel, csv or xml. I am able to export a list to xml and convert to excel using the Permalinks option under Quality Profiles but this only provides details on the priorty,key, language and profile name associated with each rule and not anything further like the descriptrion of the rule.

I found the following question on the forum which outlines the steps to download the xml file with the details listed but not the description as required

Export list of coding rules from Sonarqube

I also discovered this question which also asks the same question on how to obtain Descriptions on each rule but was unable to get the details required

sonar quality profile rule export with descrption

I was able to run the command provided in the previous link to obtain some required results by referencing the repositorykey and key_name from the xml obtained under permalinks in the Quality Profiles section

curl -X GET -v -u admin:admin "http://[Sonarservername]:[port]/api/rules/show?key=[repositorykey]:[key_name]" --output file.xml

This command provides the result required (Description of the rule) but there is a requirement to change the repositorykey adn key_name for each rule. This is not feasible as I need the description for over 550 rules

What is requried to get description/rule description text?

Please help.

Community
  • 1
  • 1

2 Answers2

9

If my understanding is correct, the /api/rules/search web service should cover your need. See https://sonarcloud.io/api/rules/search?languages=java for the list of Java rules.

The API supports many parameters that are documented here: https://sonarcloud.io/web_api/api/rules/search (click the Parameters header above the horizontal line to open the descriptions).

For example, the rule_key parameter makes it possible to search for a specific rule. To find information about the S2065 rule (fields in non-serializable classes should not be "transient"), you can use: https://sonarcloud.io/api/rules/search?rule_key=squid:S2065

Freek de Bruijn
  • 3,552
  • 2
  • 22
  • 28
  • I try to Get all the java rules https://sonarqube.com/api/rules?language=java and get "{"errors":[{"msg":"Unknown controller: api"}]}". Is this still possible to get all the rules with one call? – mibrl12 Dec 12 '16 at 13:31
  • At the moment, the URL to get all Java rules seems to be: https://sonarcloud.io/api/rules/search?languages=java – Freek de Bruijn Jul 11 '17 at 21:05
3

I have had this problem with SONAR 4.5.6 and Sonar 7.3, but i will get the all the information throught the API.

In order to get the rules I need the Quality Profile key:

extra params:

1 - qprofile: key of the QP

2 - ps: number of rules to get per page.

3 - languages: languaje of the profile

4 - activation: true, needed to use the qprofile param

ALL of this API calls return all the information in JSON format.

Finally to conver this JSON to Excell I used a ONLINE converter like this

http://www.convertcsv.com/json-to-csv.htm

Copy and paste your JSON and select your coversion options, be carefull with the output options (Output Field Separator), choose the ';' and click on JSON to excel option.

AntuanSoft
  • 343
  • 2
  • 9