Class: Bk::Commands::Annotations

Inherits:
Base
  • Object
show all
Defined in:
lib/bk/commands/annotations.rb

Constant Summary collapse

BuildAnnotationsQuery =
Client.parse "    query($slug: ID!) {\n      build(slug: $slug) {\n        number\n\n        pipeline {\n          slug\n        }\n\n        branch\n        message\n\n        url\n        pullRequest {\n          id\n        }\n        state\n        startedAt\n        finishedAt\n        canceledAt\n\n        annotations(first: 200) {\n          edges {\n            node {\n              context\n              style\n              body {\n                text\n              }\n            }\n          }\n        }\n      }\n    }\n"

Constants included from Format

Format::HORIZONTAL_PIPE, Format::VERTICAL_PIPE

Instance Attribute Summary

Attributes inherited from Base

#spinner

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Format

#annotation_colors, #build_colors, #build_header, #is_tty?, #job_colors, #pastel, #vertical_pipe

Methods included from Bk::Color

#colorize, #create_color_hash, #default_color, #error_color, #info_color, #success_color, #warning_color

Constructor Details

This class inherits a constructor from Bk::Commands::Base

Instance Method Details

#call(args: {}, url_or_slug: nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bk/commands/annotations.rb', line 43

def call(args: {}, url_or_slug: nil)
  slug = determine_slug(url_or_slug)
  unless slug
    raise ArgumentError, "Unable to figure out slug to use"
  end

  result = query(BuildAnnotationsQuery, variables: {slug: slug})

  build = result.data.build

  $stdout.puts build_header(build)
  $stdout.puts ""

  annotation_edges = build.annotations.edges
  annotations = annotation_edges.map { |edge| edge.node }

  format = AnnotationFormatter::Markdown.new
  # indent each annotation to separate it from the build status
  annotations.each_with_index do |annotation, index|
    $stdout.puts format.call(annotation)
    # horizontal separator between each
    unless index == annotations.length - 1
      $stdout.puts ""
      $stdout.puts "  #{HORIZONTAL_PIPE * (TTY::Screen.width - 4)}  "
      $stdout.puts ""
    end
  end
end