Class: Circler::Build

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Build

Returns a new instance of Build.



31
32
33
# File 'lib/circler/response/build.rb', line 31

def initialize(hash)
  @hash = hash
end

Class Method Details

.all(username, reponame) ⇒ Object



6
7
8
9
10
# File 'lib/circler/response/build.rb', line 6

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

.branch(username, reponame, branch) ⇒ Object



12
13
14
15
16
# File 'lib/circler/response/build.rb', line 12

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



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

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

.get(username, reponame, number) ⇒ Object



18
19
20
# File 'lib/circler/response/build.rb', line 18

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

.retry(username, reponame, number) ⇒ Object



22
23
24
# File 'lib/circler/response/build.rb', line 22

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

Instance Method Details

#build_numberObject



47
48
49
# File 'lib/circler/response/build.rb', line 47

def build_number
  @hash['build_num']
end

#channel_nameObject



55
56
57
# File 'lib/circler/response/build.rb', line 55

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

#informationObject



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

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

#project_nameObject



59
60
61
# File 'lib/circler/response/build.rb', line 59

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

#reponameObject



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

def reponame
  @hash['reponame']
end

#running?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/circler/response/build.rb', line 51

def running?
  status == 'running'
end

#statusObject



43
44
45
# File 'lib/circler/response/build.rb', line 43

def status
  @hash['status']
end

#stepsObject



75
76
77
78
# File 'lib/circler/response/build.rb', line 75

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

#usernameObject



35
36
37
# File 'lib/circler/response/build.rb', line 35

def username
  @hash['username']
end