Skip to content

Instantly share code, notes, and snippets.

@tonyklawrence
Last active December 29, 2015 01:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonyklawrence/7596920 to your computer and use it in GitHub Desktop.
Save tonyklawrence/7596920 to your computer and use it in GitHub Desktop.
Dashing Teamcity Widget
class Dashing.Teamcity extends Dashing.Widget
@accessor 'state', Dashing.AnimatedValue
onData: (data) ->
if data.status
$(@get('node')).attr 'class', (i,c) -> c.replace /\bstatus-\S+/g, ''
$(@get('node')).addClass "status-#{data.status}"
<h1 class="title" data-bind="title"></h1>
<h2 class="state" data-bind="state"></h2>
<p class="more-info" data-bind="moreinfo | raw"></p>
<p class="updated-at" data-bind="updatedAtMessage"></p>
require 'net/http'
require 'nokogiri'
teamcity = 'host:port'
build1 = 'bt1111'
build2 = 'bt2222'
build1 = 'bt3333'
SCHEDULER.every '5s' do
send_event('teamcity-build1', stateOf(teamcity, build1))
send_event('teamcity-build2', stateOf(teamcity, build2))
send_event('teamcity-build3', stateOf(teamcity, build3))
end
def stateOf(teamcity, buildId)
doc = Nokogiri::XML(Net::HTTP.get(URI(teamcity + '/guestAuth/app/rest/builds/buildType:(id:' + buildId + '),running:any')))
running = doc.xpath('//running-info/@percentageComplete')
status = doc.xpath('//build/@status').text() == 'SUCCESS' ? 'ok' : 'warning'
moreinfo = doc.xpath('//build/statusText').text().partition(';').first()
if running.empty?
if status == 'ok'
{ state: 'Ok', status: status, moreinfo: moreinfo }
else
{ state: 'Broke', status: status, moreinfo: moreinfo }
end
else
{ state: running.text() + '%', status: status, moreinfo: moreinfo }
end
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #00bb00;
$value-color: #fff;
$title-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.7);
// ----------------------------------------------------------------------------
// Widget-number styles
// ----------------------------------------------------------------------------
.widget-teamcity {
background-color: $background-color;
.title {
color: $title-color;
}
.value {
color: $value-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