Sha256: e8758bc8361a75264c7bd74a728ad8d8ed7a5562bb561756f9b5c1662c2f69cb

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require 'travis/cli'

module Travis
  module CLI
    class Monitor < ApiCommand
      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
      end

      attr_reader :repos

      def initialize(*)
        @repos = []
        super
      end

      def setup
        super
        repos.map! { |r| repo(r) }
        repos.concat(user.repositories) if my_repos?
      end

      def description
        case repos.size
        when 0 then session.config['host']
        when 1 then repos.first.slug
        else "#{repos.size} repositories"
        end
      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|
            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(" ")
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
travis-1.5.3 lib/travis/cli/monitor.rb