class CircleCI::CLI::Response::Build
Attributes
branch[R]
build_number[R]
reponame[R]
start_time[R]
status[R]
user[R]
username[R]
workflow_job_name[R]
workflow_name[R]
Public Class Methods
all(username, reponame)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
new(hash)
click to toggle source
# 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
retry(username, reponame, number)
click to toggle source
# 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
Public Instance Methods
channel_name()
click to toggle source
# File lib/circleci/cli/response/build.rb, line 64 def channel_name "private-#{username}@#{reponame}@#{build_number}@vcs-github@0" end
finished?()
click to toggle source
# File lib/circleci/cli/response/build.rb, line 60 def finished? status == 'success' || status == 'canceled' || status == 'failed' || status == 'no_tests' end
information()
click to toggle source
# 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_name()
click to toggle source
# File lib/circleci/cli/response/build.rb, line 68 def project_name "#{username}/#{reponame}" end
running?()
click to toggle source
# File lib/circleci/cli/response/build.rb, line 56 def running? status == 'running' || status || 'queued' end
steps()
click to toggle source
# 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
Private Instance Methods
colorize_by_status(string, status)
click to toggle source
# File lib/circleci/cli/response/build.rb, line 91 def colorize_by_status(string, status) case status when 'success', 'fixed' then Printer.colorize_green(string) when 'canceled' then Printer.colorize_yellow(string) when 'failed' then Printer.colorize_red(string) when 'no_tests', 'not_run' then Printer.colorize_light_black(string) else string end end
format_time(time)
click to toggle source
# File lib/circleci/cli/response/build.rb, line 101 def format_time(time) return '' unless time minute = format('%<time>02d', time: time / 1000 / 60) second = format('%<time>02d', time: (time / 1000) % 60) "#{minute}:#{second}" end