Fetch last build if no branch specified.

This restores backwards compatibility with the current behaviour
rather than defaulting to master. Though the latter would probably
the right thing to do in the longer term.
This commit is contained in:
Mathias Meyer 2014-06-18 11:23:18 +02:00
parent 5081bb157f
commit a7f0a861cb

View File

@ -6,14 +6,14 @@ module Travis::Api::App::Responders
class Xml < Base class Xml < Base
TEMPLATE_ERB = ERB.new <<-EOF TEMPLATE_ERB = ERB.new <<-EOF
<Projects> <Projects>
<% @resource.each do |r| %> <% @resource.each do |repository| %>
<% next if r.last_completed_build(branch).nil? -%> <% next if build(repository).nil? -%>
<Project <Project
name="<%= r.slug %>" name="<%= r.slug %>"
activity="<%= ACTIVITY[r.last_completed_build(branch).state.to_sym] || ACTIVITY[:default] %>" activity="<%= ACTIVITY[build(repository).state.to_sym] || ACTIVITY[:default] %>"
lastBuildStatus="<%= STATUS[r.last_completed_build(branch).state.to_sym] || STATUS[:default] %>" lastBuildStatus="<%= STATUS[build(repository).state.to_sym] || STATUS[:default] %>"
lastBuildLabel="<%= r.last_completed_build(branch).try(:number) %>" lastBuildLabel="<%= build(repository).try(:number) %>"
lastBuildTime="<%= r.last_completed_build(branch).finished_at.try(:strftime, '%Y-%m-%dT%H:%M:%S.%L%z') %>" lastBuildTime="<%= build(repository).finished_at.try(:strftime, '%Y-%m-%dT%H:%M:%S.%L%z') %>"
webUrl="https://<%= Travis.config.client_domain %>/<%= r.slug %>" /> webUrl="https://<%= Travis.config.client_domain %>/<%= r.slug %>" />
<% end %> <% end %>
</Projects> </Projects>
@ -44,7 +44,15 @@ module Travis::Api::App::Responders
end end
def branch def branch
params[:branch].present? ? params[:branch] : 'master' params[:branch]
end
def build(repository)
if branch.present?
repository.last_complete_build(branch)
else
repository.last_build
end
end end
private private