From 8e66618749613333c9201a6ffaf7fc67633cc055 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 22 Jun 2016 08:53:05 +0200 Subject: [PATCH] Find all builds for commit if multiple pipelines --- lib/api/builds.rb | 6 +++--- spec/requests/api/builds_spec.rb | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/api/builds.rb b/lib/api/builds.rb index 979328efe0e..33aa86999f5 100644 --- a/lib/api/builds.rb +++ b/lib/api/builds.rb @@ -33,10 +33,10 @@ module API get ':id/repository/commits/:sha/builds' do authorize_read_builds! - commit = user_project.pipelines.find_by_sha(params[:sha]) - return not_found! unless commit + pipelines = user_project.pipelines.where(sha: params[:sha]) + return not_found! if pipelines.empty? - builds = commit.builds.order('id DESC') + builds = user_project.builds.where(pipeline: pipelines).order('id DESC') builds = filter_builds(builds, params[:scope]) present paginate(builds), with: Entities::Build, diff --git a/spec/requests/api/builds_spec.rb b/spec/requests/api/builds_spec.rb index 2ab9d640269..e9948b0afa2 100644 --- a/spec/requests/api/builds_spec.rb +++ b/spec/requests/api/builds_spec.rb @@ -64,14 +64,18 @@ describe API::API, api: true do describe 'GET /projects/:id/repository/commits/:sha/builds' do before do - project.ensure_pipeline(pipeline.sha, 'master') - get api("/projects/#{project.id}/repository/commits/#{pipeline.sha}/builds", api_user) + create(:ci_pipeline, project: project, sha: project.commit.id) + create(:ci_build, pipeline: pipeline) + create(:ci_build) + + get api("/projects/#{project.id}/repository/commits/#{project.commit.id}/builds", api_user) end context 'authorized user' do it 'should return project builds for specific commit' do expect(response).to have_http_status(200) expect(json_response).to be_an Array + expect(json_response.size).to eq 2 end end