Class: Git::Story::SemaphoreResponse
- Inherits:
-
JSON::GenericObject
- Object
- JSON::GenericObject
- Git::Story::SemaphoreResponse
- Defined in:
- lib/git/story/semaphore.rb
Class Method Summary collapse
Instance Method Summary collapse
- #branch_history ⇒ Object
- #building? ⇒ Boolean
- #canceled? ⇒ Boolean
- #duration(time = nil) ⇒ Object
- #entity_name ⇒ Object
- #entity_url ⇒ Object
- #estimated_duration ⇒ Object
- #failed? ⇒ Boolean
- #finished? ⇒ Boolean
- #passed? ⇒ Boolean
- #pending? ⇒ Boolean
- #sha1 ⇒ Object
- #to_s ⇒ Object
Class Method Details
.get(url, debug: false) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/git/story/semaphore.rb', line 7 def self.get(url, debug: false) data = open(url).read debug and STDERR.puts JSON.pretty_generate(JSON(data)) result = JSON(data, object_class: self) result.debug = debug result end |
Instance Method Details
#branch_history ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/git/story/semaphore.rb', line 62 def branch_history if branch_history_url self.class.get(branch_history_url, debug: debug)&.builds else [] end end |
#building? ⇒ Boolean
30 31 32 |
# File 'lib/git/story/semaphore.rb', line 30 def building? !started_at.nil? end |
#canceled? ⇒ Boolean
42 43 44 |
# File 'lib/git/story/semaphore.rb', line 42 def canceled? result == 'canceled' end |
#duration(time = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/git/story/semaphore.rb', line 15 def duration(time = nil) unless time if finished_at.nil? time = Time.now else time = Time.parse(finished_at) end end Tins::Duration.new(time - Time.parse(started_at)) end |
#entity_name ⇒ Object
58 59 60 |
# File 'lib/git/story/semaphore.rb', line 58 def entity_name branch_name || server_name end |
#entity_url ⇒ Object
54 55 56 |
# File 'lib/git/story/semaphore.rb', line 54 def entity_url server_html_url || build_url end |
#estimated_duration ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/git/story/semaphore.rb', line 70 def estimated_duration times = branch_history.select { |b| b.result == 'passed' }.map { |b| Time.parse(b.finished_at) - Time.parse(b.started_at) } if times.empty? duration else times.sum / times.size end.to_f end |
#failed? ⇒ Boolean
38 39 40 |
# File 'lib/git/story/semaphore.rb', line 38 def failed? result == 'failed' end |
#finished? ⇒ Boolean
46 47 48 |
# File 'lib/git/story/semaphore.rb', line 46 def finished? finished_at.blank? end |
#passed? ⇒ Boolean
34 35 36 |
# File 'lib/git/story/semaphore.rb', line 34 def passed? result == 'passed' end |
#pending? ⇒ Boolean
26 27 28 |
# File 'lib/git/story/semaphore.rb', line 26 def pending? result == 'pending' end |
#sha1 ⇒ Object
50 51 52 |
# File 'lib/git/story/semaphore.rb', line 50 def sha1 commit.id[0,10] end |
#to_s ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/git/story/semaphore.rb', line 81 def to_s r = case when pending? && building? "#{entity_name} ##{sha1} building for #{duration(Time.now)}".yellow.bold when pending? "#{entity_name} ##{sha1} pending at the moment".yellow when passed? "#{entity_name} ##{sha1} passed after #{duration}".green when failed? "#{entity_name} ##{sha1} failed after #{duration}".red else "#{entity_name} ##{sha1} in state #{result}".blue end r = StringIO.new(r) Infobar( current: duration.to_f.to_i, total: estimated_duration.to_i, message: ' %l %c/%t seconds ', output: r ).update r << "\n Semaphore: #{entity_url}" << "\n Commit: #{commit.url}" << "\n Authored: #{(commit. + ' <' + commit. + ?>).bold} @#{commit.}" r.tap(&:rewind).read end |