Merge pull request #132 from travis-ci/rkh-mustermann

Pull in Mustermann
This commit is contained in:
Konstantin Haase 2014-12-01 13:08:15 +01:00
commit fd104366ef
5 changed files with 29 additions and 10 deletions

View File

@ -36,7 +36,7 @@ GIT
GIT GIT
remote: git://github.com/travis-ci/travis-core.git remote: git://github.com/travis-ci/travis-core.git
revision: b4c4ae9beb6ba8d813491273dc75fa582ee719b0 revision: a5277a1f47a8615672607026239af49a217e2830
specs: specs:
travis-core (0.0.1) travis-core (0.0.1)
actionmailer (~> 3.2.19) actionmailer (~> 3.2.19)
@ -84,6 +84,7 @@ PATH
travis-api (0.0.1) travis-api (0.0.1)
backports (~> 2.5) backports (~> 2.5)
memcachier memcachier
mustermann (~> 0.4)
pg (~> 0.13.2) pg (~> 0.13.2)
rack-contrib (~> 1.1) rack-contrib (~> 1.1)
rack-ssl (~> 1.3, >= 1.3.3) rack-ssl (~> 1.3, >= 1.3.3)
@ -214,6 +215,8 @@ GEM
metaclass (~> 0.0.1) metaclass (~> 0.0.1)
multi_json (1.10.1) multi_json (1.10.1)
multipart-post (2.0.0) multipart-post (2.0.0)
mustermann (0.4.0)
tool (~> 0.2)
net-http-persistent (2.9.4) net-http-persistent (2.9.4)
net-http-pipeline (1.0.1) net-http-pipeline (1.0.1)
pg (0.13.2) pg (0.13.2)
@ -312,6 +315,7 @@ GEM
tilt (1.4.1) tilt (1.4.1)
timers (4.0.1) timers (4.0.1)
hitimes hitimes
tool (0.2.3)
travis-config (0.1.0) travis-config (0.1.0)
hashr (~> 0.0) hashr (~> 0.0)
treetop (1.4.15) treetop (1.4.15)

View File

@ -1,11 +1,13 @@
require 'travis/api/app' require 'travis/api/app'
require 'sinatra/base' require 'sinatra/base'
require 'mustermann'
class Travis::Api::App class Travis::Api::App
# Superclass for any endpoint and middleware. # Superclass for any endpoint and middleware.
# Pulls in relevant helpers and extensions. # Pulls in relevant helpers and extensions.
class Base < Sinatra::Base class Base < Sinatra::Base
register Extensions::SmartConstants register Extensions::SmartConstants
register Mustermann
error NotImplementedError do error NotImplementedError do
content_type :txt content_type :txt

View File

@ -3,6 +3,8 @@ require 'travis/api/app'
class Travis::Api::App class Travis::Api::App
class Endpoint class Endpoint
class Repos < Endpoint class Repos < Endpoint
set :pattern, capture: { id: /\d+/ }
# Endpoint for getting all repositories. # Endpoint for getting all repositories.
# #
# You can filter the repositories by adding parameters to the request. For example, you can get all repositories # You can filter the repositories by adding parameters to the request. For example, you can get all repositories
@ -18,14 +20,6 @@ class Travis::Api::App
end end
end end
# Retrieves repositories for a given owner.
get '/:owner_name' do
pass if params[:owner_name] =~ /^\d+$/ # so we don't capture '/:id'
prefer_follower do
respond_with service(:find_repos, params)
end
end
# Gets the repository with the given id. # Gets the repository with the given id.
# #
# ### Response # ### Response
@ -37,6 +31,13 @@ class Travis::Api::App
end end
end end
# Retrieves repositories for a given owner.
get '/:owner_name' do
prefer_follower do
respond_with service(:find_repos, params)
end
end
get '/:id/cc' do get '/:id/cc' do
respond_with service(:find_repo, params.merge(schema: 'cc')) respond_with service(:find_repo, params.merge(schema: 'cc'))
end end

View File

@ -1,5 +1,16 @@
require 'spec_helper' require 'spec_helper'
describe Travis::Api::App::Endpoint::Repos do describe Travis::Api::App::Endpoint::Repos do
it 'has to be tested' before do
described_class.get('/spec/match/:id') { "id" }
described_class.get('/spec/match/:name') { "name" }
end
it 'matches id with digits' do
get('/repos/spec/match/123').body.should be == "id"
end
it 'does not match id with non-digits' do
get('/repos/spec/match/f123').body.should be == "name"
end
end end

View File

@ -259,6 +259,7 @@ Gem::Specification.new do |s|
s.add_dependency 'thin', '~> 1.4' s.add_dependency 'thin', '~> 1.4'
s.add_dependency 'sinatra', '~> 1.3' s.add_dependency 'sinatra', '~> 1.3'
s.add_dependency 'sinatra-contrib', '~> 1.3' s.add_dependency 'sinatra-contrib', '~> 1.3'
s.add_dependency 'mustermann', '~> 0.4'
s.add_dependency 'redcarpet', '~> 2.1' s.add_dependency 'redcarpet', '~> 2.1'
s.add_dependency 'rack-ssl', '~> 1.3', '>= 1.3.3' s.add_dependency 'rack-ssl', '~> 1.3', '>= 1.3.3'
s.add_dependency 'rack-contrib', '~> 1.1' s.add_dependency 'rack-contrib', '~> 1.1'