class Circler::WatchCommand
Public Class Methods
run(options)
click to toggle source
# File lib/circler/command/watch_command.rb, line 6 def run(options) setup_token setup_client build = get_build(options) if build&.running? start_watch(build) wait_until_finish finalize(build, build.channel_name) else say 'The build is not running' end end
Private Class Methods
bind_event_handling(channel)
click to toggle source
# File lib/circler/command/watch_command.rb, line 43 def bind_event_handling(channel) @client.bind_event_json(channel, 'newAction') do |json| print_bordered json['log']['name'].green end @client.bind_event_json(channel, 'appendAction') do |json| say json['out']['message'] end @client.bind_event_json(channel, 'updateAction') do |json| @running = json['log']['name'] != 'Disable SSH' end end
finalize(build, channel)
click to toggle source
# File lib/circler/command/watch_command.rb, line 61 def finalize(build, channel) @client.unsubscribe(channel) text = "Finish watching #{build.project_name} ##{build.build_number}" print_bordered text.blue TerminalNotifier.notify text end
get_build(options)
click to toggle source
# File lib/circler/command/watch_command.rb, line 28 def get_build(options) username, reponame = project_name(options).split('/') number = build_number options Build.get(username, reponame, number) end
print_bordered(text)
click to toggle source
# File lib/circler/command/watch_command.rb, line 68 def print_bordered(text) say Terminal::Table.new(rows: [[text]], style: { width: 120 }).to_s end
setup_client()
click to toggle source
# File lib/circler/command/watch_command.rb, line 23 def setup_client @client = CirclerPusherClient.new @client.connect end
start_watch(build)
click to toggle source
# File lib/circler/command/watch_command.rb, line 34 def start_watch(build) @running = true text = "Start watching #{build.project_name} ##{build.build_number}" print_bordered text TerminalNotifier.notify text bind_event_handling build.channel_name end
wait_until_finish()
click to toggle source
# File lib/circler/command/watch_command.rb, line 57 def wait_until_finish sleep(1) while @running end