Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F11708541
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/tommy.rb b/tommy.rb
index 6d00609..8a0b0f7 100644
--- a/tommy.rb
+++ b/tommy.rb
@@ -1,80 +1,79 @@
require 'sinatra'
require 'rest-client'
require 'active_support/all'
-require 'crack'
require 'hashie'
require 'erb'
HUDSON_URL = ENV['HUDSON_URL'] || 'http://username:password@my.hudsonurl.com'
# This class represents a defined or discrete hash for a Jenkins project.
class Project < Hashie::Dash
property :name
property :build_score
property :last_build_number
property :last_build_url
property :last_stable_build
property :health_report
property :last_complete_url
property :last_failed_url
property :colour
def self.parse_incoming_json(json)
returned_projects = []
projects = json['jobs']
projects.each do |project|
next if !project['buildable']
returned_projects << Project.new( :name => project['displayName'].gsub('-', ' '),
:build_score => project['healthReport'].first['score'].to_i,
:last_build_number => project['builds'].first['number'],
:last_build_url => (project['lastBuild'].blank? ? '' : project['lastBuild']['url']),
:last_stable_build => (project['lastStableBuild'].blank? ? '' : project['lastStableBuild']['number']),
:health_report => project['healthReport'].first['description'],
:last_complete_url => (project['lastCompletedBuild'].blank? ? '' : project['lastCompletedBuild']['url']),
:last_failed_url => (project['lastFailedBuild'].blank? ? '' : project['lastFailedBuild']['url'] ),
:colour => project['color'])
end
return returned_projects
end
def is_green?
self.last_stable_build == self.last_build_number
end
def is_building?
self.colour.include?('anime')
end
end
get '/' do
json = RestClient::Resource.new("#{HUDSON_URL}/api/json?depth=1")
- @projects = Project.parse_incoming_json(Crack::JSON.parse(json.get))
+ @projects = Project.parse_incoming_json(JSON.parse(json.get))
erb :index
end
helpers do
def css_for_project(project)
score = project.build_score
if project.is_green?
if score == 100
'best'
elsif score >= 80
'better'
elsif score >= 60
'good'
elsif score >= 40
'bad'
else
'worse'
end
elsif project.is_building?
'building'
else
'worst'
end
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Sep 15, 06:11 (22 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2983812
Default Alt Text
(2 KB)
Attached To
Mode
rTOMMY Tommy
Attached
Detach File
Event Timeline
Log In to Comment