Module: Bk::Format
- Included in:
- AnnotationFormatter::Markdown, Commands::Base
- Defined in:
- lib/bk/format.rb
Constant Summary collapse
- VERTICAL_PIPE =
"⏐"
- HORIZONTAL_PIPE =
"⎯"
Instance Method Summary collapse
- #annotation_colors ⇒ Object
- #build_colors ⇒ Object
- #build_header(build) ⇒ Object
- #is_tty? ⇒ Boolean
- #job_colors ⇒ Object
- #pastel ⇒ Object
- #vertical_pipe ⇒ Object
Instance Method Details
#annotation_colors ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bk/format.rb', line 51 def annotation_colors return @annotation_colors if defined?(@annotation_colors) @annotation_colors = create_color_hash({ "SUCCESS" => success_color, "ERROR" => error_color, "WARNING" => warning_color, "INFO" => info_color }) end |
#build_colors ⇒ Object
62 63 64 65 66 67 |
# File 'lib/bk/format.rb', line 62 def build_colors return @build_colors if defined?(@build_colors) @build_colors = create_color_hash({ "FAILED" => error_color }) end |
#build_header(build) ⇒ Object
18 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 |
# File 'lib/bk/format.rb', line 18 def build_header(build) io = StringIO.new started_at = Time.parse(build.started_at) finished_at = Time.parse(build.finished_at) if build.finished_at build_color = build_colors[build.state] build_url = pastel.dim("» #{build.url}") # TODO handle multi-line message better io.puts "#{build_color.call(vertical_pipe)}#{pastel.bold(build.)} #{build_url}" io.puts build_color.call(vertical_pipe) state = if build.state == "RUNNING" || build.state == "FAILING" duration = Time.now - started_at minutes = (duration / 60).to_i seconds = (duration % 60).to_i "running for #{minutes}m #{seconds}s" elsif finished_at duration = finished_at - started_at "#{build.state.downcase.capitalize} in #{duration}s" end parts = [ "Build ##{build.number}", build.branch, build_color.call(state) ].join(pastel.dim(" | ")) io.puts "#{build_color.call(vertical_pipe)}#{parts}" io.string end |
#is_tty? ⇒ Boolean
14 15 16 |
# File 'lib/bk/format.rb', line 14 def is_tty? $stdout.tty? end |
#job_colors ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/bk/format.rb', line 69 def job_colors return @job_colors if defined?(@job_colors) @job_colors = Hash.new(error_color) @job_colors.merge!({ "0" => success_color, "BROKEN" => @pastel.dim }) end |
#pastel ⇒ Object
6 7 8 |
# File 'lib/bk/format.rb', line 6 def pastel @pastel ||= Pastel.new end |
#vertical_pipe ⇒ Object
10 11 12 |
# File 'lib/bk/format.rb', line 10 def vertical_pipe is_tty? ? "#{VERTICAL_PIPE} " : "" end |