Commit 41f53685 authored by Sean McGivern's avatar Sean McGivern

Use exceptions for MergeService error handling

If any method called by `MergeService#execute` raises a `MergeError`,
that error's message will be logged, the model will be updated, and the
merge will fail.
parent 1adb3ea6
...@@ -22,11 +22,7 @@ module MergeRequests ...@@ -22,11 +22,7 @@ module MergeRequests
return log_merge_error('Merge request is not mergeable', save_message_on_model: true) return log_merge_error('Merge request is not mergeable', save_message_on_model: true)
end end
if @merge_request.target_project.above_size_limit? check_size_limit
message = Gitlab::RepositorySizeError.new(@merge_request.target_project).merge_error
return log_merge_error(message, save_message_on_model: true)
end
@source = find_merge_source @source = find_merge_source
...@@ -78,19 +74,13 @@ module MergeRequests ...@@ -78,19 +74,13 @@ module MergeRequests
commit_id = repository.merge(current_user, source, merge_request, options) commit_id = repository.merge(current_user, source, merge_request, options)
if commit_id raise MergeError, 'Conflicts detected during merge' unless commit_id
merge_request.update(merge_commit_sha: commit_id)
else merge_request.update(merge_commit_sha: commit_id)
log_merge_error('Conflicts detected during merge', save_message_on_model: true)
false
end
rescue GitHooksService::PreReceiveError => e rescue GitHooksService::PreReceiveError => e
log_merge_error(e.message, save_message_on_model: true) raise MergeError, e.message
false
rescue StandardError => e rescue StandardError => e
merge_request.update(merge_error: "Something went wrong during merge: #{e.message}") raise MergeError, "Something went wrong during merge: #{e.message}"
log_merge_error(e.message)
false
ensure ensure
merge_request.update(in_progress_merge_commit_sha: nil) merge_request.update(in_progress_merge_commit_sha: nil)
end end
...@@ -118,6 +108,14 @@ module MergeRequests ...@@ -118,6 +108,14 @@ module MergeRequests
merge_request.to_reference(full: true) merge_request.to_reference(full: true)
end end
def check_size_limit
if @merge_request.target_project.above_size_limit?
message = Gitlab::RepositorySizeError.new(@merge_request.target_project).merge_error
raise MergeError, message
end
end
def find_merge_source def find_merge_source
return merge_request.diff_head_sha unless merge_request.squash return merge_request.diff_head_sha unless merge_request.squash
......
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