Commit c47eef94 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix-mwps-shows-inconsistent-sha-ce' into 'master'

CE Port: Fix MWPS/ADMTWPS system notes shows wrong sha

See merge request gitlab-org/gitlab-ce!30160
parents 1ca9784e df3a0f26
...@@ -5,7 +5,7 @@ module AutoMerge ...@@ -5,7 +5,7 @@ module AutoMerge
def execute(merge_request) def execute(merge_request)
super do super do
if merge_request.saved_change_to_auto_merge_enabled? if merge_request.saved_change_to_auto_merge_enabled?
SystemNoteService.merge_when_pipeline_succeeds(merge_request, project, current_user, merge_request.diff_head_commit) SystemNoteService.merge_when_pipeline_succeeds(merge_request, project, current_user, merge_request.actual_head_pipeline.sha)
end end
end end
end end
......
...@@ -221,8 +221,8 @@ module SystemNoteService ...@@ -221,8 +221,8 @@ module SystemNoteService
end end
# Called when 'merge when pipeline succeeds' is executed # Called when 'merge when pipeline succeeds' is executed
def merge_when_pipeline_succeeds(noteable, project, author, last_commit) def merge_when_pipeline_succeeds(noteable, project, author, sha)
body = "enabled an automatic merge when the pipeline for #{last_commit.to_reference(project)} succeeds" body = "enabled an automatic merge when the pipeline for #{sha} succeeds"
create_note(NoteSummary.new(noteable, project, author, body, action: 'merge')) create_note(NoteSummary.new(noteable, project, author, body, action: 'merge'))
end end
......
...@@ -59,6 +59,11 @@ describe AutoMerge::BaseService do ...@@ -59,6 +59,11 @@ describe AutoMerge::BaseService do
context 'when strategy is merge when pipeline succeeds' do context 'when strategy is merge when pipeline succeeds' do
let(:service) { AutoMerge::MergeWhenPipelineSucceedsService.new(project, user) } let(:service) { AutoMerge::MergeWhenPipelineSucceedsService.new(project, user) }
before do
pipeline = build(:ci_pipeline)
allow(merge_request).to receive(:actual_head_pipeline) { pipeline }
end
it 'sets the auto merge strategy' do it 'sets the auto merge strategy' do
subject subject
......
...@@ -64,8 +64,11 @@ describe AutoMerge::MergeWhenPipelineSucceedsService do ...@@ -64,8 +64,11 @@ describe AutoMerge::MergeWhenPipelineSucceedsService do
end end
it 'creates a system note' do it 'creates a system note' do
pipeline = build(:ci_pipeline)
allow(merge_request).to receive(:actual_head_pipeline) { pipeline }
note = merge_request.notes.last note = merge_request.notes.last
expect(note.note).to match %r{enabled an automatic merge when the pipeline for (\w+/\w+@)?\h{8}} expect(note.note).to match "enabled an automatic merge when the pipeline for #{pipeline.sha}"
end end
end end
......
...@@ -332,7 +332,7 @@ describe SystemNoteService do ...@@ -332,7 +332,7 @@ describe SystemNoteService do
create(:merge_request, source_project: project, target_project: project) create(:merge_request, source_project: project, target_project: project)
end end
subject { described_class.merge_when_pipeline_succeeds(noteable, project, author, noteable.diff_head_commit) } subject { described_class.merge_when_pipeline_succeeds(noteable, project, author, pipeline.sha) }
it_behaves_like 'a system note' do it_behaves_like 'a system note' do
let(:action) { 'merge' } let(:action) { 'merge' }
......
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