circleci-cli 0.6.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +21 -19
- data/bin/circle +2 -2
- data/bin/console +1 -1
- data/{circler.gemspec → circleci-cli.gemspec} +3 -3
- data/exe/{circle → circleci-cli} +2 -2
- data/lib/circleci/cli.rb +77 -0
- data/lib/circleci/cli/command.rb +16 -0
- data/lib/circleci/cli/command/base_command.rb +45 -0
- data/lib/circleci/cli/command/browse_command.rb +24 -0
- data/lib/circleci/cli/command/build_command.rb +19 -0
- data/lib/circleci/cli/command/builds_command.rb +25 -0
- data/lib/circleci/cli/command/cancel_command.rb +23 -0
- data/lib/circleci/cli/command/projects_command.rb +16 -0
- data/lib/circleci/cli/command/retry_command.rb +23 -0
- data/lib/circleci/cli/command/watch_command.rb +77 -0
- data/lib/circleci/cli/networking.rb +9 -0
- data/lib/circleci/cli/networking/pusher_client.rb +62 -0
- data/lib/circleci/cli/printer.rb +11 -0
- data/lib/circleci/cli/printer/build_printer.rb +63 -0
- data/lib/circleci/cli/printer/project_printer.rb +37 -0
- data/lib/circleci/cli/printer/step_printer.rb +57 -0
- data/lib/circleci/cli/response.rb +13 -0
- data/lib/circleci/cli/response/account.rb +21 -0
- data/lib/circleci/cli/response/action.rb +39 -0
- data/lib/circleci/cli/response/build.rb +104 -0
- data/lib/circleci/cli/response/project.rb +21 -0
- data/lib/circleci/cli/response/step.rb +22 -0
- data/lib/circleci/cli/version.rb +7 -0
- data/lib/circleci_cli.rb +7 -0
- metadata +29 -25
- data/lib/circler.rb +0 -6
- data/lib/circler/cli.rb +0 -88
- data/lib/circler/command/base_command.rb +0 -41
- data/lib/circler/command/browse_command.rb +0 -20
- data/lib/circler/command/build_command.rb +0 -15
- data/lib/circler/command/builds_command.rb +0 -21
- data/lib/circler/command/cancel_command.rb +0 -19
- data/lib/circler/command/projects_command.rb +0 -12
- data/lib/circler/command/retry_command.rb +0 -19
- data/lib/circler/command/watch_command.rb +0 -73
- data/lib/circler/networking/pusher_client.rb +0 -56
- data/lib/circler/printer/build_printer.rb +0 -59
- data/lib/circler/printer/project_printer.rb +0 -33
- data/lib/circler/printer/step_printer.rb +0 -53
- data/lib/circler/response/account.rb +0 -17
- data/lib/circler/response/action.rb +0 -35
- data/lib/circler/response/build.rb +0 -100
- data/lib/circler/response/project.rb +0 -17
- data/lib/circler/response/step.rb +0 -18
- data/lib/circler/version.rb +0 -5
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Circler
|
4
|
-
class BuildPrinter
|
5
|
-
def initialize(builds, pretty: true)
|
6
|
-
@builds = builds
|
7
|
-
@pretty = pretty
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_s
|
11
|
-
@pretty ? print_pretty : print_compact
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def print_compact
|
17
|
-
rows.map { |row| pad_columns_by_space(row, max_row_widths) }.join("\n")
|
18
|
-
end
|
19
|
-
|
20
|
-
def print_pretty
|
21
|
-
Terminal::Table.new(title: title, headings: headings, rows: rows).to_s
|
22
|
-
end
|
23
|
-
|
24
|
-
def title
|
25
|
-
build = @builds.first
|
26
|
-
"Recent Builds / #{build.project_name}".green
|
27
|
-
end
|
28
|
-
|
29
|
-
def headings
|
30
|
-
%w[Number Status Branch Author Commit Duration StartTime]
|
31
|
-
end
|
32
|
-
|
33
|
-
def rows
|
34
|
-
@builds.map(&:information)
|
35
|
-
end
|
36
|
-
|
37
|
-
def max_row_widths
|
38
|
-
@builds
|
39
|
-
.map(&:information)
|
40
|
-
.map { |array| array.map(&:to_s).map(&:size) }
|
41
|
-
.transpose
|
42
|
-
.map(&:max)
|
43
|
-
end
|
44
|
-
|
45
|
-
def pad_columns_by_space(columns, max_widths)
|
46
|
-
columns
|
47
|
-
.map
|
48
|
-
.with_index { |column, i| pad_column_by_space(column, max_widths, i) }
|
49
|
-
.join(' ')
|
50
|
-
.to_s
|
51
|
-
end
|
52
|
-
|
53
|
-
def pad_column_by_space(column, max_widths, index)
|
54
|
-
column_string = column.to_s
|
55
|
-
spaces = ' ' * (max_widths[index] - column_string.size)
|
56
|
-
column_string + spaces
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Circler
|
4
|
-
class ProjectPrinter
|
5
|
-
attr_accessor :compact
|
6
|
-
def initialize(projects, pretty: true)
|
7
|
-
@projects = projects
|
8
|
-
@pretty = pretty
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_s
|
12
|
-
@pretty ? print_pretty : print_compact
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def print_compact
|
18
|
-
@projects
|
19
|
-
.map(&:information)
|
20
|
-
.map { |array| array.join('/').to_s }
|
21
|
-
.sort
|
22
|
-
.join("\n")
|
23
|
-
end
|
24
|
-
|
25
|
-
def print_pretty
|
26
|
-
Terminal::Table.new(
|
27
|
-
title: 'Projects'.green,
|
28
|
-
headings: ['User name', 'Repository name'],
|
29
|
-
rows: @projects.map(&:information)
|
30
|
-
).to_s
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Circler
|
4
|
-
class StepPrinter
|
5
|
-
def initialize(steps, pretty: true)
|
6
|
-
@steps = steps
|
7
|
-
@pretty = pretty
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_s
|
11
|
-
Terminal::Table.new do |t|
|
12
|
-
@steps
|
13
|
-
.group_by(&:type)
|
14
|
-
.each do |key, steps|
|
15
|
-
t << :separator
|
16
|
-
t << [{ value: key.green, alignment: :center, colspan: 2 }]
|
17
|
-
steps.each { |s| print_actions(t, s) }
|
18
|
-
end
|
19
|
-
end.to_s
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def colorize_by_status(string, status)
|
25
|
-
case status
|
26
|
-
when 'success', 'fixed' then string.green
|
27
|
-
when 'canceled' then string.yellow
|
28
|
-
when 'failed', 'timedout' then string.red
|
29
|
-
when 'no_tests', 'not_run' then string.light_black
|
30
|
-
else string
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def format_time(time)
|
35
|
-
return '' unless time
|
36
|
-
|
37
|
-
minute = format('%02d', time / 1000 / 60)
|
38
|
-
second = format('%02d', (time / 1000) % 60)
|
39
|
-
"#{minute}:#{second}"
|
40
|
-
end
|
41
|
-
|
42
|
-
def print_actions(table, step)
|
43
|
-
table << :separator
|
44
|
-
step.actions.each do |a|
|
45
|
-
table << [
|
46
|
-
colorize_by_status(a.name.slice(0..120), a.status),
|
47
|
-
format_time(a.run_time_millis)
|
48
|
-
]
|
49
|
-
table << [{ value: a.log, alignment: :left, colspan: 2 }] if a.failed? && a.log
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Circler
|
4
|
-
class Action
|
5
|
-
attr_reader :name, :status, :run_time_millis
|
6
|
-
def initialize(hash)
|
7
|
-
@hash = hash
|
8
|
-
@name = hash['name']
|
9
|
-
@status = hash['status']
|
10
|
-
@run_time_millis = hash['run_time_millis']
|
11
|
-
end
|
12
|
-
|
13
|
-
def log
|
14
|
-
request(@hash['output_url'])
|
15
|
-
.map do |r|
|
16
|
-
r['message']
|
17
|
-
.gsub(/\r\n/, "\n")
|
18
|
-
.gsub(/\e\[A\r\e\[2K/, '')
|
19
|
-
.scan(/.{1,120}/)
|
20
|
-
.join("\n")
|
21
|
-
end
|
22
|
-
.join("\n")
|
23
|
-
end
|
24
|
-
|
25
|
-
def failed?
|
26
|
-
@status == 'timedout' || @status == 'failed'
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def request(url)
|
32
|
-
JSON.parse(Faraday.new(url).get.body)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Circler
|
4
|
-
class Build
|
5
|
-
class << self
|
6
|
-
def all(username, reponame)
|
7
|
-
CircleCi::Project.new(username, reponame, 'github').recent_builds
|
8
|
-
.body
|
9
|
-
.map { |b| Build.new(b) }
|
10
|
-
end
|
11
|
-
|
12
|
-
def branch(username, reponame, branch)
|
13
|
-
CircleCi::Project.new(username, reponame, 'github').recent_builds_branch(branch)
|
14
|
-
.body
|
15
|
-
.map { |b| Build.new(b) }
|
16
|
-
end
|
17
|
-
|
18
|
-
def get(username, reponame, number)
|
19
|
-
Build.new(CircleCi::Build.new(username, reponame, 'github', number).get.body)
|
20
|
-
end
|
21
|
-
|
22
|
-
def retry(username, reponame, number)
|
23
|
-
Build.new(CircleCi::Build.new(username, reponame, 'github', number).retry.body)
|
24
|
-
end
|
25
|
-
|
26
|
-
def cancel(username, reponame, number)
|
27
|
-
Build.new(CircleCi::Build.new(username, reponame, 'github', number).cancel.body)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def initialize(hash)
|
32
|
-
@hash = hash
|
33
|
-
end
|
34
|
-
|
35
|
-
def username
|
36
|
-
@hash['username']
|
37
|
-
end
|
38
|
-
|
39
|
-
def reponame
|
40
|
-
@hash['reponame']
|
41
|
-
end
|
42
|
-
|
43
|
-
def status
|
44
|
-
@hash['status']
|
45
|
-
end
|
46
|
-
|
47
|
-
def build_number
|
48
|
-
@hash['build_num']
|
49
|
-
end
|
50
|
-
|
51
|
-
def running?
|
52
|
-
status == 'running'
|
53
|
-
end
|
54
|
-
|
55
|
-
def channel_name
|
56
|
-
"private-#{username}@#{reponame}@#{build_number}@vcs-github@0"
|
57
|
-
end
|
58
|
-
|
59
|
-
def project_name
|
60
|
-
"#{username}/#{reponame}"
|
61
|
-
end
|
62
|
-
|
63
|
-
def information
|
64
|
-
[
|
65
|
-
@hash['build_num'],
|
66
|
-
colorize_by_status(@hash['status'], @hash['status']),
|
67
|
-
colorize_by_status(@hash['branch'], @hash['status']),
|
68
|
-
@hash['author_name'],
|
69
|
-
(@hash['subject'] || '').slice(0..60),
|
70
|
-
format_time(@hash['build_time_millis']),
|
71
|
-
@hash['start_time']
|
72
|
-
]
|
73
|
-
end
|
74
|
-
|
75
|
-
def steps
|
76
|
-
hash = @hash['steps'].group_by { |s| s['actions'].first['type'] }
|
77
|
-
hash.flat_map { |type, value| value.map { |v| Step.new(type, v) } }
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
def colorize_by_status(string, status)
|
83
|
-
case status
|
84
|
-
when 'success', 'fixed' then string.green
|
85
|
-
when 'canceled' then string.yellow
|
86
|
-
when 'failed' then string.red
|
87
|
-
when 'no_tests', 'not_run' then string.light_black
|
88
|
-
else string
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def format_time(time)
|
93
|
-
return '' unless time
|
94
|
-
|
95
|
-
minute = format('%02d', time / 1000 / 60)
|
96
|
-
second = format('%02d', (time / 1000) % 60)
|
97
|
-
"#{minute}:#{second}"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Circler
|
4
|
-
class Project
|
5
|
-
def initialize(hash)
|
6
|
-
@hash = hash
|
7
|
-
end
|
8
|
-
|
9
|
-
def information
|
10
|
-
[@hash['username'], @hash['reponame']]
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.all
|
14
|
-
CircleCi::Projects.new.get.body.map { |p| Project.new(p) }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Circler
|
4
|
-
class Step
|
5
|
-
attr_reader :type
|
6
|
-
attr_reader :status
|
7
|
-
|
8
|
-
def initialize(type, hash)
|
9
|
-
@type = type
|
10
|
-
@status = hash['status']
|
11
|
-
@hash = hash
|
12
|
-
end
|
13
|
-
|
14
|
-
def actions
|
15
|
-
@hash['actions'].map { |a| Action.new(a) }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|