summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-01-24 14:18:32 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-01-24 14:18:32 +0200
commit48f741eed9f3676a8d0d089d7336fcffd31ebaa7 (patch)
tree4a1e24e29f0a4c90fc10f274f4e900c0064bcd20 /app/services
parentd1d138562a347ec78f0331d5242e28fbb368bad0 (diff)
downloadgitlab-ce-48f741eed9f3676a8d0d089d7336fcffd31ebaa7.tar.gz
MergeRequests services
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/services')
-rw-r--r--app/services/merge_requests/auto_merge_service.rb30
-rw-r--r--app/services/merge_requests/base_merge_service.rb26
-rw-r--r--app/services/merge_requests/merge_service.rb22
3 files changed, 78 insertions, 0 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..d60d61ed54a
--- /dev/null
+++ b/app/services/merge_requests/auto_merge_service.rb
@@ -0,0 +1,30 @@
+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
+ def execute(merge_request, current_user, commit_message)
+ merge_request.lock
+
+ if Gitlab::Satellite::MergeAction.new(current_user, merge_request).merge!(commit_message)
+ merge_request.author_id_of_changes = current_user.id
+ merge_request.merge
+
+ notification.merge_mr(merge_request)
+ create_merge_event(merge_request)
+ execute_project_hooks(merge_request)
+
+ true
+ else
+ merge_request.unlock
+ false
+ end
+ rescue
+ merge_request.unlock if merge_request.locked?
+ merge_request.mark_as_unmergeable
+ false
+ 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..dbdb0063074
--- /dev/null
+++ b/app/services/merge_requests/base_merge_service.rb
@@ -0,0 +1,26 @@
+module MergeRequests
+ class BaseMergeService
+
+ private
+
+ def notification
+ NotificationService.new
+ end
+
+ def create_merge_event(merge_request)
+ Event.create(
+ project: merge_request.target_project,
+ target_id: merge_request.id,
+ target_type: merge_request.class.name,
+ action: Event::MERGED,
+ author_id: merge_request.author_id_of_changes
+ )
+ end
+
+ def execute_project_hooks(merge_request)
+ if merge_request.project
+ merge_request.project.execute_hooks(merge_request.to_hook_data, :merge_request_hooks)
+ end
+ end
+ end
+end
diff --git a/app/services/merge_requests/merge_service.rb b/app/services/merge_requests/merge_service.rb
new file mode 100644
index 00000000000..1d5af04cdbb
--- /dev/null
+++ b/app/services/merge_requests/merge_service.rb
@@ -0,0 +1,22 @@
+module MergeRequests
+ # MergeService class
+ #
+ # 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, current_user, commit_message)
+ merge_request.author_id_of_changes = current_user.id
+ merge_request.merge
+
+ notification.merge_mr(merge_request)
+ create_merge_event(merge_request)
+ execute_project_hooks(merge_request)
+
+ true
+ rescue
+ false
+ end
+ end
+end