Class: CircleCI::CLI::Response::Build

Inherits:
Object
  • Object
show all
Defined in:
lib/circleci/cli/response/build.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Build

rubocop:disable Metrics/MethodLength



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/circleci/cli/response/build.rb', line 42

def initialize(hash) # rubocop:disable Metrics/MethodLength
  @hash = hash
  @username = hash['username']
  @build_number = hash['build_num']
  @reponame = hash['reponame']
  @branch = hash['branch']
  @status = hash['status']
  @author_name = hash['author_name']
  @start_time = hash['start_time']
  @user = hash.dig('user', 'login')
  @workflow_name = hash.dig('workflows', 'workflow_name')
  @workflow_job_name = hash.dig('workflows', 'job_name')
end

Instance Attribute Details

#author_nameObject (readonly)

Returns the value of attribute author_name.



39
40
41
# File 'lib/circleci/cli/response/build.rb', line 39

def author_name
  @author_name
end

#branchObject (readonly)

Returns the value of attribute branch.



39
40
41
# File 'lib/circleci/cli/response/build.rb', line 39

def branch
  @branch
end

#build_numberObject (readonly)

Returns the value of attribute build_number.



39
40
41
# File 'lib/circleci/cli/response/build.rb', line 39

def build_number
  @build_number
end

#reponameObject (readonly)

Returns the value of attribute reponame.



39
40
41
# File 'lib/circleci/cli/response/build.rb', line 39

def reponame
  @reponame
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



39
40
41
# File 'lib/circleci/cli/response/build.rb', line 39

def start_time
  @start_time
end

#statusObject (readonly)

Returns the value of attribute status.



39
40
41
# File 'lib/circleci/cli/response/build.rb', line 39

def status
  @status
end

#userObject (readonly)

Returns the value of attribute user.



39
40
41
# File 'lib/circleci/cli/response/build.rb', line 39

def user
  @user
end

#usernameObject (readonly)

Returns the value of attribute username.



39
40
41
# File 'lib/circleci/cli/response/build.rb', line 39

def username
  @username
end

#workflow_job_nameObject (readonly)

Returns the value of attribute workflow_job_name.



39
40
41
# File 'lib/circleci/cli/response/build.rb', line 39

def workflow_job_name
  @workflow_job_name
end

#workflow_nameObject (readonly)

Returns the value of attribute workflow_name.



39
40
41
# File 'lib/circleci/cli/response/build.rb', line 39

def workflow_name
  @workflow_name
end

Class Method Details

.all(username, reponame) ⇒ Object



8
9
10
11
12
# File 'lib/circleci/cli/response/build.rb', line 8

def all(username, reponame)
  CircleCi::Project.new(username, reponame, 'github').recent_builds
                   .body
                   .map { |b| Build.new(b) }
end

.branch(username, reponame, branch) ⇒ Object



20
21
22
23
24
# File 'lib/circleci/cli/response/build.rb', line 20

def branch(username, reponame, branch)
  CircleCi::Project.new(username, reponame, 'github').recent_builds_branch(branch)
                   .body
                   .map { |b| Build.new(b) }
end

.cancel(username, reponame, number) ⇒ Object



34
35
36
# File 'lib/circleci/cli/response/build.rb', line 34

def cancel(username, reponame, number)
  Build.new(CircleCi::Build.new(username, reponame, 'github', number).cancel.body)
end

.failed(username, reponame) ⇒ Object



14
15
16
17
18
# File 'lib/circleci/cli/response/build.rb', line 14

def failed(username, reponame)
  CircleCi::Project.new(username, reponame, 'github').recent_builds(filter: 'failed')
                   .body
                   .map { |b| Build.new(b) }
end

.get(username, reponame, number) ⇒ Object



26
27
28
# File 'lib/circleci/cli/response/build.rb', line 26

def get(username, reponame, number)
  Build.new(CircleCi::Build.new(username, reponame, 'github', number).get.body)
end

.retry(username, reponame, number) ⇒ Object



30
31
32
# File 'lib/circleci/cli/response/build.rb', line 30

def retry(username, reponame, number)
  Build.new(CircleCi::Build.new(username, reponame, 'github', number).retry.body)
end

Instance Method Details

#channel_nameObject



64
65
66
# File 'lib/circleci/cli/response/build.rb', line 64

def channel_name
  "private-#{username}@#{reponame}@#{build_number}@vcs-github@0"
end

#finished?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/circleci/cli/response/build.rb', line 60

def finished?
  %w[success canceled failed no_tests].include?(status)
end

#informationObject



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/circleci/cli/response/build.rb', line 72

def information
  [
    build_number,
    colorize_by_status(status, status),
    colorize_by_status(branch, status),
    author_name,
    (@hash['subject'] || '').slice(0..60),
    format_time(@hash['build_time_millis']),
    start_time
  ]
end

#project_nameObject



68
69
70
# File 'lib/circleci/cli/response/build.rb', line 68

def project_name
  "#{username}/#{reponame}"
end

#running?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/circleci/cli/response/build.rb', line 56

def running?
  status == 'running' || status || 'queued'
end

#stepsObject



84
85
86
87
# File 'lib/circleci/cli/response/build.rb', line 84

def steps
  hash = @hash['steps']&.group_by { |s| s['actions'].first['type'] } || {}
  hash.flat_map { |type, value| value.map { |v| Step.new(type, v) } }
end