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:
parent
a74b94c938
commit
3fa96de682
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
63
lib/travis/api/app/responders/atom.rb
Normal file
63
lib/travis/api/app/responders/atom.rb
Normal 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">
|
||||
<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>
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue
Block a user