Class: BuildBuddy::BuildData

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ BuildData

Returns a new instance of BuildData.



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

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.



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

def end_time
  @end_time
end

#exit_codeObject

Returns the value of attribute exit_code.



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

def exit_code
  @exit_code
end

#flagsObject

Returns the value of attribute flags.



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

def flags
  @flags
end

#metricsObject

Returns the value of attribute metrics.



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

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

#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.



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

def repo_sha
  @repo_sha
end

#start_timeObject

Returns the value of attribute start_time.



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

def start_time
  @start_time
end

#started_byObject

Returns the value of attribute started_by.



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

def started_by
  @started_by
end

#stopped_byObject

Returns the value of attribute stopped_by.



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

def stopped_by
  @stopped_by
end

#termination_typeObject

:killed or :exited



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

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



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

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

.server_report_uri(id) ⇒ Object



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

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

Instance Method Details

#log_file_nameObject



86
87
88
89
# File 'lib/build_buddy/build_data.rb', line 86

def log_file_name
  return nil if @start_time.nil?
  File.join(Config.build_output_dir, "#{@start_time.strftime('%Y%m%d-%H%M%S')}.log")
end

#pull_request_uriObject



82
83
84
# File 'lib/build_buddy/build_data.rb', line 82

def pull_request_uri
  "https://github.com/#{@repo_full_name}/pull/#{@pull_request}"
end

#server_log_uriObject



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

def server_log_uri
  BuildData.server_log_uri(@_id)
end

#status_verbObject



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

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

#to_hObject



54
55
56
57
58
59
60
# File 'lib/build_buddy/build_data.rb', line 54

def to_h
  hash = {}
  instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
  # Remove the bb_id field as it's only meaningful while the build-buddy is running
  hash.delete(:bb_id)
  hash
end