I am trying to write a tiny script that
Get the versions of all microservices that are in a specific environment (resolved)
For each project / version, it receives sonar code coverage for this exact version. I'm having trouble getting Sonarbub coverage for the exact version of a specific project.
I am using sonarqube 6.0 (according to my endpoint my / api / server / version) (I hope we can upgrade to 6.4 in the near future, but this is not in my direct control and I do not want to wait for it)
My problem: I cannot bind data together, because when I call the endpoint / api / events, I get only the project date and scope, not the version. Here is an example of working code (credentials and base url not included)
I would be happy to solve this in any language: ruby, python, php, java, js, no matter what works.
require 'rest-client'
require 'json'
require 'ostruct'
require 'date'
require 'nokogiri'
projects_endpoint='/api/projects/'
time_machine_endpoint='/api/timemachine/'
events_endpoint='/api/events'
rc = RestClient::Resource.new(server_url, user, pass)
sonarqube_projects = JSON.parse(rc["#{projects_endpoint}index?format=json"].get, object_class: OpenStruct)
coverage_per_project = sonarqube_projects.map {|sq_project|
project_name = sq_project.k
url = "#{time_machine_endpoint}?format=json&resource=#{project_name}&metrics=coverage"
events = JSON.parse(rc[url].get, object_class: OpenStruct)
correct_event = events.first {|event|
event.version == my_deployed_app_version
}
return {project_name: project_name, coverage: correct_event.coverage}
}
puts coverage_per_project
source
share