Alexei
Alexei

Reputation: 15726

Can't get severity info via API

Java 11

SonarQube 8.9.2 LTS

For my java project the SonarQube show the next issues info:

Severity
Blocker 1.3k
Minor 1.1k
Critical 5.8k
Info 233
Major 1.3k

So I need to get this information via SonarQube WEB API.

I found only this api method:

 GET http://some_url_sonar_qube/api/issues/search

And its return all issues on page = 1

And its return all issues on page = 1 with detail info

{
  "total": 10049,
  "p": 1,
  "ps": 100,
  "paging": {
    "pageIndex": 1,
    "pageSize": 100,
    "total": 10049
  },
  "effortTotal": 50995,
   "issues": [
{
  "key": "dddd",
  "rule": "css:S4670",
  "severity": "CRITICAL",

...

This:

 GET http://some_url_sonar_qube/api/issues/search?p=2

And its return all issues on page = 2

and so on.

Response example:

As you can see has 10049 issues. It's 100 pages.

But I need summary info. Smt like this in json format:

{
  "Severity": {
    "Blocker": 1300,
    "Minor": 1100,
    "Critical": 5800,
    "Info": 233,
    "Major": 1300
  }
}

I'm not found api method for this

Upvotes: 0

Views: 602

Answers (2)

Bishwajit Vikram
Bishwajit Vikram

Reputation: 113

I too took above suggestion and created my own api.

{SONAR_HOST_URL}/api/issues/search?componentKeys=YOUR_PROJECT_KEY&facets=severities&pullRequest=66&resolved=false

{
  "total": 0,
  "p": 1,
  "ps": 100,
  "paging": { "pageIndex": 1, "pageSize": 100, "total": 0 },
  "effortTotal": 0,
  "issues": [],
  "components": [],
  "facets": [
    {
      "property": "severities",
      "values": [
        { "val": "INFO", "count": 0 },
        { "val": "MINOR", "count": 0 },
        { "val": "MAJOR", "count": 0 },
        { "val": "CRITICAL", "count": 0 },
        { "val": "BLOCKER", "count": 0 }
      ]
    }
  ]
}

Upvotes: 0

Alexei
Alexei

Reputation: 15726

I found solution (thanks for @gawkface)

Use this method:

GET http://some_url_sonar_qube/api/issues/search?componentKeys=my_project_key&facets=severities

And here result (on section facets)

{
  "total": 10049,
  "p": 1,
  "ps": 100,
  "paging": {
    "pageIndex": 1,
    "pageSize": 100,
    "total": 10049
  },
  "effortTotal": 50995,
  "issues": [...],
  "components": [...],
  "facets": [
    {
      "property": "severities",
      "values": [
        {
          "val": "CRITICAL",
          "count": 5817
        },
        {
          "val": "MAJOR",
          "count": 1454
        },
        {
          "val": "BLOCKER",
          "count": 1286
        },
        {
          "val": "MINOR",
          "count": 1161
        },
        {
          "val": "INFO",
          "count": 331
        }
      ]
    }
  ]
}

Upvotes: 2

Related Questions