lib/travis/cli/monitor.rb in travis-1.11.1 vs lib/travis/cli/monitor.rb in travis-1.12.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
require 'travis/cli'
require 'travis/tools/notification'
module Travis
module CLI
@@ -7,14 +9,14 @@
description "live monitor for what's going on"
on('-m', '--my-repos', 'Only monitor my own repositories')
on('-r', '--repo SLUG', 'monitor given repository (can be used more than once)') do |c, slug|
c.repos << slug
- c.send(:error, "SLUG should be of the form OWNER/REPO") unless slug.split('/').compact.size == 2
+ c.send(:error, 'SLUG should be of the form OWNER/REPO') unless slug.split('/').compact.size == 2
end
- types = Tools::Notification::DEFAULT.map(&:to_s).join(", ")
+ types = Tools::Notification::DEFAULT.map(&:to_s).join(', ')
on('-n', '--[no-]notify [TYPE]', "send out desktop notifications (optional type: #{types})") do |c, type|
c.setup_notification(type)
end
on('-b', '--builds', 'only monitor builds, not jobs')
@@ -73,38 +75,39 @@
!pull? and !push?
end
def monitor?(entity)
return true if all?
+
entity.pull_request? ? pull? : push?
end
def display(entity, time)
say [
color(formatter.time(time), entity.color),
color(entity.inspect_info, [entity.color, :bold]),
color(entity.state, entity.color),
color(entity.commit.subject, entity.color)
- ].join(" ")
+ ].join(' ')
notification.notify(entity.repository.slug, [
entity.class.name[/[^:]+$/],
entity.number,
- entity.state + ":",
+ "#{entity.state}:",
entity.commit.subject
- ].join(" "))
+ ].join(' '))
end
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?
+ rescue Travis::Client::Error => e
+ raise e if explode?
end
def run
listen(*repos) do |listener|
- listener.on_connect { say description, "Monitoring #{"builds for " if builds?}%s:" }
+ listener.on_connect { say description, "Monitoring #{'builds for ' if builds?}%s:" }
listener.on(*events) { |e| handle_event(e) }
end
end
end
end