Merge pull request #96 from BanzaiMan/gh82_atom_feed
Implement Atom feed
This commit is contained in:
commit
f45467530a
|
@ -18,6 +18,10 @@ class Travis::Api::App
|
||||||
def png?
|
def png?
|
||||||
request.accept =~ %r(image/png)
|
request.accept =~ %r(image/png)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def atom?
|
||||||
|
request.accept =~ %r(application/atom+xml)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Travis::Api::App
|
||||||
end
|
end
|
||||||
|
|
||||||
def responders(resource, options)
|
def responders(resource, options)
|
||||||
[:Json, :Image, :Xml, :Plain].map do |name|
|
[:Json, :Atom, :Image, :Xml, :Plain].map do |name|
|
||||||
Responders.const_get(name)
|
Responders.const_get(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ require 'travis/api/app'
|
||||||
class Travis::Api::App
|
class Travis::Api::App
|
||||||
class Middleware
|
class Middleware
|
||||||
class Rewrite < Middleware
|
class Rewrite < Middleware
|
||||||
FORMAT = %r(\.(json|xml|png|txt)$)
|
FORMAT = %r(\.(json|xml|png|txt|atom)$)
|
||||||
V1_REPO_URL = %r(^(/[^/]+/[^/]+(?:/builds(?:/[\d]+)?|/cc)?)$)
|
V1_REPO_URL = %r(^(/[^/]+/[^/]+(?:/builds(?:/[\d]+)?|/cc)?)$)
|
||||||
|
|
||||||
helpers :accept
|
helpers :accept
|
||||||
|
@ -56,6 +56,10 @@ class Travis::Api::App
|
||||||
env['travis.format'] == 'xml'
|
env['travis.format'] == 'xml'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def atom?
|
||||||
|
env['travis.format'] == 'atom'
|
||||||
|
end
|
||||||
|
|
||||||
def v1?
|
def v1?
|
||||||
accept_version == 'v1'
|
accept_version == 'v1'
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'travis/api/app'
|
||||||
|
|
||||||
class Travis::Api::App
|
class Travis::Api::App
|
||||||
module Responders
|
module Responders
|
||||||
|
autoload :Atom, 'travis/api/app/responders/atom'
|
||||||
autoload :Base, 'travis/api/app/responders/base'
|
autoload :Base, 'travis/api/app/responders/base'
|
||||||
autoload :Image, 'travis/api/app/responders/image'
|
autoload :Image, 'travis/api/app/responders/image'
|
||||||
autoload :Json, 'travis/api/app/responders/json'
|
autoload :Json, 'travis/api/app/responders/json'
|
||||||
|
|
60
lib/travis/api/app/responders/atom.rb
Normal file
60
lib/travis/api/app/responders/atom.rb
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
module Travis::Api::App::Responders
|
||||||
|
require 'date'
|
||||||
|
|
||||||
|
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><%= resource.first.repository.slug %> Builds</title>
|
||||||
|
<link href="<%= endpoint.url %>" type="application/atom+xml" rel = "self" />
|
||||||
|
<id>repo:<%= resource.first.repository.id %></id>
|
||||||
|
<rights>Copyright (c) <%= DateTime.now.strftime("%Y") %> Travis CI GmbH</rights>
|
||||||
|
<updated><%= DateTime.now.rfc3339 %></updated>
|
||||||
|
|
||||||
|
<% resource.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>repo:<%= build.repository.id %>:build:<%= build.id %></id>
|
||||||
|
<updated><%= ::DateTime.parse(build.updated_at.to_s).rfc3339 %></updated>
|
||||||
|
<summary type="html">
|
||||||
|
<p>
|
||||||
|
<%= build.commit.message.encode(:xml => :text) %> (<%= 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?
|
||||||
|
super && resource.is_a?(ActiveRecord::Relation) && resource.first.is_a?(Build)
|
||||||
|
end
|
||||||
|
|
||||||
|
def apply
|
||||||
|
super
|
||||||
|
|
||||||
|
ATOM_FEED_ERB.result(binding)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def content_type
|
||||||
|
'application/atom+xml;charset=utf-8'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -95,4 +95,20 @@ describe 'v1 repos' do
|
||||||
get('/svenfuchs/minimal.png?branch=foo,bar').should deliver_result_image_for('passing')
|
get('/svenfuchs/minimal.png?branch=foo,bar').should deliver_result_image_for('passing')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with "Accept: application/atom+xml" header' do
|
||||||
|
let(:headers) { { 'HTTP_ACCEPT' => 'application/atom+xml' } }
|
||||||
|
it 'GET /repositories/svenfuchs/minimal/builds' do
|
||||||
|
response = get '/repositories/svenfuchs/minimal/builds', {}, headers
|
||||||
|
response.content_type.should =~ /^application\/atom\+xml/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with .atom extension and "Accept: */*" header' do
|
||||||
|
let(:headers) { { 'HTTP_ACCEPT' => '*/*' } }
|
||||||
|
it 'GET /repositories/svenfuchs/minimal/builds.atom' do
|
||||||
|
response = get '/repositories/svenfuchs/minimal/builds.atom', {}, headers
|
||||||
|
response.content_type.should =~ /^application\/atom\+xml/
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -139,4 +139,20 @@ describe 'Repos' do
|
||||||
result.should deliver_result_image_for('passing')
|
result.should deliver_result_image_for('passing')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with "Accept: application/atom+xml" header' do
|
||||||
|
let(:headers) { { 'HTTP_ACCEPT' => 'application/atom+xml' } }
|
||||||
|
it 'GET /repositories/svenfuchs/minimal/builds' do
|
||||||
|
response = get '/repositories/svenfuchs/minimal/builds', {}, headers
|
||||||
|
response.content_type.should =~ /^application\/atom\+xml/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with .atom extension' do
|
||||||
|
let(:headers) { { 'HTTP_ACCEPT' => '*/*' } }
|
||||||
|
it 'GET /repositories/svenfuchs/minimal/builds.atom' do
|
||||||
|
response = get '/repositories/svenfuchs/minimal/builds.atom', {}, headers
|
||||||
|
response.content_type.should =~ /^application\/atom\+xml/
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,7 +22,8 @@ Gem::Specification.new do |s|
|
||||||
"Nick Schonning",
|
"Nick Schonning",
|
||||||
"Patrick Williams",
|
"Patrick Williams",
|
||||||
"James Dennes",
|
"James Dennes",
|
||||||
"Tim Carey-Smith"
|
"Tim Carey-Smith",
|
||||||
|
"Hiro Asari"
|
||||||
]
|
]
|
||||||
|
|
||||||
s.email = [
|
s.email = [
|
||||||
|
@ -135,6 +136,7 @@ Gem::Specification.new do |s|
|
||||||
"lib/travis/api/app/middleware/rewrite.rb",
|
"lib/travis/api/app/middleware/rewrite.rb",
|
||||||
"lib/travis/api/app/middleware/scope_check.rb",
|
"lib/travis/api/app/middleware/scope_check.rb",
|
||||||
"lib/travis/api/app/responders.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/base.rb",
|
||||||
"lib/travis/api/app/responders/image.rb",
|
"lib/travis/api/app/responders/image.rb",
|
||||||
"lib/travis/api/app/responders/json.rb",
|
"lib/travis/api/app/responders/json.rb",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user