lib/travis/cli/monitor.rb in travis-1.5.7.travis.345.4 vs lib/travis/cli/monitor.rb in travis-1.5.7
- old
+ new
@@ -14,10 +14,14 @@
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')
+ on('-p', '--push', 'monitor push events')
+ on('-P', '--pull', 'monitor pull request events')
+
attr_reader :repos, :notification
def initialize(*)
@repos = []
super
@@ -51,21 +55,37 @@
when 1 then repos.first.slug
else "#{repos.size} repositories"
end
end
+ def events
+ events = %w[build:started build:finished]
+ events << 'job:started' << 'job:finished' unless builds?
+ events
+ end
+
+ def all?
+ !pull? and !push?
+ end
+
+ def monitor?(entity)
+ return true if all?
+ entity.pull_request? ? pull? : push?
+ end
+
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|
+ 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("Travis CI", "#{entity.inspect_info} #{entity.state}")
+ notification.notify(entity.repository.slug, "#{entity.class.name[/[^:]+$/]} ##{entity.number} #{entity.state}")
end
end
end
end
end