Created
March 31, 2014 02:39
-
-
Save jacobh/9884192 to your computer and use it in GitHub Desktop.
LIFX build status light
This file contains 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
require 'LIFX' | |
require 'net/http' | |
require 'json' | |
# LIFX setup | |
green = LIFX::Color.green saturation: 1 | |
red = LIFX::Color.red saturation: 1 | |
white = LIFX::Color.white | |
off_color = LIFX::Color.white brightness: 0 | |
client = LIFX::Client.lan | |
client.discover! | |
lights = client.lights | |
# API setup | |
build_status_url = URI "https://circleci.com/api/v1/project/gizmag/gizmag?circle-token=NOPE&limit=5" | |
last_build_id = nil | |
while true | |
begin | |
resp = Net::HTTP.get build_status_url | |
data = JSON.restore resp | |
rescue | |
next | |
end | |
# find latest completed build | |
build = data.find { |x| x['status'] == 'success' or x['status'] == 'failed' } | |
if last_build_id != build['build_num'] | |
if build['status'] == "success" | |
lights.set_color green, duration: 1 | |
sleep 10 | |
lights.set_color off_color, duration: 5 | |
else | |
lights.set_color red, duration: 1 | |
sleep 10 | |
lights.set_color off_color, duration: 5 | |
end | |
last_build_id = build['build_num'] | |
end | |
sleep 10 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment