Commit f50b7b5c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'merge-system-note' into 'master'

Refactor merge request merge service

See merge request !1374
parents 6e5c72f8 ee9849b7
...@@ -189,7 +189,9 @@ class MergeRequest < ActiveRecord::Base ...@@ -189,7 +189,9 @@ class MergeRequest < ActiveRecord::Base
end end
def automerge!(current_user, commit_message = nil) def automerge!(current_user, commit_message = nil)
MergeRequests::AutoMergeService.new.execute(self, current_user, commit_message) MergeRequests::AutoMergeService.
new(target_project, current_user).
execute(self, commit_message)
end end
def open? def open?
......
...@@ -5,15 +5,16 @@ module MergeRequests ...@@ -5,15 +5,16 @@ module MergeRequests
# mark merge request as merged and execute all hooks and notifications # mark merge request as merged and execute all hooks and notifications
# Called when you do merge via GitLab UI # Called when you do merge via GitLab UI
class AutoMergeService < BaseMergeService class AutoMergeService < BaseMergeService
def execute(merge_request, current_user, commit_message) def execute(merge_request, commit_message)
merge_request.lock_mr merge_request.lock_mr
if Gitlab::Satellite::MergeAction.new(current_user, merge_request).merge!(commit_message) if Gitlab::Satellite::MergeAction.new(current_user, merge_request).merge!(commit_message)
merge_request.merge merge_request.merge
notification.merge_mr(merge_request, current_user) notification_service.merge_mr(merge_request, current_user)
create_merge_event(merge_request, current_user) create_merge_event(merge_request, current_user)
execute_project_hooks(merge_request) create_note(merge_request)
execute_hooks(merge_request)
true true
else else
......
module MergeRequests module MergeRequests
class BaseMergeService class BaseMergeService < MergeRequests::BaseService
private private
def notification
NotificationService.new
end
def create_merge_event(merge_request, current_user) def create_merge_event(merge_request, current_user)
EventCreateService.new.merge_mr(merge_request, current_user) EventCreateService.new.merge_mr(merge_request, current_user)
end end
def execute_project_hooks(merge_request)
if merge_request.project
hook_data = merge_request.to_hook_data(current_user)
merge_request.project.execute_hooks(hook_data, :merge_request_hooks)
end
end
end end
end end
...@@ -6,12 +6,13 @@ module MergeRequests ...@@ -6,12 +6,13 @@ module MergeRequests
# Called when you do merge via command line and push code # Called when you do merge via command line and push code
# to target branch # to target branch
class MergeService < BaseMergeService class MergeService < BaseMergeService
def execute(merge_request, current_user, commit_message) def execute(merge_request, commit_message)
merge_request.merge merge_request.merge
notification.merge_mr(merge_request, current_user) notification_service.merge_mr(merge_request, current_user)
create_merge_event(merge_request, current_user) create_merge_event(merge_request, current_user)
execute_project_hooks(merge_request) create_note(merge_request)
execute_hooks(merge_request)
true true
rescue rescue
......
...@@ -32,7 +32,9 @@ module MergeRequests ...@@ -32,7 +32,9 @@ module MergeRequests
merge_requests.uniq.select(&:source_project).each do |merge_request| merge_requests.uniq.select(&:source_project).each do |merge_request|
MergeRequests::MergeService.new.execute(merge_request, @current_user, nil) MergeRequests::MergeService.
new(merge_request.target_project, @current_user).
execute(merge_request, nil)
end end
end end
......
...@@ -47,10 +47,10 @@ describe MergeRequests::RefreshService do ...@@ -47,10 +47,10 @@ describe MergeRequests::RefreshService do
reload_mrs reload_mrs
end end
it { @merge_request.notes.should be_empty } it { @merge_request.notes.last.note.should include('changed to merged') }
it { @merge_request.should be_merged } it { @merge_request.should be_merged }
it { @fork_merge_request.should be_merged } it { @fork_merge_request.should be_merged }
it { @fork_merge_request.notes.should be_empty } it { @fork_merge_request.notes.last.note.should include('changed to merged') }
end end
context 'push to fork repo source branch' do context 'push to fork repo source branch' do
...@@ -61,7 +61,7 @@ describe MergeRequests::RefreshService do ...@@ -61,7 +61,7 @@ describe MergeRequests::RefreshService do
it { @merge_request.notes.should be_empty } it { @merge_request.notes.should be_empty }
it { @merge_request.should be_open } it { @merge_request.should be_open }
it { @fork_merge_request.notes.should_not be_empty } it { @fork_merge_request.notes.last.note.should include('new commit') }
it { @fork_merge_request.should be_open } it { @fork_merge_request.should be_open }
end end
...@@ -84,7 +84,7 @@ describe MergeRequests::RefreshService do ...@@ -84,7 +84,7 @@ describe MergeRequests::RefreshService do
reload_mrs reload_mrs
end end
it { @merge_request.notes.should be_empty } it { @merge_request.notes.last.note.should include('changed to merged') }
it { @merge_request.should be_merged } it { @merge_request.should be_merged }
it { @fork_merge_request.should be_open } it { @fork_merge_request.should be_open }
it { @fork_merge_request.notes.should be_empty } it { @fork_merge_request.notes.should be_empty }
......
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