buildkite-cli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.pryrc +4 -0
- data/.rubocop.yml +9 -0
- data/.standard.yml +2 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +142 -0
- data/LICENSE +21 -0
- data/README.md +65 -0
- data/Rakefile +12 -0
- data/exe/bk +5 -0
- data/lefthook.yml +7 -0
- data/lib/bk/annotation_formatter/markdown.rb +58 -0
- data/lib/bk/color.rb +32 -0
- data/lib/bk/commands/annotations.rb +73 -0
- data/lib/bk/commands/artifacts.rb +148 -0
- data/lib/bk/commands.rb +54 -0
- data/lib/bk/format.rb +79 -0
- data/lib/bk/version.rb +5 -0
- data/lib/bk.rb +41 -0
- data/schema.json +35702 -0
- data/sig/bk.rbs +4 -0
- metadata +247 -0
data/lib/bk/format.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
module Bk
|
2
|
+
module Format
|
3
|
+
VERTICAL_PIPE = "⏐"
|
4
|
+
HORIZONTAL_PIPE = "⎯"
|
5
|
+
|
6
|
+
def pastel
|
7
|
+
@pastel ||= Pastel.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def vertical_pipe
|
11
|
+
is_tty? ? "#{VERTICAL_PIPE} " : ""
|
12
|
+
end
|
13
|
+
|
14
|
+
def is_tty?
|
15
|
+
$stdout.tty?
|
16
|
+
end
|
17
|
+
|
18
|
+
def build_header(build)
|
19
|
+
io = StringIO.new
|
20
|
+
|
21
|
+
started_at = Time.parse(build.started_at)
|
22
|
+
finished_at = Time.parse(build.finished_at) if build.finished_at
|
23
|
+
|
24
|
+
build_color = build_colors[build.state]
|
25
|
+
|
26
|
+
build_url = pastel.dim("» #{build.url}")
|
27
|
+
# TODO handle multi-line message better
|
28
|
+
io.puts "#{build_color.call(vertical_pipe)}#{pastel.bold(build.message)} #{build_url}"
|
29
|
+
io.puts build_color.call(vertical_pipe)
|
30
|
+
|
31
|
+
state = if build.state == "RUNNING" || build.state == "FAILING"
|
32
|
+
duration = Time.now - started_at
|
33
|
+
minutes = (duration / 60).to_i
|
34
|
+
seconds = (duration % 60).to_i
|
35
|
+
"running for #{minutes}m #{seconds}s"
|
36
|
+
elsif finished_at
|
37
|
+
duration = finished_at - started_at
|
38
|
+
"#{build.state.downcase.capitalize} in #{duration}s"
|
39
|
+
end
|
40
|
+
|
41
|
+
parts = [
|
42
|
+
"Build ##{build.number}",
|
43
|
+
build.branch,
|
44
|
+
build_color.call(state)
|
45
|
+
].join(pastel.dim(" | "))
|
46
|
+
io.puts "#{build_color.call(vertical_pipe)}#{parts}"
|
47
|
+
|
48
|
+
io.string
|
49
|
+
end
|
50
|
+
|
51
|
+
def annotation_colors
|
52
|
+
return @annotation_colors if defined?(@annotation_colors)
|
53
|
+
|
54
|
+
@annotation_colors = create_color_hash({
|
55
|
+
"SUCCESS" => success_color,
|
56
|
+
"ERROR" => error_color,
|
57
|
+
"WARNING" => warning_color,
|
58
|
+
"INFO" => info_color
|
59
|
+
})
|
60
|
+
end
|
61
|
+
|
62
|
+
def build_colors
|
63
|
+
return @build_colors if defined?(@build_colors)
|
64
|
+
@build_colors = create_color_hash({
|
65
|
+
"FAILED" => error_color
|
66
|
+
})
|
67
|
+
end
|
68
|
+
|
69
|
+
def job_colors
|
70
|
+
return @job_colors if defined?(@job_colors)
|
71
|
+
|
72
|
+
@job_colors = Hash.new(error_color)
|
73
|
+
@job_colors.merge!({
|
74
|
+
"0" => success_color,
|
75
|
+
"BROKEN" => @pastel.dim
|
76
|
+
})
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/lib/bk/version.rb
ADDED
data/lib/bk.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "zeitwerk"
|
4
|
+
loader = Zeitwerk::Loader.for_gem
|
5
|
+
loader.setup
|
6
|
+
|
7
|
+
require "json"
|
8
|
+
require "httparty"
|
9
|
+
require "tty-pager"
|
10
|
+
require "tty-markdown"
|
11
|
+
require "tty-spinner"
|
12
|
+
require "tty-box"
|
13
|
+
require "graphql/client"
|
14
|
+
require "graphql/client/http"
|
15
|
+
require "dry/cli"
|
16
|
+
require "cgi"
|
17
|
+
|
18
|
+
require_relative "bk/version"
|
19
|
+
|
20
|
+
module Bk
|
21
|
+
class Error < StandardError; end
|
22
|
+
|
23
|
+
# Configure GraphQL endpoint using the basic HTTP network adapter.
|
24
|
+
HTTP = GraphQL::Client::HTTP.new("https://graphql.buildkite.com/v1") do
|
25
|
+
def headers(context)
|
26
|
+
unless (token = context[:access_token] || ENV["BUILDKITE_API_TOKEN"])
|
27
|
+
raise "missing BuildKite access token"
|
28
|
+
end
|
29
|
+
|
30
|
+
{
|
31
|
+
"Authorization" => "Bearer #{token}",
|
32
|
+
"Content-Type" => "application/json"
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
SCHEMA_PATH = Pathname.new(__FILE__).dirname.dirname.join("schema.json")
|
38
|
+
Schema = GraphQL::Client.load_schema(SCHEMA_PATH.to_s)
|
39
|
+
# Schema = GraphQL::Client.load_schema(HTTP)
|
40
|
+
Client = GraphQL::Client.new(schema: Schema, execute: HTTP)
|
41
|
+
end
|