Class: Chicanery::Cctray::Server

Inherits:
Site
  • Object
show all
Defined in:
lib/chicanery/cctray.rb

Instance Attribute Summary

Attributes inherited from Site

#body, #code, #duration, #name, #options, #uri

Instance Method Summary collapse

Methods inherited from Site

#get, #initialize, #path

Constructor Details

This class inherits a constructor from Chicanery::Site

Instance Method Details

#filtered(name) ⇒ Object



50
51
52
53
# File 'lib/chicanery/cctray.rb', line 50

def filtered name
  return false unless options[:include]
  !options[:include].match(name)
end

#jobsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/chicanery/cctray.rb', line 16

def jobs
  jobs = {}
  response_body = get
  File.open("#{Time.now.to_i}.xml", 'w') {|f| f.puts response_body} if ENV['CHICANERY_CAPTURE']
  Nokogiri::XML(response_body).css("Project").each do |project|
    job = {
      activity: project[:activity] == 'Sleeping' ? :sleeping : :building,
      last_build_status: parse_build_status(project[:lastBuildStatus]),
      last_build_time: parse_build_time(project[:lastBuildTime]),
      url: project[:webUrl],
      last_label: project[:lastBuildLabel]
    }
    project.css('message').each do |message|
      job[:breaker] = message[:text] if message[:kind] == 'Breakers'
    end
    jobs[project[:name]] = job unless filtered project[:name]
  end
  raise "could not find any jobs in response: [#{response_body}]" if jobs.empty?
  jobs
end

#parse_build_status(status) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/chicanery/cctray.rb', line 42

def parse_build_status status
  case status
  when /^Success/ then :success
  when /^Unknown/ then :unknown
  else :failure
  end
end

#parse_build_time(time) ⇒ Object



37
38
39
40
# File 'lib/chicanery/cctray.rb', line 37

def parse_build_time time
  return 0 if time.nil? || time.empty? || time == '0'
  DateTime.parse(time).to_time.to_i
end