Request
curl -XGET http\://my_host\:9111/api/issues/search\?componentKeys\=my_poject\&facets\=severities\&p\=1\&ps\=1
Here response:
{
"total": 10057,
"p": 1,
"ps": 1,
"paging": {
"pageIndex": 1,
"pageSize": 1,
"total": 10057
},
"effortTotal": 51031,
"issues": [
{
"key": "AX0NVCNfENszTAxEgX5e",
"rule": "java:S122",
"severity": "MINOR",
"component": "my_project:SomeFile.java",
"project": "my_project",
"line": 241,
"hash": "1111111111",
"textRange": {
"startLine": 241,
"endLine": 241,
"startOffset": 0,
"endOffset": 46
},
"flows": [],
"status": "OPEN",
"message": "At most one statement is allowed per line, but 2 statements were found on this line.",
"effort": "1min",
"debt": "1min",
"author": "eugeniur",
"tags": [
"convention"
],
"creationDate": "2021-11-11T06:40:05+0200",
"updateDate": "2021-11-11T06:40:05+0200",
"type": "CODE_SMELL",
"scope": "MAIN"
}
],
"components": [
{
"key": "my_project",
"enabled": true,
"qualifier": "TRK",
"name": "Parent",
"longName": "Parent"
},
{
"key": "my_project:MyFile.java",
"enabled": true,
"qualifier": "FIL",
"name": "XStartDServerComponent.java",
"longName": "MyFile.java",
"path": "MyFile.java"
}
],
"facets": [
{
"property": "severities",
"values": [
{
"val": "CRITICAL",
"count": 5818
},
{
"val": "MAJOR",
"count": 1459
},
{
"val": "BLOCKER",
"count": 1286
},
{
"val": "MINOR",
"count": 1163
},
{
"val": "INFO",
"count": 331
}
]
}
]
}
Now I want to extract keys: "total", "issues", "facets.values"
.
So I try this in my bash script:
#!/bin/bash
readonly BASE_URL=http://my_host:9111/api
readonly PROJECT_KEY=my_project
read totalIssues facetsArr issuesArr < <(echo $(curl -XGET $BASE_URL/issues/search\?componentKeys\=$PROJECT_KEY\&facets\=severities\&p\=1\&ps\=1 |
jq -r '.total, .issues[], .facets[].values'))
echo "total : $totalIssues"
echo "facetsArr : $facetsArr"
echo "issuesArr : $issuesArr"
But result is:
total : 10057
facetsArr : {
issuesArr : "key": "AX0NVCNfENszTAxEgX5e", "rule": "java:S122", "severity": "MINOR", "component": "MyFile.java", "project": "myProject", "line": 241, "hash": "b68d3b4b390c81e2714d263b31acdd08", "textRange": { "startLine": 241, "endLine": 241, "startOffset": 0, "endOffset": 46 }, "flows": [], "status": "OPEN", "message": "At most one statement is allowed per line, but 2 statements were found on this line.", "effort": "1min", "debt": "1min", "author": "eugeniur", "tags": [ "convention" ], "creationDate": "2021-11-11T06:40:05+0200", "updateDate": "2021-11-11T06:40:05+0200", "type": "CODE_SMELL", "scope": "MAIN" } [ { "val": "CRITICAL", "count": 5818 }, { "val": "MAJOR", "count": 1459 }, { "val": "BLOCKER", "count": 1286 }, { "val": "MINOR", "count": 1163 }, { "val": "INFO", "count": 331 } ]
Why "facetsArr" get incorrect value?
The "facetsArr" must be:
facetsArr : [ { "val": "CRITICAL", "count": 5818 }, { "val": "MAJOR", "count": 1459 }, { "val": "BLOCKER", "count": 1286 }, { "val": "MINOR", "count": 1163 }, { "val": "INFO", "count": 331 } ]