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

Returns a new instance of Build.



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/circleci/cli/response/build.rb', line 36

def initialize(hash)
  @hash = hash
  @username = hash['username']
  @build_number = hash['build_num']
  @reponame = hash['reponame']
  @status = hash['status']
  @author_name = hash['author_name']
  @start_time = hash['start_time']
  @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.



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

def author_name
  @author_name
end

#build_numberObject (readonly)

Returns the value of attribute build_number.



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

def build_number
  @build_number
end

#reponameObject (readonly)

Returns the value of attribute reponame.



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

def reponame
  @reponame
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



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

def start_time
  @start_time
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

#workflow_job_nameObject (readonly)

Returns the value of attribute workflow_job_name.



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

def workflow_job_name
  @workflow_job_name
end

#workflow_nameObject (readonly)

Returns the value of attribute workflow_name.



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

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



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

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



28
29
30
# File 'lib/circleci/cli/response/build.rb', line 28

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

.get(username, reponame, number) ⇒ Object



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

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

.retry(username, reponame, number) ⇒ Object



24
25
26
# File 'lib/circleci/cli/response/build.rb', line 24

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

Instance Method Details

#channel_nameObject



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

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

#finished?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/circleci/cli/response/build.rb', line 52

def finished?
  status == 'success' || status == 'canceled' || status == 'failed' || status == 'no_tests'
end

#informationObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/circleci/cli/response/build.rb', line 64

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

#project_nameObject



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

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

#running?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/circleci/cli/response/build.rb', line 48

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

#stepsObject



76
77
78
79
# File 'lib/circleci/cli/response/build.rb', line 76

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