2014-01-24 07:18:32 -05:00
|
|
|
module MergeRequests
|
|
|
|
# MergeService class
|
|
|
|
#
|
2015-08-11 08:33:31 -04:00
|
|
|
# Do git merge and in case of success
|
|
|
|
# mark merge request as merged and execute all hooks and notifications
|
|
|
|
# Executed when you do merge via GitLab UI
|
|
|
|
#
|
|
|
|
class MergeService < MergeRequests::BaseService
|
|
|
|
attr_reader :merge_request, :commit_message
|
|
|
|
|
2015-01-06 19:24:47 -05:00
|
|
|
def execute(merge_request, commit_message)
|
2015-08-11 08:33:31 -04:00
|
|
|
@commit_message = commit_message
|
|
|
|
@merge_request = merge_request
|
2014-01-24 07:18:32 -05:00
|
|
|
|
2015-08-11 08:33:31 -04:00
|
|
|
unless @merge_request.mergeable?
|
|
|
|
return error('Merge request is not mergeable')
|
|
|
|
end
|
|
|
|
|
|
|
|
merge_request.in_locked_state do
|
2015-08-14 11:52:49 -04:00
|
|
|
if commit
|
2015-08-11 08:33:31 -04:00
|
|
|
after_merge
|
|
|
|
success
|
|
|
|
else
|
|
|
|
error('Can not merge changes')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def commit
|
|
|
|
committer = repository.user_to_comitter(current_user)
|
|
|
|
|
|
|
|
options = {
|
|
|
|
message: commit_message,
|
|
|
|
author: committer,
|
|
|
|
committer: committer
|
|
|
|
}
|
|
|
|
|
2015-08-14 11:52:49 -04:00
|
|
|
repository.merge(current_user, merge_request.source_sha, merge_request.target_branch, options)
|
2015-08-11 08:33:31 -04:00
|
|
|
end
|
2014-01-24 07:18:32 -05:00
|
|
|
|
2015-08-11 08:33:31 -04:00
|
|
|
def after_merge
|
|
|
|
MergeRequests::PostMergeService.new(project, current_user).execute(merge_request)
|
2014-01-24 07:18:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|