From 0cdafcc9c0a4de566195ba9bef889946e09e7fa8 Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Wed, 12 Nov 2014 22:06:08 -0500 Subject: [PATCH 1/3] Add spec for /repos/*/branches endpoint --- spec/integration/v2/repositories_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/integration/v2/repositories_spec.rb b/spec/integration/v2/repositories_spec.rb index e40518e2..6989f72a 100644 --- a/spec/integration/v2/repositories_spec.rb +++ b/spec/integration/v2/repositories_spec.rb @@ -134,6 +134,16 @@ describe 'Repos' do JSON.parse(result.body).should == { 'file' => 'not found' } end + it 'GET /repos/svenfuchs/minimal/branches' do + response = get '/repos/svenfuchs/minimal/branches', {}, headers + response.should deliver_json_for(repo.last_finished_builds_by_branches, version: 'v2', type: 'branches') + end + + it 'GET /repos/1/branches' do + response = get "/repos/#{repo.id}/branches", {}, headers + response.should deliver_json_for(repo.last_finished_builds_by_branches, version: 'v2', type: 'branches') + end + describe 'GET /repos/svenfuchs/minimal.png?branch=foo,bar' do let(:on_foo) { Factory(:commit, branch: 'foo') } let(:on_bar) { Factory(:commit, branch: 'bar') } From e45aa12d9736d48675b7965813750bb8b489c2b3 Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Wed, 12 Nov 2014 22:47:08 -0500 Subject: [PATCH 2/3] Add spec for /repos/*/branches/* endpoint --- spec/integration/v2/repositories_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/integration/v2/repositories_spec.rb b/spec/integration/v2/repositories_spec.rb index 6989f72a..86792000 100644 --- a/spec/integration/v2/repositories_spec.rb +++ b/spec/integration/v2/repositories_spec.rb @@ -144,6 +144,13 @@ describe 'Repos' do response.should deliver_json_for(repo.last_finished_builds_by_branches, version: 'v2', type: 'branches') end + it 'GET /repos/svenfuchs/minimal/branches/mybranch' do + mybuild = Factory(:build, repository: repo, state: :started, commit: Factory(:commit, branch: 'mybranch'), request: Factory(:request, event_type: 'push')) + response = get "/repos/svenfuchs/minimal/branches/mybranch", {}, headers + body = JSON.parse(response.body) + body['branch']['id'].should == mybuild.id + end + describe 'GET /repos/svenfuchs/minimal.png?branch=foo,bar' do let(:on_foo) { Factory(:commit, branch: 'foo') } let(:on_bar) { Factory(:commit, branch: 'bar') } From 7ba84757dc3121967ac16c1221d09375747f2b1c Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Wed, 12 Nov 2014 16:40:20 -0500 Subject: [PATCH 3/3] Allow branch names to contain slashes Fixes: #145 --- lib/travis/api/app/endpoint/repos.rb | 10 ++++++---- spec/integration/v2/repositories_spec.rb | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/travis/api/app/endpoint/repos.rb b/lib/travis/api/app/endpoint/repos.rb index 1e52b7d0..14203d15 100644 --- a/lib/travis/api/app/endpoint/repos.rb +++ b/lib/travis/api/app/endpoint/repos.rb @@ -97,8 +97,9 @@ class Travis::Api::App respond_with service(:find_branches, params), type: :branches, version: :v2 end - # Gets lastest build on a branch branches - get '/:repository_id/branches/:branch' do + # Gets latest build on a branch + get '/:repository_id/branches/*' do + params[:branch] = params[:splat] respond_with service(:find_branch, params), type: :branch, version: :v2 end @@ -169,8 +170,9 @@ class Travis::Api::App respond_with service(:find_branches, params), type: :branches, version: :v2 end - # Gets lastest build on a branch branches - get '/:owner_name/:name/branches/:branch' do + # Gets latest build on a branch + get '/:owner_name/:name/branches/*' do + params[:branch] = params[:splat] respond_with service(:find_branch, params), type: :branch, version: :v2 end diff --git a/spec/integration/v2/repositories_spec.rb b/spec/integration/v2/repositories_spec.rb index 86792000..dfa86220 100644 --- a/spec/integration/v2/repositories_spec.rb +++ b/spec/integration/v2/repositories_spec.rb @@ -151,6 +151,13 @@ describe 'Repos' do body['branch']['id'].should == mybuild.id end + it 'GET /repos/svenfuchs/minimal/branches/my/branch' do + mybuild = Factory(:build, repository: repo, state: :started, commit: Factory(:commit, branch: 'my/branch'), request: Factory(:request, event_type: 'push')) + response = get "/repos/svenfuchs/minimal/branches/my/branch", {}, headers + body = JSON.parse(response.body) + body['branch']['id'].should == mybuild.id + end + describe 'GET /repos/svenfuchs/minimal.png?branch=foo,bar' do let(:on_foo) { Factory(:commit, branch: 'foo') } let(:on_bar) { Factory(:commit, branch: 'bar') }