From f2d768080f0228eaeb4390b094ff7ca099101b1d Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sat, 26 Jan 2013 01:12:42 +0100 Subject: [PATCH] Return last builds on each branch for /builds?branches=true This is a hack to fix travis-ci/travis-web#123 easier. A proper solution would be to refactor how /branches work. --- lib/travis/api/app/endpoint/builds.rb | 3 ++- spec/integration/v2/builds_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index fe7b21c4..3ef22141 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -4,7 +4,8 @@ class Travis::Api::App class Endpoint class Builds < Endpoint get '/' do - respond_with service(:find_builds, params) + name = params[:branches] ? :find_branches : :find_builds + respond_with service(name, params) end get '/:id' do diff --git a/spec/integration/v2/builds_spec.rb b/spec/integration/v2/builds_spec.rb index 4366a558..51eb82fb 100644 --- a/spec/integration/v2/builds_spec.rb +++ b/spec/integration/v2/builds_spec.rb @@ -29,4 +29,9 @@ describe 'Builds' do response = get "/repos/svenfuchs/minimal/builds/#{build.id}", {}, headers response.should deliver_json_for(build, version: 'v2') end + + it 'GET /builds/1?repository_id=1&branches=true' do + response = get "/builds?repository_id=#{repo.id}&branches=true", {}, headers + response.should deliver_json_for(repo.last_finished_builds_by_branches, version: 'v2') + end end