Class: Git::Story::SemaphoreResponse

Inherits:
JSON::GenericObject
  • Object
show all
Defined in:
lib/git/story/semaphore.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get(url, debug: false) ⇒ Object



6
7
8
9
10
# File 'lib/git/story/semaphore.rb', line 6

def self.get(url, debug: false)
  data = open(url).read
  debug and STDERR.puts JSON.pretty_generate(JSON(data))
  JSON(data, object_class: self)
end

Instance Method Details

#building?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/git/story/semaphore.rb', line 27

def building?
  !started_at.nil?
end

#canceled?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/git/story/semaphore.rb', line 39

def canceled?
  result == 'canceled'
end

#duration(time = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/git/story/semaphore.rb', line 12

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_nameObject



55
56
57
# File 'lib/git/story/semaphore.rb', line 55

def entity_name
  branch_name || server_name
end

#entity_urlObject



51
52
53
# File 'lib/git/story/semaphore.rb', line 51

def entity_url
  server_html_url || build_url
end

#failed?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/git/story/semaphore.rb', line 35

def failed?
  result == 'failed'
end

#finished?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/git/story/semaphore.rb', line 43

def finished?
  finished_at.blank?
end

#passed?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/git/story/semaphore.rb', line 31

def passed?
  result == 'passed'
end

#pending?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/git/story/semaphore.rb', line 23

def pending?
  result == 'pending'
end

#sha1Object



47
48
49
# File 'lib/git/story/semaphore.rb', line 47

def sha1
  commit.id[0,10]
end

#to_sObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/git/story/semaphore.rb', line 59

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 <<
    "\n  Semaphore: #{entity_url}" <<
    "\n  Commit: #{commit.url}" <<
    "\n  Authored: #{(commit.author_name + ' <' + commit.author_email + ?>).bold} @#{commit.timestamp}"
end