Find all builds for commit if multiple pipelines

This commit is contained in:
Grzegorz Bizon 2016-06-22 08:53:05 +02:00
parent 2c3f3cb392
commit 8e66618749
2 changed files with 9 additions and 5 deletions

View file

@ -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,

View file

@ -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