Skip to content

Instantly share code, notes, and snippets.

@Pritesh-Patel
Last active June 27, 2019 00:24
Show Gist options
  • Save Pritesh-Patel/b94cf564c8fcba43b013 to your computer and use it in GitHub Desktop.
Save Pritesh-Patel/b94cf564c8fcba43b013 to your computer and use it in GitHub Desktop.
Scoverage Dashboard Plugin

Dashing Widget - Scoverage

  • Place the coffee,html and scss files into a folder named pull_requests in the widgets folder
  • Place the rb file into the jobs folder

Add nokogiri to the gemfile:

gem 'nokogiri'

and then just run

$ bundle install

Make sure to you have a config/config.yml file.

Example Config.yml

scoverages:
- :name: SERVICENAME_FRONTEND
  :scoverage: https://xxxx.co.uk/job/JOB_NAME/ws/target/scala-2.11/scoverage-report/overview.html
  :title: Front End
- :name: SERVICENAME_BACKEND
  :scoverage: https://xxxx.co.uk/job/JOB_NAME/ws/target/scala-2.11/scoverage-report/overview.html
  :title: Back End

name - is used for dashing purposes ie this could be SERVICENAME_FRONTEND or SERVICENAME_BACKEND scoverage - is the url to your scoverage page on jenkins, the url should look like this: https://xxxx.co.uk/job/JOB_NAME/ws/target/scala-2.11/scoverage-report/overview.html

title - is the name displayed on the widget

Example of what you would add to your dashboard file:

  <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
	  <div data-view="Scoverage" data-id="scoverage_SERVICENAME_FRONTEND"></div>
  </li>
  <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
	  <div data-view="Scoverage" data-id="scoverage_SERVICENAME_BACKEND"></div>
  </li>
class Dashing.Scoverage extends Dashing.Widget
@accessor 'value', Dashing.AnimatedValue
constructor: ->
super
@observe 'value', (value) ->
$(@node).find(".meter").val(value).trigger('change')
ready: ->
meter = $(@node).find(".meter")
meter.attr("data-bgcolor", meter.css("background-color"))
meter.attr("data-fgcolor", meter.css("color"))
meter.knob()
<h1 class="title" data-bind="title"></h1>
<input class="meter" data-angleOffset=-125 data-angleArc=250 data-width=100 data-height=100 data-readOnly=true data-bind-value="value | shortenedNumber | append '%'" data-bind-data-min="min" data-bind-data-max="max">
<p class="more-info" data-bind="moreinfo"></p>
<p class="updated-at" data-bind="updatedAtMessage"></p>
require 'nokogiri'
SCHEDULER.every '5m', :first_in => 0 do |job|
config = YAML.load_file("config/config.yml")
@login = config["jenkins-user"]
@pass = config["jenkins-password"]
scoverages = config["scoverages"]
scoverages.each do |scoverage|
scoverage_url = scoverage[:scoverage]
uri = URI.parse(scoverage_url)
http = Net::HTTP.new(uri.host,uri.port)
if 'https' == uri.scheme
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
request = Net::HTTP::Get.new(uri.request_uri)
if @login
request.basic_auth(@login, @pass)
end
response = http.request(request)
noko = Nokogiri::HTML(response.body)
perc = noko.css("/html/body/div[2]/div[1]/table/tr[5]/td[2]")
actPerc = perc.text[/[0-9]+(.)[0-9]+/].to_f.round(1)
send_event("scoverage_" + scoverage[:name], { title: scoverage[:title], min: 0, value: actPerc, max: 100})
end
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #99B923;
$title-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.5);
$meter-background: darken($background-color, 7%);
// ----------------------------------------------------------------------------
// Widget-sprint-progress styles
// ----------------------------------------------------------------------------
.widget-scoverage {
background-color: $background-color;
input.meter {
background-color: $meter-background;
color: #fff;
}
.title {
color: $title-color;
}
.more-info {
color: $moreinfo-color;
}
.updated-at {
color: rgba(0, 0, 0, 0.3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment