sonar api 获取质量数据

查看sonar api接口:http://{ip}:9000/web_api

可以通过接口:

http://my.sonar.com/drilldown/measures/My-Project-Name?metric=line_coverage 

官方说这个接口也是可以获取的,但是尝试返回404

sonar api 获取质量数据_第1张图片

通过接口:(接口resource=componentKey)

http://my.sonar.com/api/resources?resource=com.suning.plppss:plppss-pom:1.1.1&metrics=ncloc,conditions_to_cover,uncovered_conditions,lines_to_cover,uncovered_lines,coverage,new_coverage,line_coverage,new_line_coverage,branch_coverage,it_conditions_to_cover,it_uncovered_conditions,it_lines_to_cover,it_uncovered_lines,it_coverage,it_line_coverage,it_branch_coverage,overall_conditions_to_cover,overall_uncovered_conditions,overall_lines_to_cover,overall_uncovered_lines,overall_coverage,overall_line_coverage,overall_branch_coverage

返回:



8393640
com.suning.plppss:plppss-pom:1.1.1
plppss-pom 1.1.1
plppss-pom 1.1.1
1.1.1
PRJ
TRK
4.5.1
2018-05-02T15:16:41+0800
2018-04-09T09:49:28+0800

coverage
15.5
15.5%


uncovered_lines
31866.0
31,866


conditions_to_cover
11293.0
11,293


uncovered_conditions
10064.0
10,064


lines_to_cover
38301.0
38,301


ncloc
105198.0
105,198


line_coverage
16.8
16.8%


branch_coverage
10.9
10.9%


但是这个接口没有返回 new_coverage信息

---------------------------------------------------------------------------------------------------------------------------

通过接口

http://my.sonar.com/api/measures/component?componentKey=com.suning.o2oms:o2oms-pom:1.0.0&metricKeys=new_uncovered_conditions,new_uncovered_lines,new_duplicated_blocks,new_lines_to_cover,bugs,files,new_bugs,new_vulnerabilities,new_code_smells,new_duplicated_lines,new_violations,uncovered_conditions,new_branch_coverage,new_coverage,new_lines,new_sqale_debt_ratio,new_maintainability_rating&additionalFields=metrics,periods

返回:

