Commit 8e666187 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Find all builds for commit if multiple pipelines

parent 2c3f3cb3
...@@ -33,10 +33,10 @@ module API ...@@ -33,10 +33,10 @@ module API
get ':id/repository/commits/:sha/builds' do get ':id/repository/commits/:sha/builds' do
authorize_read_builds! authorize_read_builds!
commit = user_project.pipelines.find_by_sha(params[:sha]) pipelines = user_project.pipelines.where(sha: params[:sha])
return not_found! unless commit 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]) builds = filter_builds(builds, params[:scope])
present paginate(builds), with: Entities::Build, present paginate(builds), with: Entities::Build,
......
...@@ -64,14 +64,18 @@ describe API::API, api: true do ...@@ -64,14 +64,18 @@ describe API::API, api: true do
describe 'GET /projects/:id/repository/commits/:sha/builds' do describe 'GET /projects/:id/repository/commits/:sha/builds' do
before do before do
project.ensure_pipeline(pipeline.sha, 'master') create(:ci_pipeline, project: project, sha: project.commit.id)
get api("/projects/#{project.id}/repository/commits/#{pipeline.sha}/builds", api_user) create(:ci_build, pipeline: pipeline)
create(:ci_build)
get api("/projects/#{project.id}/repository/commits/#{project.commit.id}/builds", api_user)
end end
context 'authorized user' do context 'authorized user' do
it 'should return project builds for specific commit' do it 'should return project builds for specific commit' do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq 2
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment