Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从sonarqube API获取项目语言?_Sonarqube - Fatal编程技术网

如何从sonarqube API获取项目语言?

如何从sonarqube API获取项目语言?,sonarqube,Sonarqube,如何使用SonarqubeAPI获取项目的主编程语言?或者是项目所有编程语言的列表?每个SonarQube: ncloc_语言分布-按语言分布的非注释代码行 将其与SonarQube WebAPI/measures(SonarQube服务器中的文档)一起使用,您应该可以很好地使用。为了解决同样的问题,我提出了一个小的shell脚本,该脚本编写了所有SonarQube项目密钥的列表以及给定项目的语言分布: #!/bin/bash API="http://my.sonar-server.com:9

如何使用SonarqubeAPI获取项目的主编程语言?或者是项目所有编程语言的列表?

每个SonarQube:

ncloc_语言分布-按语言分布的非注释代码行


将其与SonarQube WebAPI/measures(SonarQube服务器中的文档)一起使用,您应该可以很好地使用。

为了解决同样的问题,我提出了一个小的shell脚本,该脚本编写了所有SonarQube项目密钥的列表以及给定项目的语言分布:

#!/bin/bash

API="http://my.sonar-server.com:9000/sonar/api"  ### adjust this!
API_LANG_DIST="$API/measures/component?metricKeys=ncloc_language_distribution"

# get a list of all project keys:
projKeys=$(curl -s "$API/projects/index" | jq -r '.[].k')

# for each project key, get the language distribution metric:
for key in ${projKeys}; do
    langDist=$(curl -s "${API_LANG_DIST}&componentKey=${key}" | jq '.component.measures[0].value')
    printf "%-80s%-80s\n" ${key} ${langDist}
done
输出如下所示:

com.mycompany:projectA      "grvy=75;java=4091"
com.mycompany:projectB      "css=1966;java=52770;js=11460;less=1862"
com.mycompany:projectC      "css=40185;java=11451;js=13757"
注意:此脚本使用了
jq
JSON解析实用程序。如果没有,可以通过
sudo-yum-install-jq
进行安装


(在SonarQube 5.6.6和6.7.0上测试)

谢谢,这正是我想要的!我的用法:api/measures/component?componentKey=[key]&metricKeys=ncloc\u language\u发行版