use services

This commit is contained in:
Sven Fuchs 2012-09-14 21:48:22 +02:00
parent f05f841a46
commit 1fdcec33a4
10 changed files with 35 additions and 47 deletions

View File

@ -4,7 +4,7 @@ source :rubygems
gemspec
gem 'travis-support', github: 'travis-ci/travis-support'
gem 'travis-core', github: 'travis-ci/travis-core'
gem 'travis-core', github: 'travis-ci/travis-core', branch: 'sf-moar-services'
gem 'hubble', github: 'roidrage/hubble'
gem 'yard-sinatra', github: 'rkh/yard-sinatra'
gem 'gh', github: 'rkh/gh'

View File

@ -32,7 +32,8 @@ GIT
GIT
remote: git://github.com/travis-ci/travis-core.git
revision: b71c3be388451581f2ca60e6fd862c2bfc56bfb6
revision: db8c123f2e2a35a8983f10c6524ccbab96f27ba7
branch: sf-moar-services
specs:
travis-core (0.0.1)
actionmailer (~> 3.2.3)
@ -105,7 +106,7 @@ GEM
atomic (1.0.1)
avl_tree (1.1.3)
backports (2.6.2)
builder (3.0.0)
builder (3.0.3)
daemons (1.1.8)
data_migrations (0.0.1)
activerecord
@ -120,7 +121,7 @@ GEM
ffi (1.1.0)
foreman (0.53.0)
thor (>= 0.13.6)
hashr (0.0.21)
hashr (0.0.22)
hike (1.2.1)
hitimes (1.1.1)
i18n (0.6.0)
@ -196,7 +197,7 @@ GEM
rspec-expectations (2.11.2)
diff-lcs (~> 1.1.3)
rspec-mocks (2.11.1)
signature (0.1.3)
signature (0.1.4)
simple_states (0.1.1)
activesupport
hashr (~> 0.0.10)

View File

@ -5,7 +5,9 @@ class Travis::Api::App
# TODO: Add documentation.
class Artifacts < Endpoint
# TODO: Add documentation.
get('/:id') { |id| body Artifact.find(id) }
get('/:id') do |id|
service(:artifacts).find_one(params)
end
end
end
end

View File

@ -6,15 +6,8 @@ class Travis::Api::App
class Branches < Endpoint
# TODO: Add documentation.
get('/') do
body repository, :type => "Branches"
body service(:branches).find_all(params)
end
private
def repository
pass if params.empty?
Repository.find_by(params) || not_found
end
end
end
end

View File

@ -6,23 +6,13 @@ class Travis::Api::App
class Builds < Endpoint
# TODO: Add documentation.
get '/' do
scope = repository.builds.by_event_type(params[:event_type] || 'push')
scope = params[:after] ? scope.older_than(params[:after]) : scope.recent
scope
service(:builds).find_all(params)
end
# TODO: Add documentation.
get '/:id' do
one = params[:repository_id] ? repository.builds : Build
body one.includes(:commit, :matrix => [:commit, :log]).find(params[:id])
service(:builds).find_one(params)
end
private
def repository
pass if params.empty?
Repository.find_by(params) || not_found
end
end
end
end

View File

@ -5,10 +5,14 @@ class Travis::Api::App
# TODO: Add documentation.
class Hooks < Endpoint
# TODO: Add implementation and documentation.
get('/', scope: :private) { raise NotImplementedError }
get('/', scope: :private) do
service(:builds).find_all(params)
end
# TODO: Add implementation and documentation.
put('/:id', scope: :admin) { raise NotImplementedError }
put('/:id', scope: :admin) do
respond_with service(:hooks).update(params)
end
end
end
end

View File

@ -4,20 +4,14 @@ class Travis::Api::App
class Endpoint
# TODO: Add documentation.
class Jobs < Endpoint
# TODO: Add implementation and documentation.
# TODO: Add documentation.
get('/') do
if params[:ids]
Job.where(:id => params[:ids]).includes(:commit, :log)
else
jobs = Job.queued.includes(:commit, :log)
jobs = jobs.where(:queue => params[:queue]) if params[:queue]
jobs
end
service(:jobs).find_all(params)
end
# TODO: Add implementation and documentation.
# TODO: Add documentation.
get('/:id') do
body Job.find(params[:id])
service(:jobs).find_one(params)
end
end
end

View File

@ -6,15 +6,17 @@ class Travis::Api::App
class Repositories < Endpoint
# TODO: Add documentation.
get '/' do
scope = Repository.timeline.recent
scope = scope.by_owner_name(params[:owner_name]) if params[:owner_name]
scope = scope.by_slug(params[:slug]) if params[:slug]
scope = scope.search(params[:search]) if params[:search].present?
scope
body service(:repositories).find_all(params)
end
# TODO: Add documentation.
get('/:id') { body Repository.find_by(params) }
get('/:id') do
body service(:repositories).find_one(params)
end
# TODO make sure status images and cc.xml work
# rescue ActiveRecord::RecordNotFound
# raise unless params[:format] == 'png'
end
end
end

View File

@ -6,12 +6,12 @@ class Travis::Api::App
class Stats < Endpoint
# TODO: Add documentation.
get('/repos') do
{ :stats => Travis::Stats.daily_repository_counts }
{ :stats => services(:stats).daily_repository_counts }
end
# TODO: Add documentation.
get('/tests') do
{ :stats => Travis::Stats.daily_tests_counts }
{ :stats => services(:stats).daily_tests_counts }
end
end
end

View File

@ -5,7 +5,9 @@ class Travis::Api::App
# TODO: Add documentation.
class Workers < Endpoint
# TODO: Add implementation and documentation.
get('/') { Worker.order(:host, :name) }
get('/') do
service(:workers).find_all(params)
end
end
end
end