Class: BuildBuddy::BuildData

Inherits:
Object
  • Object
show all
Defined in:
lib/build_buddy/build_data.rb

Constant Summary collapse

GITHUB_URL =
"https://github.com"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ BuildData

Returns a new instance of BuildData.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/build_buddy/build_data.rb', line 40

def initialize(args)
  args.each do |key, value|
    begin
      self.method((key.to_s + '=').to_sym).call(value)
    rescue NameError
      # Ignore fields in the database we don't understand
    end
  end

  BuildBuddy::bb_id_mutex.synchronize {
    bb_id = BuildBuddy::bb_id
    @bb_id = 'BB-' + bb_id.to_s
    BuildBuddy::bb_id = bb_id + 1
  }
  @create_time = Time.now.utc
end

Instance Attribute Details

#_idObject

Mongo ID



20
21
22
# File 'lib/build_buddy/build_data.rb', line 20

def _id
  @_id
end

#bb_idObject

Build Buddy id



21
22
23
# File 'lib/build_buddy/build_data.rb', line 21

def bb_id
  @bb_id
end

#branchObject

Returns the value of attribute branch.



25
26
27
# File 'lib/build_buddy/build_data.rb', line 25

def branch
  @branch
end

#create_timeObject

Returns the value of attribute create_time.



22
23
24
# File 'lib/build_buddy/build_data.rb', line 22

def create_time
  @create_time
end

#end_timeObject

Returns the value of attribute end_time.



34
35
36
# File 'lib/build_buddy/build_data.rb', line 34

def end_time
  @end_time
end

#exit_codeObject

Returns the value of attribute exit_code.



32
33
34
# File 'lib/build_buddy/build_data.rb', line 32

def exit_code
  @exit_code
end

#flagsObject

Returns the value of attribute flags.



35
36
37
# File 'lib/build_buddy/build_data.rb', line 35

def flags
  @flags
end

#metricsObject

Returns the value of attribute metrics.



36
37
38
# File 'lib/build_buddy/build_data.rb', line 36

def metrics
  @metrics
end

#pull_requestObject

Returns the value of attribute pull_request.



26
27
28
# File 'lib/build_buddy/build_data.rb', line 26

def pull_request
  @pull_request
end

#pull_request_titleObject

Returns the value of attribute pull_request_title.



27
28
29
# File 'lib/build_buddy/build_data.rb', line 27

def pull_request_title
  @pull_request_title
end

#repo_full_nameObject

Returns the value of attribute repo_full_name.



24
25
26
# File 'lib/build_buddy/build_data.rb', line 24

def repo_full_name
  @repo_full_name
end

#repo_shaObject

Returns the value of attribute repo_sha.



28
29
30
# File 'lib/build_buddy/build_data.rb', line 28

def repo_sha
  @repo_sha
end

#start_timeObject

Returns the value of attribute start_time.



33
34
35
# File 'lib/build_buddy/build_data.rb', line 33

def start_time
  @start_time
end

#started_byObject

Returns the value of attribute started_by.



30
31
32
# File 'lib/build_buddy/build_data.rb', line 30

def started_by
  @started_by
end

#stopped_byObject

Returns the value of attribute stopped_by.



31
32
33
# File 'lib/build_buddy/build_data.rb', line 31

def stopped_by
  @stopped_by
end

#termination_typeObject

:killed or :exited



29
30
31
# File 'lib/build_buddy/build_data.rb', line 29

def termination_type
  @termination_type
end

#typeObject

one of :master, :release or :pull_request



23
24
25
# File 'lib/build_buddy/build_data.rb', line 23

def type
  @type
end

Class Method Details

.server_log_uri(id) ⇒ Object



67
68
69
# File 'lib/build_buddy/build_data.rb', line 67

def self.server_log_uri(id)
  Config.server_base_uri + '/build/' + id.to_s + '/log.html'
end

.server_report_uri(id) ⇒ Object



71
72
73
# File 'lib/build_buddy/build_data.rb', line 71

def self.server_report_uri(id)
  Config.server_base_uri + '/build/' + id.to_s + '/report.html'
end

Instance Method Details

#run_timeObject



94
95
96
97
98
# File 'lib/build_buddy/build_data.rb', line 94

def run_time
  end_time = @end_time.nil? ? Time.now.utc : @end_time
  start_time = @start_time.nil? ? end_time : @start_time
  Time.at(end_time - start_time).utc.strftime('%H:%M:%S.%L')
end

#server_log_uriObject



63
64
65
# File 'lib/build_buddy/build_data.rb', line 63

def server_log_uri
  BuildData.server_log_uri(@_id)
end

#status_verbObject



75
76
77
78
79
80
81
# File 'lib/build_buddy/build_data.rb', line 75

def status_verb
  if @termination_type == :killed
    'stopped'
  else
    @exit_code != 0 ? 'failed' : 'succeeded'
  end
end

#to_hObject



57
58
59
60
61
# File 'lib/build_buddy/build_data.rb', line 57

def to_h
  hash = {}
  instance_variables.each {|var| hash[var.to_s.delete("@").to_sym] = instance_variable_get(var) }
  hash
end

#url_and_branch_nameObject



83
84
85
86
87
88
89
90
91
92
# File 'lib/build_buddy/build_data.rb', line 83

def url_and_branch_name
  if @type == :branch
    branch_name = "#{@repo_full_name}/#{@branch}"
    url = "#{GITHUB_URL}/#{@repo_full_name}/tree/#{@branch}"
  else
    branch_name = "#{@repo_full_name}/pr/#{@pull_request}"
    url = "#{GITHUB_URL}/#{@repo_full_name}/pull/#{@pull_request}"
  end
  [url, branch_name]
end