diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-08-11 10:28:42 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-08-11 10:28:42 +0200 |
commit | 9f10943c1a76576ac40d96189a28a4d6123a75d8 (patch) | |
tree | 88955d92ebc98a4165d66a36cb8a2cf92709981a /app/services/merge_requests | |
parent | 84727fba96c6794874e1f94d581408b70e1842a7 (diff) | |
download | gitlab-ce-9f10943c1a76576ac40d96189a28a4d6123a75d8.tar.gz |
Revert "Merge branch 'drop-satellites'"
This reverts commit 957e849f41d96fa9778fcdd06792d2f0274b29ab, reversing
changes made to 6b9dbe9f5a175a8162abf296367f561bab3eea1a.
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/services/merge_requests')
-rw-r--r-- | app/services/merge_requests/auto_merge_service.rb | 75 | ||||
-rw-r--r-- | app/services/merge_requests/base_merge_service.rb | 10 | ||||
-rw-r--r-- | app/services/merge_requests/build_service.rb | 14 | ||||
-rw-r--r-- | app/services/merge_requests/merge_service.rb | 61 | ||||
-rw-r--r-- | app/services/merge_requests/post_merge_service.rb | 22 | ||||
-rw-r--r-- | app/services/merge_requests/refresh_service.rb | 4 |
6 files changed, 107 insertions, 79 deletions
diff --git a/app/services/merge_requests/auto_merge_service.rb b/app/services/merge_requests/auto_merge_service.rb new file mode 100644 index 00000000000..db824d452d0 --- /dev/null +++ b/app/services/merge_requests/auto_merge_service.rb @@ -0,0 +1,75 @@ +module MergeRequests + # AutoMergeService class + # + # Do git merge in satellite and in case of success + # mark merge request as merged and execute all hooks and notifications + # Called when you do merge via GitLab UI + class AutoMergeService < BaseMergeService + attr_reader :merge_request, :commit_message + + def execute(merge_request, commit_message) + @commit_message = commit_message + @merge_request = merge_request + + merge_request.lock_mr + + if merge! + merge_request.merge + create_merge_event(merge_request, current_user) + create_note(merge_request) + notification_service.merge_mr(merge_request, current_user) + execute_hooks(merge_request, 'merge') + true + else + merge_request.unlock_mr + false + end + rescue + merge_request.unlock_mr if merge_request.locked? + merge_request.mark_as_unmergeable + false + end + + def merge! + if merge_request.for_fork? + Gitlab::Satellite::MergeAction.new(current_user, merge_request).merge!(commit_message) + else + # Merge local branches using rugged instead of satellites + if sha = commit + after_commit(sha, merge_request.target_branch) + + if merge_request.remove_source_branch? + DeleteBranchService.new(merge_request.source_project, current_user).execute(merge_request.source_branch) + end + + true + else + false + end + end + end + + def commit + committer = repository.user_to_comitter(current_user) + + options = { + message: commit_message, + author: committer, + committer: committer + } + + repository.merge(merge_request.source_branch, merge_request.target_branch, options) + end + + def after_commit(sha, branch) + commit = repository.commit(sha) + full_ref = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch}" + old_sha = commit.parent_id || Gitlab::Git::BLANK_SHA + GitPushService.new.execute(project, current_user, old_sha, sha, full_ref) + end + + def repository + project.repository + end + end +end diff --git a/app/services/merge_requests/base_merge_service.rb b/app/services/merge_requests/base_merge_service.rb new file mode 100644 index 00000000000..9579573adf9 --- /dev/null +++ b/app/services/merge_requests/base_merge_service.rb @@ -0,0 +1,10 @@ +module MergeRequests + class BaseMergeService < MergeRequests::BaseService + + private + + def create_merge_event(merge_request, current_user) + EventCreateService.new.merge_mr(merge_request, current_user) + end + end +end diff --git a/app/services/merge_requests/build_service.rb b/app/services/merge_requests/build_service.rb index a9b29f9654d..956480938c3 100644 --- a/app/services/merge_requests/build_service.rb +++ b/app/services/merge_requests/build_service.rb @@ -12,16 +12,12 @@ module MergeRequests merge_request.target_project ||= (project.forked_from_project || project) merge_request.target_branch ||= merge_request.target_project.default_branch - if merge_request.target_branch.blank? || merge_request.source_branch.blank? - message = - if params[:source_branch] || params[:target_branch] - "You must select source and target branch" - end - - return build_failed(merge_request, message) + unless merge_request.target_branch && merge_request.source_branch + return build_failed(merge_request, nil) end compare_result = CompareService.new.execute( + current_user, merge_request.source_project, merge_request.source_branch, merge_request.target_project, @@ -44,6 +40,7 @@ module MergeRequests merge_request.compare_diffs = diffs elsif diffs == false + # satellite timeout return false merge_request.can_be_created = false merge_request.compare_failed = true end @@ -62,6 +59,9 @@ module MergeRequests end merge_request + + rescue Gitlab::Satellite::BranchesWithoutParent + return build_failed(merge_request, "Selected branches have no common commit so they cannot be merged.") end def build_failed(merge_request, message) diff --git a/app/services/merge_requests/merge_service.rb b/app/services/merge_requests/merge_service.rb index 2107529a21a..327ead4ff3f 100644 --- a/app/services/merge_requests/merge_service.rb +++ b/app/services/merge_requests/merge_service.rb @@ -1,57 +1,22 @@ module MergeRequests # MergeService class # - # 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 - + # Mark existing merge request as merged + # and execute all hooks and notifications + # Called when you do merge via command line and push code + # to target branch + class MergeService < BaseMergeService def execute(merge_request, commit_message) - @commit_message = commit_message - @merge_request = merge_request + merge_request.merge - unless @merge_request.mergeable? - return error('Merge request is not mergeable') - end - - merge_request.in_locked_state do - if merge_changes - after_merge - success - else - error('Can not merge changes') - end - end - end - - private - - def merge_changes - if sha = commit - after_commit(sha, merge_request.target_branch) - end - end - - def commit - committer = repository.user_to_comitter(current_user) - - options = { - message: commit_message, - author: committer, - committer: committer - } - - repository.merge(merge_request.source_sha, merge_request.target_branch, options) - end - - def after_commit(sha, branch) - PostCommitService.new(project, current_user).execute(sha, branch) - end + create_merge_event(merge_request, current_user) + create_note(merge_request) + notification_service.merge_mr(merge_request, current_user) + execute_hooks(merge_request, 'merge') - def after_merge - MergeRequests::PostMergeService.new(project, current_user).execute(merge_request) + true + rescue + false end end end diff --git a/app/services/merge_requests/post_merge_service.rb b/app/services/merge_requests/post_merge_service.rb deleted file mode 100644 index aceb8cb9021..00000000000 --- a/app/services/merge_requests/post_merge_service.rb +++ /dev/null @@ -1,22 +0,0 @@ -module MergeRequests - # PostMergeService class - # - # Mark existing merge request as merged - # and execute all hooks and notifications - # - class PostMergeService < MergeRequests::BaseService - def execute(merge_request) - merge_request.mark_as_merged - create_merge_event(merge_request, current_user) - create_note(merge_request) - notification_service.merge_mr(merge_request, current_user) - execute_hooks(merge_request, 'merge') - end - - private - - def create_merge_event(merge_request, current_user) - EventCreateService.new.merge_mr(merge_request, current_user) - end - end -end diff --git a/app/services/merge_requests/refresh_service.rb b/app/services/merge_requests/refresh_service.rb index e903e48e3cd..d0648da049b 100644 --- a/app/services/merge_requests/refresh_service.rb +++ b/app/services/merge_requests/refresh_service.rb @@ -33,9 +33,9 @@ module MergeRequests merge_requests.uniq.select(&:source_project).each do |merge_request| - MergeRequests::PostMergeService. + MergeRequests::MergeService. new(merge_request.target_project, @current_user). - execute(merge_request) + execute(merge_request, nil) end end |