WIP: Atom feed for /repos/:owner_name/:name/builds

See travis-ci/travis-core#82

TODO: Link to indivisual build.
TODO: Add specs.
TODO: Review `#apply?`
This commit is contained in:
Hiro Asari 2013-11-08 23:55:21 -05:00
parent a74b94c938
commit 3fa96de682
4 changed files with 68 additions and 2 deletions

View File

@ -49,7 +49,7 @@ class Travis::Api::App
end
def responders(resource, options)
[:Json, :Image, :Xml, :Plain].map do |name|
[:Atom, :Json, :Image, :Xml, :Plain].map do |name|
Responders.const_get(name)
end
end

View File

@ -2,6 +2,7 @@ require 'travis/api/app'
class Travis::Api::App
module Responders
autoload :Atom, 'travis/api/app/responders/atom'
autoload :Base, 'travis/api/app/responders/base'
autoload :Image, 'travis/api/app/responders/image'
autoload :Json, 'travis/api/app/responders/json'

View File

@ -0,0 +1,63 @@
module Travis::Api::App::Responders
require 'securerandom'
class Atom < Base
ATOM_FEED_ERB = ERB.new(File.read(__FILE__).split("__END__").last.strip)
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
__END__
<?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 %>" rel = "self" />
<id>urn:uuid:<%= SecureRandom.uuid %></id>
<updated><%= DateTime.now.strftime %></updated>
<% @builds.each do |build| %>
<entry>
<title><%= build.repository.slug %> Build #<%= build.number %></title>
<link href="" />
<id>urn:uuid:<%= SecureRandom.uuid %></id>
<updated><%= build.finished_at || build.started_at %></updated>
<summary type="html">
&lt;p&gt;
<%= build.commit.message %> (<%= build.commit.committer_name %>)
&lt;br/&gt;&lt;br/&gt;
State: <%= build.state %>
&lt;br/&gt;
Started at: <%= build.started_at ? build.started_at : 'not started' %>
&lt;br/&gt;
Finished at: <%= build.finished_at ? build.finished_at :
build.started_at ? 'still running' : 'not started' %>
&lt;/p&gt;
</summary>
<author>
<name><%= build.commit.committer_name %></name>
</author>
</entry>
<% end %>
</feed>

View File

@ -22,7 +22,8 @@ Gem::Specification.new do |s|
"Nick Schonning",
"Patrick Williams",
"James Dennes",
"Tim Carey-Smith"
"Tim Carey-Smith",
"Hiro Asari"
]
s.email = [
@ -135,6 +136,7 @@ Gem::Specification.new do |s|
"lib/travis/api/app/middleware/rewrite.rb",
"lib/travis/api/app/middleware/scope_check.rb",
"lib/travis/api/app/responders.rb",
"lib/travis/api/app/responders/atom.rb",
"lib/travis/api/app/responders/base.rb",
"lib/travis/api/app/responders/image.rb",
"lib/travis/api/app/responders/json.rb",