Class: Debci::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/debci/status.rb

Overview

This class represents one test execution.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#architectureObject

Returns the value of attribute architecture



11
12
13
# File 'lib/debci/status.rb', line 11

def architecture
  @architecture
end

#blameObject

Returns the value of attribute blame



10
11
12
# File 'lib/debci/status.rb', line 10

def blame
  @blame
end

#dateObject

Returns the value of attribute date



11
12
13
# File 'lib/debci/status.rb', line 11

def date
  @date
end

#duration_humanObject

Returns the value of attribute duration_human



11
12
13
# File 'lib/debci/status.rb', line 11

def duration_human
  @duration_human
end

#duration_secondsObject

Returns the value of attribute duration_seconds



11
12
13
# File 'lib/debci/status.rb', line 11

def duration_seconds
  @duration_seconds
end

#messageObject

Returns the value of attribute message



11
12
13
# File 'lib/debci/status.rb', line 11

def message
  @message
end

#packageObject

Returns the value of attribute package



11
12
13
# File 'lib/debci/status.rb', line 11

def package
  @package
end

#previous_statusObject

Returns the value of attribute previous_status



11
12
13
# File 'lib/debci/status.rb', line 11

def previous_status
  @previous_status
end

#run_idObject

Returns the value of attribute run_id



11
12
13
# File 'lib/debci/status.rb', line 11

def run_id
  @run_id
end

#statusObject

Returns the value of attribute status



11
12
13
# File 'lib/debci/status.rb', line 11

def status
  @status
end

#suiteObject

Returns the value of attribute suite



11
12
13
# File 'lib/debci/status.rb', line 11

def suite
  @suite
end

#versionObject

Returns the value of attribute version



11
12
13
# File 'lib/debci/status.rb', line 11

def version
  @version
end

Class Method Details

.from_data(data, suite, architecture) ⇒ Object

Populates an object by reading from a data hash



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/debci/status.rb', line 88

def self.from_data(data, suite, architecture)
  status = Debci::Status.new

  status.suite = suite
  status.architecture = architecture
  status.run_id = data['run_id'] || data['date']
  status.package = data['package']
  status.version = data['version']
  status.date =
    begin
      Time.parse(data.fetch('date', 'unknown') + ' UTC')
    rescue ArgumentError
      nil
    end
  status.status = data.fetch('status', :unknown).to_sym
  status.previous_status = data.fetch('previous_status', :unknown).to_sym
  status.blame = data['blame']
  status.duration_seconds =
    begin
      Integer(data.fetch('duration_seconds', 0))
    rescue ArgumentError
      nil
    end
  status.duration_human = data['duration_human']
  status.message = data['message']

  status
end

.from_file(file, suite, architecture) ⇒ Object

Constructs a new object by reading the JSON status file.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/debci/status.rb', line 62

def self.from_file(file, suite, architecture)
  status = new
  status.suite = suite
  status.architecture = architecture

  unless File.exists?(file)
    status.status = :no_test_data
    return status
  end

  data = nil

  begin
    File.open(file, 'r') do |f|
      data = JSON.load(f)
    end
  rescue JSON::ParserError
    true # nothing really
  end

  return status unless data

  from_data(data, suite, architecture)
end

Instance Method Details

#descriptionObject

A longer version of the headline



38
39
40
# File 'lib/debci/status.rb', line 38

def description
  "The tests for #{package} #{status.upcase}ED on #{suite}/#{architecture} but have previously #{previous_status.upcase}ED."
end

#headlineObject

Returns a headline for this status object, to be used as a short description of the event it represents



33
34
35
# File 'lib/debci/status.rb', line 33

def headline
  "#{package} tests #{status.upcase}ED on #{suite}/#{architecture}"
end

#inspectObject



117
118
119
# File 'lib/debci/status.rb', line 117

def inspect
  "<#{suite}/#{architecture} #{status}>"
end

#newsworthy?Boolean

Returns true if this status object represents an important event, such as a package that used to pass started failing, of vice versa.

Returns:

  • (Boolean)


15
16
17
18
19
20
# File 'lib/debci/status.rb', line 15

def newsworthy?
  [
    [:fail, :pass],
    [:pass, :fail],
  ].include?([status, previous_status])
end

#timeObject

Returns the amount of time since the date for this status object



51
52
53
54
55
56
57
58
59
# File 'lib/debci/status.rb', line 51

def time
  days = (Time.now - date)/86400

  if days >= 1 || days <= -1
    "#{days.floor} day(s) ago"
  else
    "#{Time.at(Time.now - date).gmtime.strftime('%H')} hour(s) ago"
  end
end

#titleObject



22
23
24
25
26
27
28
29
# File 'lib/debci/status.rb', line 22

def title
  {
    :pass => "Pass",
    :fail => "Fail",
    :tmpfail => "Temporary failure",
    :no_test_data => "No test data",
  }.fetch(status, "Unknown")
end