-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.rb
80 lines (66 loc) · 1.66 KB
/
setup.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require 'hue'
require 'json'
hue = nil
begin
puts "Locating the Hue bridge"
hue = Hue::Client.new("travis-ci-on-the-piiii")
puts "Hue bridge found at #{client.bridge.ip}\n\n"
rescue Hue::NoBridgeFound => e
puts "Sorry but no Hue bridge could be found"
exit
rescue => e
# nothing for now
end
begin
hue = Hue::Client.new("travis-ci-on-the-pi")
puts "Looks like the bridge knows who you are!\n\n"
rescue Hue::LinkButtonNotPressed => e
puts "This is the first time setting this up, so you need to please the link button"
sleep 2
retry
end
lights = hue.lights
case lights.size
when 0
puts "Sorry but it doesn't look like any lights are connected to your Hue"
exit
when 1
puts "Found a light!\n\n"
else
puts "Ohhhh, found #{lights.size} lights!\n\n"
end
monitored_lights = []
lights.each do |light|
light.set_state alert: 'lselect'
sleep 2
light.set_state alert: 'none'
print "Would you like to setup '#{light.name}' to link to a repo on travis-ci.org? (y/n) : "
STDOUT.flush
answer = gets.chomp.downcase
case answer
when 'y'
print "What is the repo you would like to link this light to? eg. travis-ci/travis-api : "
STDOUT.flush
repo = gets.chomp.downcase
puts "\n"
light.name = "travis-ci: #{repo.split('/').last}"[0..30]
monitored_lights << { light_id: light.id, repo: repo }
else
next
end
end
settings = {
lights: monitored_lights
}
File.open("settings.json","w") do |f|
f.write(settings.to_json)
end
message = "setup to sync with Travis CI repos"
case monitored_lights.size
when 0
puts "No lights #{message}"
when 1
puts "1 light #{message}"
else
puts "#{monitored_lights.size} lights #{message}"
end