debian-mirror-gitlab/app/services/merge_requests/merge_service.rb

52 lines
1.3 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
module MergeRequests
# MergeService class
#
2015-09-25 12:07:36 +05:30
# 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-04-26 12:48:37 +05:30
def execute(merge_request, commit_message)
2015-09-25 12:07:36 +05:30
@commit_message = commit_message
@merge_request = merge_request
unless @merge_request.mergeable?
return error('Merge request is not mergeable')
end
merge_request.in_locked_state do
if commit
after_merge
success
else
error('Can not merge changes')
end
end
end
2014-09-02 18:07:02 +05:30
2015-09-25 12:07:36 +05:30
private
def commit
2015-10-24 18:46:33 +05:30
committer = repository.user_to_committer(current_user)
2015-09-25 12:07:36 +05:30
options = {
message: commit_message,
author: committer,
committer: committer
}
repository.merge(current_user, merge_request.source_sha, merge_request.target_branch, options)
2015-10-24 18:46:33 +05:30
rescue Exception => e
merge_request.update(merge_error: "Something went wrong during merge")
Rails.logger.error(e.message)
return false
2015-09-25 12:07:36 +05:30
end
2014-09-02 18:07:02 +05:30
2015-09-25 12:07:36 +05:30
def after_merge
MergeRequests::PostMergeService.new(project, current_user).execute(merge_request)
2014-09-02 18:07:02 +05:30
end
end
end