forked from customink/stoplight
/
travis.rb
64 lines (55 loc) · 1.83 KB
/
travis.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#
# Stoplight Provider for Travis CI (http://travis-ci.org)
#
# Travis does not conform to the multi-project reporting spec, so
# we need to define our own provider
#
module Stoplight::Providers
class Travis < Provider
def provider
'travis'
end
def builds_path
@options['builds_path'] ||= 'repositories.json'
end
def projects
if @response.nil? || @response.parsed_response.nil?
@projects ||= []
else
@projects ||= @response.parsed_response.collect do |project|
project = Stoplight::Project.new({
:name => project['slug'].split(/\//).last,
:build_url => "#{options['url']}/#{project['slug']}",
:last_build_id => project['last_build_number'].to_s,
:last_build_time => project['last_build_finished_at'],
:last_build_status => status_to_int(project['last_build_status']),
:current_status => current_status_to_int(project['last_build_finished_at']),
:culprits => @options['culprits'] ? get_culprits(project['slug']) : []
})
end
end
end
private
def status_to_int(status)
status || -1
end
def current_status_to_int(status)
return 1 if status.nil? # building
begin
DateTime.parse(status)
0
rescue ArgumentError
-1
end
end
def get_culprits(slug)
response = load_server_data(:path => "/#{slug}/builds.json")
return [] if !response.parsed_response.is_a?(Array) || response.parsed_response.first.nil?
culprits = response.parsed_response.first['matrix'].collect do |commit|
hash = Digest::MD5.hexdigest(commit['author_email'].downcase)
{ 'user' => commit['author_name'], 'gravatar' => "http://www.gravatar.com/avatar/#{hash}.jpg" }
end
culprits.uniq
end
end
end