parent
d462e88909
commit
362b5d30bf
|
@ -1,6 +1,22 @@
|
||||||
module Travis::Api::App::Responders
|
module Travis::Api::App::Responders
|
||||||
|
# This XML responder is used if the resource is a Repository, or a collection
|
||||||
|
# of Repositories.
|
||||||
|
# It returns XML data conforming to Multiple Project Summary Reporting Standard,
|
||||||
|
# as explained in http://confluence.public.thoughtworks.org/display/CI/Multiple+Project+Summary+Reporting+Standard
|
||||||
class Xml < Base
|
class Xml < Base
|
||||||
TEMPLATE = File.read(__FILE__).split("__END__").last.strip
|
TEMPLATE_ERB = ERB.new <<-EOF
|
||||||
|
<Projects>
|
||||||
|
<% @resource.each do |r| %>
|
||||||
|
<Project
|
||||||
|
name="<%= r.slug %>"
|
||||||
|
activity="<%= ACTIVITY[r.last_build.state.to_sym] || ACTIVITY[:default] %>"
|
||||||
|
lastBuildStatus="<%= STATUS[r.last_build.state.to_sym] || STATUS[:default] %>"
|
||||||
|
lastBuildLabel="<%= r.last_build.try(:number) %>"
|
||||||
|
lastBuildTime="<%= r.last_build.finished_at.try(:strftime, '%Y-%m-%dT%H:%M:%S.%L%z') %>"
|
||||||
|
webUrl="<%= File.join("https://", Travis.config.client_domain, r.slug) %>" />
|
||||||
|
<% end %>
|
||||||
|
</Projects>
|
||||||
|
EOF
|
||||||
|
|
||||||
STATUS = {
|
STATUS = {
|
||||||
default: 'Unknown',
|
default: 'Unknown',
|
||||||
|
@ -16,13 +32,14 @@ module Travis::Api::App::Responders
|
||||||
}
|
}
|
||||||
|
|
||||||
def apply?
|
def apply?
|
||||||
super && resource.is_a?(Repository) && last_build
|
super && (single_repo?(resource) || repo_collection?(resource))
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply
|
def apply
|
||||||
super
|
super
|
||||||
|
|
||||||
TEMPLATE % data
|
@resource = resource.is_a?(Repository) ? [resource] : resource
|
||||||
|
TEMPLATE_ERB.result(binding)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -31,39 +48,12 @@ module Travis::Api::App::Responders
|
||||||
'application/xml;charset=utf-8'
|
'application/xml;charset=utf-8'
|
||||||
end
|
end
|
||||||
|
|
||||||
def data
|
def single_repo?(resource)
|
||||||
{
|
resource.is_a?(Repository) && (@last_build || resource.last_build)
|
||||||
name: resource.slug,
|
|
||||||
url: File.join("https://", Travis.config.client_domain, resource.slug),
|
|
||||||
activity: activity,
|
|
||||||
label: last_build.try(:number),
|
|
||||||
status: status,
|
|
||||||
time: last_build.finished_at.try(:strftime, '%Y-%m-%dT%H:%M:%S.%L%z')
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def status
|
def repo_collection?(resource)
|
||||||
STATUS[last_build.state.to_sym] || STATUS[:default]
|
resource.is_a?(ActiveRecord::Relation) && resource.first.is_a?(Repository)
|
||||||
end
|
|
||||||
|
|
||||||
def activity
|
|
||||||
ACTIVITY[last_build.state.to_sym] || ACTIVITY[:default]
|
|
||||||
end
|
|
||||||
|
|
||||||
def last_build
|
|
||||||
@last_build ||= resource.last_build
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
__END__
|
|
||||||
|
|
||||||
<Projects>
|
|
||||||
<Project
|
|
||||||
name="%{name}"
|
|
||||||
activity="%{activity}"
|
|
||||||
lastBuildStatus="%{status}"
|
|
||||||
lastBuildLabel="%{label}"
|
|
||||||
lastBuildTime="%{time}"
|
|
||||||
webUrl="%{url}" />
|
|
||||||
</Projects>
|
|
||||||
|
|
|
@ -87,9 +87,9 @@ describe 'Repos' do
|
||||||
response.should deliver_cc_xml_for(Repository.by_slug('svenfuchs/minimal').first)
|
response.should deliver_cc_xml_for(Repository.by_slug('svenfuchs/minimal').first)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not respond with cc.xml for /repos list' do
|
it 'respond with cc.xml for /repos list' do
|
||||||
response = get '/repos', {}, 'HTTP_ACCEPT' => 'application/xml; version=2'
|
response = get '/repos', {}, 'HTTP_ACCEPT' => 'application/xml; version=2'
|
||||||
response.status.should == 406
|
response.should deliver_cc_xml_for(Repository.timeline)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'responds with 404 when repo can\'t be found and format is png' do
|
it 'responds with 404 when repo can\'t be found and format is png' do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user