sonar-bugs数据库是有统计的,但是查询的话,也不如api来的方便。
sonar-api入口,我就不再说了,里面有很多接口,我是翻了一遍,其中post多用于与其它第三方应用做webhooks的时候,可能会比较方便做自动化,get多用于查询数据
报告结果

请憋住指责,我们这个这么多问题,是因为质量真的很差,举个例子:一个周期3周的项目,手工进行功能测试至少是150个BUG起步。有多差,靠想象
sonar-api
Authorization接口调用要进行身份验证,使用postman生成Authorization的值即可.
public class SonarWebApi {
/*
*
* sonar自带的邮件报告api,无法使用html
* @throws IOException*/
/*public static void sendmail() throws IOException {
SendRuquest sendRuquest=new SendRuquest();
WebApi sendMailInfo =new WebApi();
String message= sendMailInfo.getemailContent();
String subject="项目质量汇总报告";
String url="http://sonar.com.cn/api/emails/send";
// ?message=hello&subject=hi&to=liujuan@pconline.com.cn
String to="liujuan@pconline.com.cn";
Map<String,String> headerMap=new HashMap<String,String>();
headerMap.put("Authorization","Basic YWRtaW46YWRtaW4=");
String params="message="+message+"&subject="+subject+"&to="+to;
String flag=sendRuquest.sendPost(url,params,headerMap);
if(flag!=null){
System.out.println("发送成功");
}else {
System.out.println("发送失败");
}
}*/
/**
* 获取单个项目的各个质量结果 ,得到JSONArray
* @return
* @throws IOException
*/
public JSONObject getmeasures(String projectKee){
SendRuquest sendRuquest=new SendRuquest();
String url="http://sonar.com.cn/api/measures/component";
String params="component="+projectKee+
"&metricKeys=new_bugs,bugs,new_coverage,coverage,new_vulnerabilities," +
"vulnerabilities,new_duplicated_lines_density,duplicated_lines_density";
Map<String,String> headerMap

本文档展示了如何利用SonarAPI进行项目质量分析,包括获取项目指标、发送邮件报告以及对数据进行排序。通过调用API获取Bug、覆盖率、重复代码等关键指标,并实现了根据bug数量对项目进行排序的功能,以生成质量报告。此外,还提到手动功能测试中发现大量问题的情况,强调了自动化查询的重要性。
最低0.47元/天 解锁文章
3203





