Skip to content
代码片段 群组 项目
未验证 提交 edd1c5be 编辑于 作者: Max Fan's avatar Max Fan 提交者: GitLab
浏览文件

Merge branch 'fix-commit-status-api-overwriting-merge-request-head-pipeline' into 'master'

Fix commit status API incorrectly overwriting MR head pipeline

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/147212



Merged-by: default avatarMax Fan <mfan@gitlab.com>
Approved-by: default avatarMax Fan <mfan@gitlab.com>
Reviewed-by: default avatarHordur Freyr Yngvason <hfyngvason@gitlab.com>
Reviewed-by: default avatarTianwen Chen <tchen@gitlab.com>
Reviewed-by: default avatarMax Fan <mfan@gitlab.com>
Co-authored-by: default avatarHordur Freyr Yngvason <hfyngvason@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -36,7 +36,6 @@ def unsafe_execute
return bad_request(response.message) if response.error?
update_merge_request_head_pipeline
response
end
......@@ -73,6 +72,10 @@ def create_pipeline
).tap do |new_pipeline|
new_pipeline.ensure_project_iid!
new_pipeline.save!
Gitlab::EventStore.publish(
Ci::PipelineCreatedEvent.new(data: { pipeline_id: new_pipeline.id })
)
end
end
......@@ -106,14 +109,6 @@ def add_or_update_external_job
end
end
def update_merge_request_head_pipeline
return unless pipeline.latest?
::MergeRequest
.from_project(project).from_source_branches(ref)
.update_all(head_pipeline_id: pipeline.id)
end
def apply_job_state!(job)
case params[:state]
when 'pending'
......
......@@ -293,9 +293,11 @@ def create_status(commit, opts = {})
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') }
let!(:merge_request) do
create(:merge_request, source_project: project, head_pipeline_id: nil)
end
it 'sets head pipeline' do
it 'sets head pipeline', :sidekiq_inline do
subject
expect(response).to have_gitlab_http_status(:created)
......
......@@ -112,10 +112,10 @@
context 'when merge request exists for given branch' do
let!(:merge_request) do
create(:merge_request, source_project: project, source_branch: 'master', target_branch: 'develop')
create(:merge_request, source_project: project, head_pipeline: nil)
end
it 'sets head pipeline' do
it 'sets head pipeline', :sidekiq_inline do
expect { response }
.to change { ::Ci::Pipeline.count }.by(1)
.and change { ::Ci::Stage.count }.by(1)
......@@ -124,6 +124,34 @@
expect(response).to be_success
expect(merge_request.reload.head_pipeline).not_to be_nil
end
context 'when the MR has a branch head pipeline' do
let!(:merge_request) do
create(:merge_request, :with_head_pipeline, source_project: project)
end
it 'adds the status to the existing pipeline' do
expect { response }.not_to change { ::Ci::Pipeline.count }
expect(response.payload[:job].pipeline_id).to eq(merge_request.head_pipeline_id)
end
end
context 'when the MR has a merged result head pipeline' do
let!(:merge_request) do
create(:merge_request, source_project: project, head_pipeline: head_pipeline)
end
let(:head_pipeline) { create(:ci_pipeline, :merged_result_pipeline) }
it 'creates a new branch pipeline but does not change the head pipeline' do
expect { response }
.to change { ::Ci::Pipeline.count }.by(1)
.and change { ::Ci::Stage.count }.by(1)
.and change { ::CommitStatus.count }.by(1)
expect(merge_request.reload.head_pipeline_id).to eq(head_pipeline.id)
end
end
end
end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册