Last active
December 4, 2018 07:39
-
-
Save kumbasar/8bfbe6d9cd1e3aba835157b4fc7f2a71 to your computer and use it in GitHub Desktop.
A groovy code to get code coverage and line size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonSlurper | |
def sonarqube_host = "http://SONARQUBE_URL:9000" | |
def projectname = "MY_PROJECT" | |
def SONARCUBE_URL = "${sonarqube_host}/api/measures/component?componentKey=${projectname}&metricKeys=coverage,ncloc" | |
def son_ncloc = 'N/A' | |
def son_coverage = 'N/A' | |
def son_qgates = 'N/A' | |
def authString = "amin:admin".getBytes().encodeBase64().toString() | |
URL u = new URL ("${SONARCUBE_URL}") | |
HttpURLConnection huc = (HttpURLConnection) u.openConnection () | |
huc.setRequestProperty("Authorization", "Basic ${authString}") | |
int code = huc.getResponseCode() | |
if (code == 200) { | |
BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream())); | |
StringBuilder sb = new StringBuilder(); | |
String line; | |
while ((line = br.readLine()) != null) { | |
sb.append(line+"\n"); | |
} | |
br.close(); | |
son_coverage = (new JsonSlurper().parseText(sb.toString())).component.measures.find{ it.metric=='coverage' }.value | |
son_ncloc = (new JsonSlurper().parseText(sb.toString())).component.measures.find{ it.metric=='ncloc' }.value | |
u = new URL ("${QG_URL}") | |
huc = (HttpURLConnection) u.openConnection () | |
huc.setRequestProperty("Authorization", "Basic ${authString}") | |
br = new BufferedReader(new InputStreamReader(huc.getInputStream())); | |
sb = new StringBuilder(); | |
while ((line = br.readLine()) != null) { | |
sb.append(line+"\n"); | |
} | |
br.close(); | |
son_qgates = (new JsonSlurper().parseText(sb.toString())).component.measures.find{ it.metric=='alert_status' }.value | |
if (son_qgates == "ERROR") { | |
son_qgates = "Failed" | |
} | |
println son_coverage + " " + son_ncloc | |
println son_qgates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment