Add requests API
Requests API allows to get the requests from the DB and thus enable users to have more insight into what's going on in their repositories.
This commit is contained in:
parent
4d1b415d7b
commit
093831c1a2
44
Gemfile.lock
44
Gemfile.lock
|
@ -23,7 +23,7 @@ GIT
|
|||
|
||||
GIT
|
||||
remote: git://github.com/travis-ci/travis-core.git
|
||||
revision: 183d8f10c78eaf0fc08fe24fb3fcc0445ddd96e1
|
||||
revision: a17a9b90adb5567c7d6ef6e5bb796018a1b371c0
|
||||
specs:
|
||||
travis-core (0.0.1)
|
||||
actionmailer (~> 3.2.12)
|
||||
|
@ -83,12 +83,12 @@ PATH
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
actionmailer (3.2.16)
|
||||
actionpack (= 3.2.16)
|
||||
actionmailer (3.2.17)
|
||||
actionpack (= 3.2.17)
|
||||
mail (~> 2.5.4)
|
||||
actionpack (3.2.16)
|
||||
activemodel (= 3.2.16)
|
||||
activesupport (= 3.2.16)
|
||||
actionpack (3.2.17)
|
||||
activemodel (= 3.2.17)
|
||||
activesupport (= 3.2.17)
|
||||
builder (~> 3.0.0)
|
||||
erubis (~> 2.7.0)
|
||||
journey (~> 1.0.4)
|
||||
|
@ -96,20 +96,20 @@ GEM
|
|||
rack-cache (~> 1.2)
|
||||
rack-test (~> 0.6.1)
|
||||
sprockets (~> 2.2.1)
|
||||
activemodel (3.2.16)
|
||||
activesupport (= 3.2.16)
|
||||
activemodel (3.2.17)
|
||||
activesupport (= 3.2.17)
|
||||
builder (~> 3.0.0)
|
||||
activerecord (3.2.16)
|
||||
activemodel (= 3.2.16)
|
||||
activesupport (= 3.2.16)
|
||||
activerecord (3.2.17)
|
||||
activemodel (= 3.2.17)
|
||||
activesupport (= 3.2.17)
|
||||
arel (~> 3.0.2)
|
||||
tzinfo (~> 0.3.29)
|
||||
activesupport (3.2.16)
|
||||
activesupport (3.2.17)
|
||||
i18n (~> 0.6, >= 0.6.4)
|
||||
multi_json (~> 1.0)
|
||||
addressable (2.3.5)
|
||||
arel (3.0.3)
|
||||
atomic (1.1.14)
|
||||
atomic (1.1.15)
|
||||
avl_tree (1.1.3)
|
||||
backports (2.8.2)
|
||||
builder (3.0.4)
|
||||
|
@ -171,13 +171,13 @@ GEM
|
|||
mime-types (1.25.1)
|
||||
mocha (0.14.0)
|
||||
metaclass (~> 0.0.1)
|
||||
multi_json (1.8.4)
|
||||
multi_json (1.9.0)
|
||||
multipart-post (2.0.0)
|
||||
net-http-persistent (2.9)
|
||||
net-http-persistent (2.9.4)
|
||||
net-http-pipeline (1.0.1)
|
||||
newrelic_rpm (3.6.9.171)
|
||||
pg (0.13.2)
|
||||
polyglot (0.3.3)
|
||||
polyglot (0.3.4)
|
||||
proxies (0.2.1)
|
||||
pry (0.9.12.4)
|
||||
coderay (~> 1.0)
|
||||
|
@ -197,9 +197,9 @@ GEM
|
|||
rack
|
||||
rack-test (0.6.2)
|
||||
rack (>= 1.0)
|
||||
railties (3.2.16)
|
||||
actionpack (= 3.2.16)
|
||||
activesupport (= 3.2.16)
|
||||
railties (3.2.17)
|
||||
actionpack (= 3.2.17)
|
||||
activesupport (= 3.2.17)
|
||||
rack-ssl (~> 1.3.2)
|
||||
rake (>= 0.8.7)
|
||||
rdoc (~> 3.4)
|
||||
|
@ -214,7 +214,7 @@ GEM
|
|||
rdoc (3.12.2)
|
||||
json (~> 1.4)
|
||||
redcarpet (2.3.0)
|
||||
redis (3.0.6)
|
||||
redis (3.0.7)
|
||||
redis-namespace (1.3.2)
|
||||
redis (~> 3.0.4)
|
||||
rerun (0.8.2)
|
||||
|
@ -228,7 +228,7 @@ GEM
|
|||
rspec-expectations (2.14.4)
|
||||
diff-lcs (>= 1.1.3, < 2.0)
|
||||
rspec-mocks (2.14.4)
|
||||
s3 (0.3.18)
|
||||
s3 (0.3.21)
|
||||
proxies (~> 0.2.0)
|
||||
sidekiq (2.5.4)
|
||||
celluloid (~> 0.12.0)
|
||||
|
@ -237,7 +237,7 @@ GEM
|
|||
redis (~> 3)
|
||||
redis-namespace
|
||||
signature (0.1.7)
|
||||
simple_states (1.0.0)
|
||||
simple_states (1.0.1)
|
||||
activesupport
|
||||
hashr (~> 0.0.10)
|
||||
sinatra (1.4.4)
|
||||
|
|
|
@ -17,7 +17,17 @@ class Travis::Api::App
|
|||
after { content_type :json unless content_type }
|
||||
|
||||
error(ActiveRecord::RecordNotFound, Sinatra::NotFound) { not_found }
|
||||
not_found { content_type =~ /json/ ? { 'file' => 'not found' } : 'file not found' }
|
||||
not_found {
|
||||
if content_type =~ /json/
|
||||
if body && !body.empty?
|
||||
body
|
||||
else
|
||||
{ 'file' => 'not found' }
|
||||
end
|
||||
else
|
||||
'file not found'
|
||||
end
|
||||
}
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -8,6 +8,15 @@ class Travis::Api::App
|
|||
Metriks.meter("api.request.restart").mark
|
||||
respond_with service(:reset_model, params)
|
||||
end
|
||||
|
||||
get '/' do
|
||||
begin
|
||||
respond_with(service(:find_requests, params).run)
|
||||
rescue Travis::RepositoryNotFoundError => e
|
||||
status 404
|
||||
{ "error" => "Repository could not be found" }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
18
spec/integration/v2/requests_spec.rb
Normal file
18
spec/integration/v2/requests_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Requests' do
|
||||
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } }
|
||||
|
||||
it 'fetches requests' do
|
||||
repo = Factory.create(:repository)
|
||||
request = Factory.create(:request, repository: repo)
|
||||
|
||||
response = get '/requests', { repository_id: repo.id }, headers
|
||||
response.should deliver_json_for(repo.requests, version: 'v2', type: 'requests')
|
||||
end
|
||||
|
||||
it 'returns an error response if repo can\'t be found' do
|
||||
response = get '/requests', { repository_id: 0 }, headers
|
||||
JSON.parse(response.body)['error'].should == "Repository could not be found"
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user