{"component":{"id":"AWMCo0vcw6x9hRrwyONR","key":"com.suning.o2oms:o2oms-pom:1.0.0","name":"o2oms-pom 1.0.0","qualifier":"TRK","measures":[{"metric":"new_uncovered_conditions","periods":[{"index":1,"value":"198"},{"index":2,"value":"0"},{"index":3,"value":"198"}]},{"metric":"new_lines","periods":[{"index":1,"value":"22097"},{"index":2,"value":"39"},{"index":3,"value":"22097"}]},{"metric":"new_uncovered_lines","periods":[{"index":1,"value":"577"},{"index":2,"value":"3"},{"index":3,"value":"577"}]},{"metric":"new_maintainability_rating","periods":[{"index":1,"value":"1.0"},{"index":2,"value":"1.0"},{"index":3,"value":"1.0"}]},{"metric":"new_lines_to_cover","periods":[{"index":1,"value":"1704"},{"index":2,"value":"19"},{"index":3,"value":"1704"}]},{"metric":"files","value":"456","periods":[{"index":1,"value":"1"},{"index":2,"value":"0"},{"index":3,"value":"1"}]},{"metric":"new_violations","periods":[{"index":1,"value":"90"},{"index":2,"value":"3"},{"index":3,"value":"90"}]},{"metric":"bugs","value":"125","periods":[{"index":1,"value":"-49"},{"index":2,"value":"-3"},{"index":3,"value":"-49"}]},{"metric":"new_vulnerabilities","periods":[{"index":1,"value":"0"},{"index":2,"value":"0"},{"index":3,"value":"0"}]},{"metric":"new_bugs","periods":[{"index":1,"value":"14"},{"index":2,"value":"0"},{"index":3,"value":"14"}]},{"metric":"new_duplicated_blocks","periods":[{"index":1,"value":"49"},{"index":2,"value":"0"},{"index":3,"value":"49"}]},{"metric":"new_coverage","periods":[{"index":1,"value":"62.70452358036574"},{"index":2,"value":"85.71428571428571"},{"index":3,"value":"62.70452358036574"}]},{"metric":"new_duplicated_lines","periods":[{"index":1,"value":"150"},{"index":2,"value":"0"},{"index":3,"value":"150"}]},{"metric":"new_code_smells","periods":[{"index":1,"value":"76"},{"index":2,"value":"3"},{"index":3,"value":"76"}]},{"metric":"new_sqale_debt_ratio","periods":[{"index":1,"value":"0.6193306224585549"},{"index":2,"value":"1.3888888888888888"},{"index":3,"value":"0.6193306224585549"}]},{"metric":"new_branch_coverage","periods":[{"index":1,"value":"47.05882352941177"},{"index":2,"value":"100.0"},{"index":3,"value":"47.05882352941177"}]},{"metric":"uncovered_conditions","value":"1762","periods":[{"index":1,"value":"1474"},{"index":2,"value":"-2"},{"index":3,"value":"1474"}]}]},"metrics":[{"key":"new_lines","name":"Lines on New Code","description":"Non commenting lines on new code","domain":"Size","type":"INT","higherValuesAreBetter":false,"qualitative":false,"hidden":false,"custom":false},{"key":"files","name":"Files","description":"Number of files","domain":"Size","type":"INT","higherValuesAreBetter":false,"qualitative":false,"hidden":false,"custom":false},{"key":"new_coverage","name":"Coverage on New Code","description":"Coverage of new/changed code","domain":"Coverage","type":"PERCENT","higherValuesAreBetter":true,"qualitative":true,"hidden":false,"custom":false,"decimalScale":1,"bestValue":"100.0","worstValue":"0.0"},{"key":"new_lines_to_cover","name":"Lines to Cover on New Code","description":"Lines to cover on new code","domain":"Coverage","type":"INT","higherValuesAreBetter":false,"qualitative":false,"hidden":false,"custom":false},{"key":"new_uncovered_lines","name":"Uncovered Lines on New Code","description":"Uncovered lines on new code","domain":"Coverage","type":"INT","higherValuesAreBetter":false,"qualitative":false,"hidden":false,"custom":false,"bestValue":"0"},{"key":"uncovered_conditions","name":"Uncovered Conditions","description":"Uncovered conditions","domain":"Coverage","type":"INT","higherValuesAreBetter":false,"qualitative":false,"hidden":false,"custom":false,"bestValue":"0"},{"key":"new_uncovered_conditions","name":"Uncovered Conditions on New Code","description":"Uncovered conditions on new code","domain":"Coverage","type":"INT","higherValuesAreBetter":false,"qualitative":false,"hidden":false,"custom":false,"bestValue":"0"},{"key":"new_branch_coverage","name":"Condition Coverage on New Code","description":"Condition coverage of new/changed code","domain":"Coverage","type":"PERCENT","higherValuesAreBetter":true,"qualitative":true,"hidden":false,"custom":false,"decimalScale":1,"bestValue":"100.0","worstValue":"0.0"},{"key":"new_duplicated_lines","name":"Duplicated Lines on New Code","description":"Duplicated Lines on New Code","domain":"Duplications","type":"INT","higherValuesAreBetter":false,"qualitative":true,"hidden":false,"custom":false,"bestValue":"0"},{"key":"new_duplicated_blocks","name":"Duplicated Blocks on New Code","description":"Duplicated blocks on new code","domain":"Duplications","type":"INT","higherValuesAreBetter":false,"qualitative":true,"hidden":false,"custom":false,"bestValue":"0"},{"key":"new_violations","name":"New Issues","description":"New issues","domain":"Issues","type":"INT","higherValuesAreBetter":false,"qualitative":true,"hidden":false,"custom":false,"bestValue":"0"},{"key":"new_code_smells","name":"New Code Smells","description":"New Code Smells","domain":"Maintainability","type":"INT","higherValuesAreBetter":false,"qualitative":true,"hidden":false,"custom":false,"bestValue":"0"},{"key":"bugs","name":"Bugs","description":"Bugs","domain":"Reliability","type":"INT","higherValuesAreBetter":false,"qualitative":false,"hidden":false,"custom":false,"bestValue":"0"},{"key":"new_bugs","name":"New Bugs","description":"New Bugs","domain":"Reliability","type":"INT","higherValuesAreBetter":false,"qualitative":true,"hidden":false,"custom":false,"bestValue":"0"},{"key":"new_vulnerabilities","name":"New Vulnerabilities","description":"New Vulnerabilities","domain":"Security","type":"INT","higherValuesAreBetter":false,"qualitative":true,"hidden":false,"custom":false,"bestValue":"0"},{"key":"new_maintainability_rating","name":"Maintainability Rating on New Code","description":"Maintainability rating on new code","domain":"Maintainability","type":"RATING","higherValuesAreBetter":false,"qualitative":true,"hidden":false,"custom":false,"bestValue":"1.0","worstValue":"5.0"},{"key":"new_sqale_debt_ratio","name":"Technical Debt Ratio on New Code","description":"Technical Debt Ratio of new/changed code.","domain":"Maintainability","type":"PERCENT","higherValuesAreBetter":false,"qualitative":true,"hidden":false,"custom":false,"decimalScale":1,"bestValue":"0.0","worstValue":"100.0"}],"periods":[{"index":1,"mode":"previous_version","date":"2018-04-26T23:48:42+0800"},{"index":2,"mode":"previous_analysis","date":"2018-05-02T15:35:53+0800","parameter":"2018-05-02"},{"index":3,"mode":"days","date":"2018-04-26T23:48:42+0800","parameter":"30"}]}

