Class: Travis::Surveillance::CLI::Artist

Inherits:
Object
  • Object
show all
Defined in:
lib/travis/surveillance/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Artist

Returns a new instance of Artist.



15
16
17
# File 'lib/travis/surveillance/cli.rb', line 15

def initialize(project)
  @project = project
end

Instance Attribute Details

#projectObject

Returns the value of attribute project.



13
14
15
# File 'lib/travis/surveillance/cli.rb', line 13

def project
  @project
end

Instance Method Details

#drawObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/travis/surveillance/cli.rb', line 19

def draw
  if project.builds.any? && builds = project.builds.reverse
    print "\x1b[2J\x1b[H"

    latest = builds.first

    table = Terminal::Table.new title: "#{project.owner}/#{project.name} (#{project.url})", style: { width: 120 } do |t|
      t << ["Build", "#{latest.number} (#{latest.url})"]
      t << ["Duration", latest.duration] unless latest.building?
      t << ["Branch", latest.branch]
      t << ["Commit", latest.commit]
      t << ["Compare URL", latest.compare_url]
      t << ["Author", latest.author_name]
      t << ["Message", latest.message.length > 80 ? "#{latest.message[0..80]}..." : latest.message]
    end

    print table
    print "\n\n"

    table = Terminal::Table.new title: "Build Matrix", headings: ['Job', 'State', 'Duration', 'Runtime', 'ENV'], style: { width: 120 } do |t|
      latest.jobs.each do |job|
        t << [job.number, job.state, job.duration, job.runtime, ((job.config.env && job.config.env.length > 30) ? "#{job.config.env[0..30]}..." : job.config.env)]
      end
    end

    print table

    if builds.size > 1
      print "\n\n"

      table = Terminal::Table.new :title => "Build History", :headings => ['Build', 'State', 'Branch', 'Message', 'Duration'], style: { width: 120 } do |t|
        builds.each do |build|
          next if build == latest
          t << [build.number, build.state, build.branch, (build.message.length > 30 ? "#{build.message[0..30]}..." : build.message), build.duration]
        end
      end

      print table
    end
  end

  print "\x1b[H"
  $stdout.flush
end