diff --git a/Gemfile b/Gemfile index 6b5df9fd..2acc2f12 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 43304774..dbf4e81f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/lib/travis/api/app/endpoint/artifacts.rb b/lib/travis/api/app/endpoint/artifacts.rb index 88fae5a9..d5fbfc86 100644 --- a/lib/travis/api/app/endpoint/artifacts.rb +++ b/lib/travis/api/app/endpoint/artifacts.rb @@ -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 diff --git a/lib/travis/api/app/endpoint/branches.rb b/lib/travis/api/app/endpoint/branches.rb index 39d48606..ffe83a6f 100644 --- a/lib/travis/api/app/endpoint/branches.rb +++ b/lib/travis/api/app/endpoint/branches.rb @@ -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 diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index 911913cc..14566d9f 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -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 diff --git a/lib/travis/api/app/endpoint/hooks.rb b/lib/travis/api/app/endpoint/hooks.rb index b8dfbc50..1a4f2dcd 100644 --- a/lib/travis/api/app/endpoint/hooks.rb +++ b/lib/travis/api/app/endpoint/hooks.rb @@ -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 diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index 923da07f..8c2f21bb 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -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 diff --git a/lib/travis/api/app/endpoint/repositories.rb b/lib/travis/api/app/endpoint/repositories.rb index 90040db2..3053093d 100644 --- a/lib/travis/api/app/endpoint/repositories.rb +++ b/lib/travis/api/app/endpoint/repositories.rb @@ -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 diff --git a/lib/travis/api/app/endpoint/stats.rb b/lib/travis/api/app/endpoint/stats.rb index 51dfaac1..0301cb44 100644 --- a/lib/travis/api/app/endpoint/stats.rb +++ b/lib/travis/api/app/endpoint/stats.rb @@ -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 diff --git a/lib/travis/api/app/endpoint/workers.rb b/lib/travis/api/app/endpoint/workers.rb index 4c5c25f3..90516ac0 100644 --- a/lib/travis/api/app/endpoint/workers.rb +++ b/lib/travis/api/app/endpoint/workers.rb @@ -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