Skip to content

Instantly share code, notes, and snippets.

@camillebaldock
Last active December 21, 2020 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camillebaldock/e83b1859d385b05f214e to your computer and use it in GitHub Desktop.
Save camillebaldock/e83b1859d385b05f214e to your computer and use it in GitHub Desktop.
Dashing Travis

Description

A Dashing widget for displaying the number of broken builds out of a configured list of public Travis builds of a GitHub user.

See a live demo here.

Usage

Setup the following environment variables:

  • GITHUB_USER: GitHub user or organisation that owns the repos
  • TRAVIS_REPOS: comma-separated list of repos with Travis builds to be monitored
require 'net/https'
require 'json'
SCHEDULER.every "10m", :first_in => 0 do
broken_builds = 0
http = Net::HTTP.new("api.travis-ci.org", 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
repos = ENV["TRAVIS_REPOS"].split(",")
repos.each do |repo|
response = http.request(Net::HTTP::Get.new("/repositories/#{ENV["GITHUB_USER"]}/#{repo}.json"))
usage = JSON.parse(response.body)
if usage["last_build_status"].to_i != 0
broken_builds += 1
end
end
if broken_builds > 0
send_event('travis', { current: broken_builds, "background-color" => 'red' })
else
send_event('travis', { current: nil, "background-color" => 'green' })
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment