Class: CIQuantum::Build
- Inherits:
-
Struct
- Object
- Struct
- CIQuantum::Build
- Defined in:
- lib/ciquantum/build.rb
Instance Attribute Summary collapse
-
#branch ⇒ Object
Returns the value of attribute branch.
-
#finished_at ⇒ Object
Returns the value of attribute finished_at.
-
#output ⇒ Object
Returns the value of attribute output.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#project_path ⇒ Object
Returns the value of attribute project_path.
-
#sha ⇒ Object
Returns the value of attribute sha.
-
#started_at ⇒ Object
Returns the value of attribute started_at.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #building? ⇒ Boolean
- #clean_output ⇒ Object
- #commit ⇒ Object
- #dump(file) ⇒ Object
- #duration ⇒ Object
- #env_output ⇒ Object
- #failed? ⇒ Boolean
- #id ⇒ Object
-
#initialize(*args) ⇒ Build
constructor
A new instance of Build.
- #short_sha ⇒ Object
- #test_results ⇒ Object
- #worked? ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Build
Returns a new instance of Build.
5 6 7 8 |
# File 'lib/ciquantum/build.rb', line 5 def initialize(*args) super self.started_at ||= Time.now end |
Instance Attribute Details
#branch ⇒ Object
Returns the value of attribute branch
4 5 6 |
# File 'lib/ciquantum/build.rb', line 4 def branch @branch end |
#finished_at ⇒ Object
Returns the value of attribute finished_at
4 5 6 |
# File 'lib/ciquantum/build.rb', line 4 def finished_at @finished_at end |
#output ⇒ Object
Returns the value of attribute output
4 5 6 |
# File 'lib/ciquantum/build.rb', line 4 def output @output end |
#pid ⇒ Object
Returns the value of attribute pid
4 5 6 |
# File 'lib/ciquantum/build.rb', line 4 def pid @pid end |
#project_path ⇒ Object
Returns the value of attribute project_path
4 5 6 |
# File 'lib/ciquantum/build.rb', line 4 def project_path @project_path end |
#sha ⇒ Object
Returns the value of attribute sha
4 5 6 |
# File 'lib/ciquantum/build.rb', line 4 def sha @sha end |
#started_at ⇒ Object
Returns the value of attribute started_at
4 5 6 |
# File 'lib/ciquantum/build.rb', line 4 def started_at @started_at end |
#status ⇒ Object
Returns the value of attribute status
4 5 6 |
# File 'lib/ciquantum/build.rb', line 4 def status @status end |
Class Method Details
.load(file, project_path) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/ciquantum/build.rb', line 83 def self.load file, project_path puts "Loading build from file: #{file}" if File.exist?(file) config = YAML.load(File.read(file)).unshift(project_path) new *config end end |
Instance Method Details
#building? ⇒ Boolean
23 24 25 |
# File 'lib/ciquantum/build.rb', line 23 def building? status == :building end |
#clean_output ⇒ Object
44 45 46 |
# File 'lib/ciquantum/build.rb', line 44 def clean_output output.gsub(/\e\[.+?m/, '').strip end |
#commit ⇒ Object
53 54 55 56 |
# File 'lib/ciquantum/build.rb', line 53 def commit return if sha.nil? @commit ||= Commit.new(sha, project_path) end |
#dump(file) ⇒ Object
77 78 79 80 81 |
# File 'lib/ciquantum/build.rb', line 77 def dump file config = [started_at, finished_at, sha, status, output, pid, branch] data = YAML.dump(config) File.open(file, 'wb') { |io| io.write(data) } end |
#duration ⇒ Object
27 28 29 30 |
# File 'lib/ciquantum/build.rb', line 27 def duration return if building? finished_at - started_at end |
#env_output ⇒ Object
48 49 50 51 |
# File 'lib/ciquantum/build.rb', line 48 def env_output out = output # clean_output out.size > 100_000 ? out[-100_000,100_000] : out end |
#failed? ⇒ Boolean
15 16 17 |
# File 'lib/ciquantum/build.rb', line 15 def failed? status == :failed end |
#id ⇒ Object
32 33 34 |
# File 'lib/ciquantum/build.rb', line 32 def id finished_at.to_i.to_s end |
#short_sha ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/ciquantum/build.rb', line 36 def short_sha if sha sha[0,7] else "<unknown>" end end |
#test_results ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ciquantum/build.rb', line 58 def test_results #rspec parse stat = { success: 0, failures:0, pending:0 } clean_output.gsub(/(\d+) examples?, (\d+) failures?(?:, (\d+) pending)?/) do stat[:success] += $1.to_i stat[:failures] += $2.to_i stat[:pending] += $3.to_i end #cucumber parse clean_output.gsub(/(\d+) scenarios \((?:(\d+) failed,?\s?)?(?:(\d+) undefined,?\s?)?(?:(\d+) passed)?\)/) do stat[:success] += $1.to_i stat[:failures] += $2.to_i stat[:pending] += $3.to_i end res = "#{stat[:success]} examples, #{stat[:failures]} failures" res += ", #{stat[:pending]} pending" if stat[:pending] > 0 res end |
#worked? ⇒ Boolean
19 20 21 |
# File 'lib/ciquantum/build.rb', line 19 def worked? status == :worked end |