转化为json:

{
    "component": {
        "id": "AWMCo0vcw6x9hRrwyONR", 
        "key": "com.suning.o2oms:o2oms-pom:1.0.0", 
        "name": "o2oms-pom 1.0.0", 
        "qualifier": "TRK", 
        "measures": [
            {
                "metric": "new_uncovered_conditions", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "198"
                    }, 
                    {
                        "index": 2, 
                        "value": "0"
                    }, 
                    {
                        "index": 3, 
                        "value": "198"
                    }
                ]
            }, 
            {
                "metric": "new_lines", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "22097"
                    }, 
                    {
                        "index": 2, 
                        "value": "39"
                    }, 
                    {
                        "index": 3, 
                        "value": "22097"
                    }
                ]
            }, 
            {
                "metric": "new_uncovered_lines", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "577"
                    }, 
                    {
                        "index": 2, 
                        "value": "3"
                    }, 
                    {
                        "index": 3, 
                        "value": "577"
                    }
                ]
            }, 
            {
                "metric": "new_maintainability_rating", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "1.0"
                    }, 
                    {
                        "index": 2, 
                        "value": "1.0"
                    }, 
                    {
                        "index": 3, 
                        "value": "1.0"
                    }
                ]
            }, 
            {
                "metric": "new_lines_to_cover", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "1704"
                    }, 
                    {
                        "index": 2, 
                        "value": "19"
                    }, 
                    {
                        "index": 3, 
                        "value": "1704"
                    }
                ]
            }, 
            {
                "metric": "files", 
                "value": "456", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "1"
                    }, 
                    {
                        "index": 2, 
                        "value": "0"
                    }, 
                    {
                        "index": 3, 
                        "value": "1"
                    }
                ]
            }, 
            {
                "metric": "new_violations", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "90"
                    }, 
                    {
                        "index": 2, 
                        "value": "3"
                    }, 
                    {
                        "index": 3, 
                        "value": "90"
                    }
                ]
            }, 
            {
                "metric": "bugs", 
                "value": "125", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "-49"
                    }, 
                    {
                        "index": 2, 
                        "value": "-3"
                    }, 
                    {
                        "index": 3, 
                        "value": "-49"
                    }
                ]
            }, 
            {
                "metric": "new_vulnerabilities", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "0"
                    }, 
                    {
                        "index": 2, 
                        "value": "0"
                    }, 
                    {
                        "index": 3, 
                        "value": "0"
                    }
                ]
            }, 
            {
                "metric": "new_bugs", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "14"
                    }, 
                    {
                        "index": 2, 
                        "value": "0"
                    }, 
                    {
                        "index": 3, 
                        "value": "14"
                    }
                ]
            }, 
            {
                "metric": "new_duplicated_blocks", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "49"
                    }, 
                    {
                        "index": 2, 
                        "value": "0"
                    }, 
                    {
                        "index": 3, 
                        "value": "49"
                    }
                ]
            }, 
            {
                "metric": "new_coverage", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "62.70452358036574"
                    }, 
                    {
                        "index": 2, 
                        "value": "85.71428571428571"
                    }, 
                    {
                        "index": 3, 
                        "value": "62.70452358036574"
                    }
                ]
            }, 
            {
                "metric": "new_duplicated_lines", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "150"
                    }, 
                    {
                        "index": 2, 
                        "value": "0"
                    }, 
                    {
                        "index": 3, 
                        "value": "150"
                    }
                ]
            }, 
            {
                "metric": "new_code_smells", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "76"
                    }, 
                    {
                        "index": 2, 
                        "value": "3"
                    }, 
                    {
                        "index": 3, 
                        "value": "76"
                    }
                ]
            }, 
            {
                "metric": "new_sqale_debt_ratio", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "0.6193306224585549"
                    }, 
                    {
                        "index": 2, 
                        "value": "1.3888888888888888"
                    }, 
                    {
                        "index": 3, 
                        "value": "0.6193306224585549"
                    }
                ]
            }, 
            {
                "metric": "new_branch_coverage", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "47.05882352941177"
                    }, 
                    {
                        "index": 2, 
                        "value": "100.0"
                    }, 
                    {
                        "index": 3, 
                        "value": "47.05882352941177"
                    }
                ]
            }, 
            {
                "metric": "uncovered_conditions", 
                "value": "1762", 
                "periods": [
                    {
                        "index": 1, 
                        "value": "1474"
                    }, 
                    {
                        "index": 2, 
                        "value": "-2"
                    }, 
                    {
                        "index": 3, 
                        "value": "1474"
                    }
                ]
            }
        ]
    }, 
    "metrics": [
        {
            "key": "new_lines", 
            "name": "Lines on New Code", 
            "description": "Non commenting lines on new code", 
            "domain": "Size", 
            "type": "INT", 
            "higherValuesAreBetter": false, 
            "qualitative": false, 
            "hidden": false, 
            "custom": false
        }, 
        {
            "key": "files", 
            "name": "Files", 
            "description": "Number of files", 
            "domain": "Size", 
            "type": "INT", 
            "higherValuesAreBetter": false, 
            "qualitative": false, 
            "hidden": false, 
            "custom": false
        }, 
        {
            "key": "new_coverage", 
            "name": "Coverage on New Code", 
            "description": "Coverage of new/changed code", 
            "domain": "Coverage", 
            "type": "PERCENT", 
            "higherValuesAreBetter": true, 
            "qualitative": true, 
            "hidden": false, 
            "custom": false, 
            "decimalScale": 1, 
            "bestValue": "100.0", 
            "worstValue": "0.0"
        }, 
        {
            "key": "new_lines_to_cover", 
            "name": "Lines to Cover on New Code", 
            "description": "Lines to cover on new code", 
            "domain": "Coverage", 
            "type": "INT", 
            "higherValuesAreBetter": false, 
            "qualitative": false, 
            "hidden": false, 
            "custom": false
        }, 
        {
            "key": "new_uncovered_lines", 
            "name": "Uncovered Lines on New Code", 
            "description": "Uncovered lines on new code", 
            "domain": "Coverage", 
            "type": "INT", 
            "higherValuesAreBetter": false, 
            "qualitative": false, 
            "hidden": false, 
            "custom": false, 
            "bestValue": "0"
        }, 
        {
            "key": "uncovered_conditions", 
            "name": "Uncovered Conditions", 
            "description": "Uncovered conditions", 
            "domain": "Coverage", 
            "type": "INT", 
            "higherValuesAreBetter": false, 
            "qualitative": false, 
            "hidden": false, 
            "custom": false, 
            "bestValue": "0"
        }, 
        {
            "key": "new_uncovered_conditions", 
            "name": "Uncovered Conditions on New Code", 
            "description": "Uncovered conditions on new code", 
            "domain": "Coverage", 
            "type": "INT", 
            "higherValuesAreBetter": false, 
            "qualitative": false, 
            "hidden": false, 
            "custom": false, 
            "bestValue": "0"
        }, 
        {
            "key": "new_branch_coverage", 
            "name": "Condition Coverage on New Code", 
            "description": "Condition coverage of new/changed code", 
            "domain": "Coverage", 
            "type": "PERCENT", 
            "higherValuesAreBetter": true, 
            "qualitative": true, 
            "hidden": false, 
            "custom": false, 
            "decimalScale": 1, 
            "bestValue": "100.0", 
            "worstValue": "0.0"
        }, 
        {
            "key": "new_duplicated_lines", 
            "name": "Duplicated Lines on New Code", 
            "description": "Duplicated Lines on New Code", 
            "domain": "Duplications", 
            "type": "INT", 
            "higherValuesAreBetter": false, 
            "qualitative": true, 
            "hidden": false, 
            "custom": false, 
            "bestValue": "0"
        }, 
        {
            "key": "new_duplicated_blocks", 
            "name": "Duplicated Blocks on New Code", 
            "description": "Duplicated blocks on new code", 
            "domain": "Duplications", 
            "type": "INT", 
            "higherValuesAreBetter": false, 
            "qualitative": true, 
            "hidden": false, 
            "custom": false, 
            "bestValue": "0"
        }, 
        {
            "key": "new_violations", 
            "name": "New Issues", 
            "description": "New issues", 
            "domain": "Issues", 
            "type": "INT", 
            "higherValuesAreBetter": false, 
            "qualitative": true, 
            "hidden": false, 
            "custom": false, 
            "bestValue": "0"
        }, 
        {
            "key": "new_code_smells", 
            "name": "New Code Smells", 
            "description": "New Code Smells", 
            "domain": "Maintainability", 
            "type": "INT", 
            "higherValuesAreBetter": false, 
            "qualitative": true, 
            "hidden": false, 
            "custom": false, 
            "bestValue": "0"
        }, 
        {
            "key": "bugs", 
            "name": "Bugs", 
            "description": "Bugs", 
            "domain": "Reliability", 
            "type": "INT", 
            "higherValuesAreBetter": false, 
            "qualitative": false, 
            "hidden": false, 
            "custom": false, 
            "bestValue": "0"
        }, 
        {
            "key": "new_bugs", 
            "name": "New Bugs", 
            "description": "New Bugs", 
            "domain": "Reliability", 
            "type": "INT", 
            "higherValuesAreBetter": false, 
            "qualitative": true, 
            "hidden": false, 
            "custom": false, 
            "bestValue": "0"
        }, 
        {
            "key": "new_vulnerabilities", 
            "name": "New Vulnerabilities", 
            "description": "New Vulnerabilities", 
            "domain": "Security", 
            "type": "INT", 
            "higherValuesAreBetter": false, 
            "qualitative": true, 
            "hidden": false, 
            "custom": false, 
            "bestValue": "0"
        }, 
        {
            "key": "new_maintainability_rating", 
            "name": "Maintainability Rating on New Code", 
            "description": "Maintainability rating on new code", 
            "domain": "Maintainability", 
            "type": "RATING", 
            "higherValuesAreBetter": false, 
            "qualitative": true, 
            "hidden": false, 
            "custom": false, 
            "bestValue": "1.0", 
            "worstValue": "5.0"
        }, 
        {
            "key": "new_sqale_debt_ratio", 
            "name": "Technical Debt Ratio on New Code", 
            "description": "Technical Debt Ratio of new/changed code.", 
            "domain": "Maintainability", 
            "type": "PERCENT", 
            "higherValuesAreBetter": false, 
            "qualitative": true, 
            "hidden": false, 
            "custom": false, 
            "decimalScale": 1, 
            "bestValue": "0.0", 
            "worstValue": "100.0"
        }
    ], 
    "periods": [
        {
            "index": 1, 
            "mode": "previous_version", 
            "date": "2018-04-26T23:48:42+0800"
        }, 
        {
            "index": 2, 
            "mode": "previous_analysis", 
            "date": "2018-05-02T15:35:53+0800", 
            "parameter": "2018-05-02"
        }, 
        {
            "index": 3, 
            "mode": "days", 
            "date": "2018-04-26T23:48:42+0800", 
            "parameter": "30"
        }
    ]
}

这个接口返回new_coverage信息,这个接口最后面添加additionalFields=metrics,periods,会返回metric字段信息,和对应的index构建的时间。

 

 

你可能感兴趣的:(sonar)