
Currently, there is no easy way to grab this information from the Build model. So we need to construct it from various parts at our disposal.
64 lines
1.7 KiB
Ruby
64 lines
1.7 KiB
Ruby
module Travis::Api::App::Responders
|
|
require 'securerandom'
|
|
|
|
class Atom < Base
|
|
ATOM_FEED_ERB = ERB.new <<-EOF
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
|
|
|
<title><%= @builds.first.repository.slug %> Builds</title>
|
|
<link href="<%= endpoint.url %>" type="application/atom+xml" rel = "self" />
|
|
<id>urn:uuid:<%= SecureRandom.uuid %></id>
|
|
<rights>Copyright (c) <%= DateTime.now.strftime("%Y") %> Travis CI GmbH</rights>
|
|
<updated><%= DateTime.now.strftime %></updated>
|
|
|
|
<% @builds.each do |build| %>
|
|
<entry>
|
|
<title><%= build.repository.slug %> Build #<%= build.number %></title>
|
|
<link href="<%= File.join("https://", Travis.config.host, build.repository.slug, "builds", build.id.to_s) %>" />
|
|
<id>urn:uuid:<%= SecureRandom.uuid %></id>
|
|
<updated><%= build.finished_at || build.started_at %></updated>
|
|
<summary type="html">
|
|
<p>
|
|
<%= build.commit.message %> (<%= build.commit.committer_name %>)
|
|
<br/><br/>
|
|
State: <%= build.state %>
|
|
<br/>
|
|
Started at: <%= build.started_at ? build.started_at : 'not started' %>
|
|
<br/>
|
|
Finished at: <%= build.finished_at ? build.finished_at :
|
|
build.started_at ? 'still running' : 'not started' %>
|
|
</p>
|
|
</summary>
|
|
<author>
|
|
<name><%= build.commit.committer_name %></name>
|
|
</author>
|
|
</entry>
|
|
<% end %>
|
|
|
|
</feed>
|
|
EOF
|
|
|
|
def apply?
|
|
if resource.is_a?(ActiveRecord::Relation) && resource.first.is_a?(Build)
|
|
@builds = resource
|
|
end
|
|
super && @builds
|
|
end
|
|
|
|
def apply
|
|
super
|
|
|
|
ATOM_FEED_ERB.result(binding)
|
|
end
|
|
|
|
private
|
|
|
|
def content_type
|
|
'application/atom+xml;charset=utf-8'
|
|
end
|
|
|
|
end
|
|
end
|