Commit 6afff7c6 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix head pipeline stored in merge request for external pipelines

parent 99bdfd18
---
title: Fix head pipeline stored in merge request for external pipelines
merge_request:
author:
...@@ -108,6 +108,9 @@ module API ...@@ -108,6 +108,9 @@ module API
render_api_error!('invalid state', 400) render_api_error!('invalid state', 400)
end end
MergeRequest.where(source_project: @project, source_branch: ref)
.update_all(head_pipeline_id: pipeline) if pipeline.latest?
present status, with: Entities::CommitStatus present status, with: Entities::CommitStatus
rescue StateMachines::InvalidTransition => e rescue StateMachines::InvalidTransition => e
render_api_error!(e.message, 400) render_api_error!(e.message, 400)
......
...@@ -164,25 +164,40 @@ describe API::CommitStatuses do ...@@ -164,25 +164,40 @@ describe API::CommitStatuses do
context 'with all optional parameters' do context 'with all optional parameters' do
context 'when creating a commit status' do context 'when creating a commit status' do
it 'creates commit status' do subject do
post api(post_url, developer), { post api(post_url, developer), {
state: 'success', state: 'success',
context: 'coverage', context: 'coverage',
ref: 'develop', ref: 'master',
description: 'test', description: 'test',
coverage: 80.0, coverage: 80.0,
target_url: 'http://gitlab.com/status' target_url: 'http://gitlab.com/status'
} }
end
it 'creates commit status' do
subject
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
expect(json_response['sha']).to eq(commit.id) expect(json_response['sha']).to eq(commit.id)
expect(json_response['status']).to eq('success') expect(json_response['status']).to eq('success')
expect(json_response['name']).to eq('coverage') 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['coverage']).to eq(80.0)
expect(json_response['description']).to eq('test') expect(json_response['description']).to eq('test')
expect(json_response['target_url']).to eq('http://gitlab.com/status') expect(json_response['target_url']).to eq('http://gitlab.com/status')
end 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 end
context 'when updatig a commit status' do context 'when updatig a commit status' do
...@@ -190,7 +205,7 @@ describe API::CommitStatuses do ...@@ -190,7 +205,7 @@ describe API::CommitStatuses do
post api(post_url, developer), { post api(post_url, developer), {
state: 'running', state: 'running',
context: 'coverage', context: 'coverage',
ref: 'develop', ref: 'master',
description: 'coverage test', description: 'coverage test',
coverage: 0.0, coverage: 0.0,
target_url: 'http://gitlab.com/status' target_url: 'http://gitlab.com/status'
...@@ -199,7 +214,7 @@ describe API::CommitStatuses do ...@@ -199,7 +214,7 @@ describe API::CommitStatuses do
post api(post_url, developer), { post api(post_url, developer), {
state: 'success', state: 'success',
name: 'coverage', name: 'coverage',
ref: 'develop', ref: 'master',
description: 'new description', description: 'new description',
coverage: 90.0 coverage: 90.0
} }
...@@ -210,7 +225,7 @@ describe API::CommitStatuses do ...@@ -210,7 +225,7 @@ describe API::CommitStatuses do
expect(json_response['sha']).to eq(commit.id) expect(json_response['sha']).to eq(commit.id)
expect(json_response['status']).to eq('success') expect(json_response['status']).to eq('success')
expect(json_response['name']).to eq('coverage') 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['coverage']).to eq(90.0)
expect(json_response['description']).to eq('new description') expect(json_response['description']).to eq('new description')
expect(json_response['target_url']).to eq('http://gitlab.com/status') expect(json_response['target_url']).to eq('http://gitlab.com/status')
......
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