class Travis::CLI::Monitor

Attributes

notification[R]
repos[R]

Public Class Methods

new(*) click to toggle source
Calls superclass method Travis::CLI::ApiCommand.new
# File lib/travis/cli/monitor.rb, line 25
def initialize(*)
  @repos = []
  super
end

Public Instance Methods

all?() click to toggle source
# File lib/travis/cli/monitor.rb, line 71
def all?
  !pull? and !push?
end
description() click to toggle source
# File lib/travis/cli/monitor.rb, line 53
def description
  case repos.size
  when 0 then session.config['host']
  when 1 then repos.first.slug
  else "#{repos.size} repositories"
  end
end
display(entity, time) click to toggle source
# File lib/travis/cli/monitor.rb, line 80
def display(entity, time)
  say [
    color(formatter.time(time), entity.color),
    color(entity.inspect_info, [entity.color, :bold]),
    color(entity.state, entity.color)
  ].join(" ")
  notification.notify(entity.repository.slug, [
    entity.class.name[/[^:]+$/],
    entity.number,
    entity.state + ":",
    entity.commit.subject
  ].join(" "))
end
events() click to toggle source
# File lib/travis/cli/monitor.rb, line 61
def events
  events = %w[build:started build:finished]
  events << 'job:started' << 'job:finished' unless builds?
  events
end
firehose?() click to toggle source
# File lib/travis/cli/monitor.rb, line 67
def firehose?
  org? and repos.empty?
end
handle_event(event) click to toggle source
# File lib/travis/cli/monitor.rb, line 94
def handle_event(event)
  entity = event.job          || event.build
  time   = entity.finished_at || entity.started_at
  display(entity, time) if monitor? entity
rescue Travis::Client::Error => error
  raise error if explode?
end
monitor?(entity) click to toggle source
# File lib/travis/cli/monitor.rb, line 75
def monitor?(entity)
  return true if all?
  entity.pull_request? ? pull? : push?
end
run() click to toggle source
# File lib/travis/cli/monitor.rb, line 102
def run
  listen(*repos) do |listener|
    listener.on_connect { say description, "Monitoring #{"builds for " if builds?}%s:" }
    listener.on(*events) { |e| handle_event(e) }
  end
end
setup() click to toggle source
Calls superclass method Travis::CLI::ApiCommand#setup
# File lib/travis/cli/monitor.rb, line 30
def setup
  super
  repos.map! { |r| repo(r) }
  repos.concat(user.repositories) if my_repos?
  setup_notification(!firehose? || :dummy) unless notification
  debug "Using notifications: #{notification.class.name[/[^:]+$/]}"
end
setup_notification(type = nil) click to toggle source
# File lib/travis/cli/monitor.rb, line 38
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