Class: Travis::CLI::Monitor
- Inherits:
-
ApiCommand
- Object
- Command
- ApiCommand
- Travis::CLI::Monitor
- Defined in:
- lib/travis/cli/monitor.rb
Constant Summary
Constants included from Tools::Assets
Instance Attribute Summary collapse
-
#notification ⇒ Object
readonly
Returns the value of attribute notification.
-
#repos ⇒ Object
readonly
Returns the value of attribute repos.
Attributes inherited from ApiCommand
Attributes inherited from Command
#arguments, #config, #force_interactive, #formatter, #input, #output
Instance Method Summary collapse
- #all? ⇒ Boolean
- #description ⇒ Object
- #events ⇒ Object
-
#initialize ⇒ Monitor
constructor
A new instance of Monitor.
- #monitor?(entity) ⇒ Boolean
- #run ⇒ Object
- #setup ⇒ Object
- #setup_notification(type = nil) ⇒ Object
Methods inherited from ApiCommand
#authenticate, #detected_endpoint?, #endpoint_config, #enterprise?, #org?, #pro?, #sync
Methods included from Travis::Client::Methods
#access_token, #access_token=, #account, #accounts, #api_endpoint, #api_endpoint=, #artifact, #broadcasts, #build, #cancel, #explicit_api_endpoint?, #github_auth, #job, #listen, #repo, #restart, #user, #worker, #workers
Methods inherited from Command
abstract, abstract?, #check_completion, #check_ruby, #check_version, command_name, #command_name, #debug, description, #execute, #help, #info, #last_check, #on_signal, #parse, #say, skip, #terminal, #usage, #write_to
Methods included from Tools::Assets
Methods included from Parser
Constructor Details
#initialize ⇒ Monitor
Returns a new instance of Monitor.
25 26 27 28 |
# File 'lib/travis/cli/monitor.rb', line 25 def initialize(*) @repos = [] super end |
Instance Attribute Details
#notification ⇒ Object (readonly)
Returns the value of attribute notification.
23 24 25 |
# File 'lib/travis/cli/monitor.rb', line 23 def notification @notification end |
#repos ⇒ Object (readonly)
Returns the value of attribute repos.
23 24 25 |
# File 'lib/travis/cli/monitor.rb', line 23 def repos @repos end |
Instance Method Details
#all? ⇒ Boolean
66 67 68 |
# File 'lib/travis/cli/monitor.rb', line 66 def all? !pull? and !push? end |
#description ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/travis/cli/monitor.rb', line 52 def description case repos.size when 0 then session.config['host'] when 1 then repos.first.slug else "#{repos.size} repositories" end end |
#events ⇒ Object
60 61 62 63 64 |
# File 'lib/travis/cli/monitor.rb', line 60 def events events = %w[build:started build:finished] events << 'job:started' << 'job:finished' unless builds? events end |
#monitor?(entity) ⇒ Boolean
70 71 72 73 |
# File 'lib/travis/cli/monitor.rb', line 70 def monitor?(entity) return true if all? entity.pull_request? ? pull? : push? end |
#run ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/travis/cli/monitor.rb', line 75 def run listen(*repos) do |listener| listener.on_connect { say description, "Monitoring #{"builds for " if builds?}%s:" } listener.on(*events) do |event| entity = event.job || event.build time = entity.finished_at || entity.started_at next unless monitor? entity 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}") end end end |
#setup ⇒ Object
30 31 32 33 34 35 |
# 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(repos.any? || :dummy) unless notification end |
#setup_notification(type = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/travis/cli/monitor.rb', line 37 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.) if refuse warn(e.) end |