diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-04-02 22:51:17 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-04-02 22:51:17 +0400 |
commit | 3c867dfa8efec28155158e3b2b7dbb21ba3ce0a1 (patch) | |
tree | ae7fbca5d6cc9b195db95fbea05da79b52e8e04e /app/services | |
parent | 65cd9829eecd2485f17eaadf84107631d5a723d9 (diff) |
MergeRequest services for create, update, close and reopen
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/merge_requests/base_service.rb | 16 | ||||
-rw-r--r-- | app/services/merge_requests/close_service.rb | 18 | ||||
-rw-r--r-- | app/services/merge_requests/create_service.rb | 18 | ||||
-rw-r--r-- | app/services/merge_requests/reopen_service.rb | 15 | ||||
-rw-r--r-- | app/services/merge_requests/update_service.rb | 33 |
5 files changed, 100 insertions, 0 deletions
diff --git a/app/services/merge_requests/base_service.rb b/app/services/merge_requests/base_service.rb new file mode 100644 index 00000000000..a1261972157 --- /dev/null +++ b/app/services/merge_requests/base_service.rb @@ -0,0 +1,16 @@ +module MergeRequests + class BaseService < ::BaseService + + private + + def create_note(merge_request) + Note.create_status_change_note(merge_request, merge_request.target_project, current_user, merge_request.state, nil) + end + + def execute_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/close_service.rb b/app/services/merge_requests/close_service.rb new file mode 100644 index 00000000000..64e37a23e6b --- /dev/null +++ b/app/services/merge_requests/close_service.rb @@ -0,0 +1,18 @@ +module MergeRequests + class CloseService < MergeRequests::BaseService + def execute(merge_request, commit = nil) + # If we close MergeRequest we want to ignore validation + # so we can close broken one (Ex. fork project removed) + merge_request.allow_broken = true + + if merge_request.close + event_service.close_mr(merge_request, current_user) + notification_service.close_mr(merge_request, current_user) + create_note(merge_request) + execute_hooks(merge_request) + end + + merge_request + end + end +end diff --git a/app/services/merge_requests/create_service.rb b/app/services/merge_requests/create_service.rb new file mode 100644 index 00000000000..3717d4d1fc4 --- /dev/null +++ b/app/services/merge_requests/create_service.rb @@ -0,0 +1,18 @@ +module MergeReques + class CreateService < MergeRequests::BaseService + def execute + merge_request = MergeRequest.new(params) + merge_request.source_project = project + merge_request.author = current_user + + if merge_request.save + event_service.open_mr(merge_request, current_user) + notification_service.new_merge_request(merge_request, current_user) + merge_request.create_cross_references!(merge_request.project, current_user) + execute_hooks(merge_request) + end + + merge_request + end + end +end diff --git a/app/services/merge_requests/reopen_service.rb b/app/services/merge_requests/reopen_service.rb new file mode 100644 index 00000000000..2eb13d3e0e1 --- /dev/null +++ b/app/services/merge_requests/reopen_service.rb @@ -0,0 +1,15 @@ +module MergeRequests + class ReopenService < MergeRequests::BaseService + def execute(merge_request) + if merge_request.reopen + event_service.reopen_mr(merge_request, current_user) + create_note(merge_request) + execute_hooks(merge_request) + merge_request.reload_code + merge_request.mark_as_unchecked + end + + merge_request + end + end +end diff --git a/app/services/merge_requests/update_service.rb b/app/services/merge_requests/update_service.rb new file mode 100644 index 00000000000..743930f5e8b --- /dev/null +++ b/app/services/merge_requests/update_service.rb @@ -0,0 +1,33 @@ +module MergeRequests + class UpdateService < MergeRequests::BaseService + def execute(merge_request) + # We dont allow change of source/target projects + # after merge request was created + params.delete(:source_project_id) + params.delete(:target_project_id) + + state = params.delete('state_event') + + case state + when 'reopen' + MergeRequests::ReopenService.new(project, current_user, {}).execute(merge_request) + when 'close' + MergeRequests::CloseService.new(project, current_user, {}).execute(merge_request) + end + + if params.present? && merge_request.update_attributes(params) + merge_request.reset_events_cache + + if merge_request.previous_changes.include?('assignee_id') + notification_service.reassigned_merge_request(merge_request, current_user) + create_assignee_note(merge_request) + end + + merge_request.notice_added_references(merge_request.project, current_user) + execute_hooks(merge_request) + end + + merge_request + end + end +end |