diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-06-27 14:08:40 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-06-27 21:08:31 +0200 |
commit | 6afff7c6073f58caf590dee5dadd84996a69f1ef (patch) | |
tree | 66ee9eb72f602ff193be9bdab9c5ed52facda98a | |
parent | 99bdfd189bc9728444923b93fdd839ebe2b24eb5 (diff) | |
download | gitlab-ce-6afff7c6073f58caf590dee5dadd84996a69f1ef.tar.gz |
Fix head pipeline stored in merge request for external pipelinesfix-head-pipeline-for-commit-status
-rw-r--r-- | changelogs/unreleased/fix-head-pipeline-for-external-pipelines.md | 4 | ||||
-rw-r--r-- | lib/api/commit_statuses.rb | 3 | ||||
-rw-r--r-- | spec/requests/api/commit_statuses_spec.rb | 27 |
3 files changed, 28 insertions, 6 deletions
diff --git a/changelogs/unreleased/fix-head-pipeline-for-external-pipelines.md b/changelogs/unreleased/fix-head-pipeline-for-external-pipelines.md new file mode 100644 index 00000000000..bf667464e60 --- /dev/null +++ b/changelogs/unreleased/fix-head-pipeline-for-external-pipelines.md @@ -0,0 +1,4 @@ +--- +title: Fix head pipeline stored in merge request for external pipelines +merge_request: +author: diff --git a/lib/api/commit_statuses.rb b/lib/api/commit_statuses.rb index 10f2d5ef6a3..485b680cd5f 100644 --- a/lib/api/commit_statuses.rb +++ b/lib/api/commit_statuses.rb @@ -108,6 +108,9 @@ module API render_api_error!('invalid state', 400) end + MergeRequest.where(source_project: @project, source_branch: ref) + .update_all(head_pipeline_id: pipeline) if pipeline.latest? + present status, with: Entities::CommitStatus rescue StateMachines::InvalidTransition => e render_api_error!(e.message, 400) diff --git a/spec/requests/api/commit_statuses_spec.rb b/spec/requests/api/commit_statuses_spec.rb index b8ca73c321c..cdb60fc0d1a 100644 --- a/spec/requests/api/commit_statuses_spec.rb +++ b/spec/requests/api/commit_statuses_spec.rb @@ -164,25 +164,40 @@ describe API::CommitStatuses do context 'with all optional parameters' do context 'when creating a commit status' do - it 'creates commit status' do + subject do post api(post_url, developer), { state: 'success', context: 'coverage', - ref: 'develop', + ref: 'master', description: 'test', coverage: 80.0, target_url: 'http://gitlab.com/status' } + end + + it 'creates commit status' do + subject expect(response).to have_http_status(201) expect(json_response['sha']).to eq(commit.id) expect(json_response['status']).to eq('success') expect(json_response['name']).to eq('coverage') - expect(json_response['ref']).to eq('develop') + expect(json_response['ref']).to eq('master') expect(json_response['coverage']).to eq(80.0) expect(json_response['description']).to eq('test') expect(json_response['target_url']).to eq('http://gitlab.com/status') end + + context 'when merge request exists for given branch' do + let!(:merge_request) { create(:merge_request, source_project: project, source_branch: 'master', target_branch: 'develop') } + + it 'sets head pipeline' do + subject + + expect(response).to have_http_status(201) + expect(merge_request.reload.head_pipeline).not_to be_nil + end + end end context 'when updatig a commit status' do @@ -190,7 +205,7 @@ describe API::CommitStatuses do post api(post_url, developer), { state: 'running', context: 'coverage', - ref: 'develop', + ref: 'master', description: 'coverage test', coverage: 0.0, target_url: 'http://gitlab.com/status' @@ -199,7 +214,7 @@ describe API::CommitStatuses do post api(post_url, developer), { state: 'success', name: 'coverage', - ref: 'develop', + ref: 'master', description: 'new description', coverage: 90.0 } @@ -210,7 +225,7 @@ describe API::CommitStatuses do expect(json_response['sha']).to eq(commit.id) expect(json_response['status']).to eq('success') expect(json_response['name']).to eq('coverage') - expect(json_response['ref']).to eq('develop') + expect(json_response['ref']).to eq('master') expect(json_response['coverage']).to eq(90.0) expect(json_response['description']).to eq('new description') expect(json_response['target_url']).to eq('http://gitlab.com/status') |