class Travis::CLI::Monitor
def description
def description case repos.size when 0 then session.config['host'] when 1 then repos.first.slug else "#{repos.size} repositories" end end
def initialize(*)
def initialize(*) @repos = [] super end
def run
def run listen(*repos) do |listener| listener.on_connect { say description, 'Monitoring %s:' } listener.on 'build:started', 'job:started', 'build:finished', 'job:finished' do |event| entity = event.job || event.build time = entity.finished_at || entity.started_at say [ color(formatter.time(time), entity.color), color(entity.inspect_info, [entity.color, :bold]), color(entity.state, entity.color) ].join(" ") notification.notify("Travis CI", "#{entity.inspect_info} #{entity.state}") end end end
def setup
def setup super repos.map! { |r| repo(r) } repos.concat(user.repositories) if my_repos? setup_notification(repos.any? || :dummy) unless notification end
def setup_notification(type = nil)
def setup_notification(type = nil) refuse = false case type when false then @notification = Tools::Notification.new(:dummy) when nil, true then @notification = Tools::Notification.new else refuse = true @notification = Tools::Notification.new(type) end rescue ArgumentError => e @notification = Tools::Notification.new(:dummy) error(e.message) if refuse warn(e.message) end