Commit 886c2093 authored by syasonik's avatar syasonik

Refactor services into helpers

parent 9955183f
...@@ -17,11 +17,11 @@ module EE ...@@ -17,11 +17,11 @@ module EE
end end
def relate_issue(noteable, noteable_ref, user) def relate_issue(noteable, noteable_ref, user)
::SystemNotes::IssuablesService.new(noteable: noteable, project: noteable.project, author: user).relate_issue(noteable_ref) issuables_service(noteable, noteable.project, user).relate_issue(noteable_ref)
end end
def unrelate_issue(noteable, noteable_ref, user) def unrelate_issue(noteable, noteable_ref, user)
::SystemNotes::IssuablesService.new(noteable: noteable, project: noteable.project, author: user).unrelate_issue(noteable_ref) issuables_service(noteable, noteable.project, user).unrelate_issue(noteable_ref)
end end
# Parameters: # Parameters:
...@@ -34,9 +34,9 @@ module EE ...@@ -34,9 +34,9 @@ module EE
# #
# Returns [Array<Note>]: the created Note objects # Returns [Array<Note>]: the created Note objects
def design_version_added(version) def design_version_added(version)
EE::SystemNotes::DesignManagementService.new(noteable: version.issue, design_management_service(version.issue,
project: version.issue.project, version.issue.project,
author: version.author).design_version_added(version) version.author).design_version_added(version)
end end
# Called when a new discussion is created on a design # Called when a new discussion is created on a design
...@@ -50,29 +50,29 @@ module EE ...@@ -50,29 +50,29 @@ module EE
# Returns the created Note object # Returns the created Note object
def design_discussion_added(discussion_note) def design_discussion_added(discussion_note)
design = discussion_note.noteable design = discussion_note.noteable
EE::SystemNotes::DesignManagementService.new(noteable: design.issue, design_management_service(design.issue,
project: design.project, design.project,
author: discussion_note.author).design_discussion_added(discussion_note) discussion_note.author).design_discussion_added(discussion_note)
end end
def epic_issue(epic, issue, user, type) def epic_issue(epic, issue, user, type)
EE::SystemNotes::EpicsService.new(noteable: epic, author: user).epic_issue(issue, type) epics_service(epic, user).epic_issue(issue, type)
end end
def epic_issue_moved(from_epic, issue, to_epic, user) def epic_issue_moved(from_epic, issue, to_epic, user)
EE::SystemNotes::EpicsService.new(noteable: from_epic, author: user).epic_issue_moved(issue, to_epic) epics_service(from_epic, user).epic_issue_moved(issue, to_epic)
end end
def issue_promoted(noteable, noteable_ref, author, direction:) def issue_promoted(noteable, noteable_ref, author, direction:)
EE::SystemNotes::EpicsService.new(noteable: noteable, author: author).issue_promoted(noteable_ref, direction: direction) epics_service(noteable, author).issue_promoted(noteable_ref, direction: direction)
end end
def issue_on_epic(issue, epic, user, type) def issue_on_epic(issue, epic, user, type)
EE::SystemNotes::EpicsService.new(noteable: epic, author: user).issue_on_epic(issue, type) epics_service(epic, user).issue_on_epic(issue, type)
end end
def issue_epic_change(issue, epic, user) def issue_epic_change(issue, epic, user)
EE::SystemNotes::EpicsService.new(noteable: epic, author: user).issue_epic_change(issue) epics_service(epic, user).issue_epic_change(issue)
end end
# Called when the merge request is approved by user # Called when the merge request is approved by user
...@@ -86,11 +86,11 @@ module EE ...@@ -86,11 +86,11 @@ module EE
# #
# Returns the created Note object # Returns the created Note object
def approve_mr(noteable, user) def approve_mr(noteable, user)
::SystemNotes::MergeRequestsService.new(noteable: noteable, project: noteable.project, author: user).approve_mr merge_requests_service(noteable, noteable.project, user).approve_mr
end end
def unapprove_mr(noteable, user) def unapprove_mr(noteable, user)
::SystemNotes::MergeRequestsService.new(noteable: noteable, project: noteable.project, author: user).unapprove_mr merge_requests_service(noteable, noteable.project, user).unapprove_mr
end end
# Called when the weight of a Noteable is changed # Called when the weight of a Noteable is changed
...@@ -107,7 +107,7 @@ module EE ...@@ -107,7 +107,7 @@ module EE
# #
# Returns the created Note object # Returns the created Note object
def change_weight_note(noteable, project, author) def change_weight_note(noteable, project, author)
::SystemNotes::IssuablesService.new(noteable: noteable, project: project, author: author).change_weight_note issuables_service(noteable, project, author).change_weight_note
end end
# Called when the health_stauts of an Issue is changed # Called when the health_stauts of an Issue is changed
...@@ -123,7 +123,7 @@ module EE ...@@ -123,7 +123,7 @@ module EE
# #
# Returns the created Note object # Returns the created Note object
def change_health_status_note(noteable, project, author) def change_health_status_note(noteable, project, author)
::SystemNotes::IssuablesService.new(noteable: noteable, project: project, author: author).change_health_status_note issuables_service(noteable, project, author).change_health_status_note
end end
# Called when the start or end date of an Issuable is changed # Called when the start or end date of an Issuable is changed
...@@ -139,50 +139,77 @@ module EE ...@@ -139,50 +139,77 @@ module EE
# #
# Returns the created Note object # Returns the created Note object
def change_epic_date_note(noteable, author, date_type, date) def change_epic_date_note(noteable, author, date_type, date)
EE::SystemNotes::EpicsService.new(noteable: noteable, author: author).change_epic_date_note(date_type, date) epics_service(noteable, author).change_epic_date_note(date_type, date)
end end
def change_epics_relation(epic, child_epic, user, type) def change_epics_relation(epic, child_epic, user, type)
EE::SystemNotes::EpicsService.new(noteable: epic, author: user).change_epics_relation(child_epic, type) epics_service(epic, user).change_epics_relation(child_epic, type)
end end
# Called when 'merge train' is executed # Called when 'merge train' is executed
def merge_train(noteable, project, author, merge_train) def merge_train(noteable, project, author, merge_train)
EE::SystemNotes::MergeTrainService.new(noteable: noteable, project: project, author: author).enqueue(merge_train) merge_trains_service(noteable, project, author).enqueue(merge_train)
end end
# Called when 'merge train' is canceled # Called when 'merge train' is canceled
def cancel_merge_train(noteable, project, author) def cancel_merge_train(noteable, project, author)
EE::SystemNotes::MergeTrainService.new(noteable: noteable, project: project, author: author).cancel merge_trains_service(noteable, project, author).cancel
end end
# Called when 'merge train' is aborted # Called when 'merge train' is aborted
def abort_merge_train(noteable, project, author, reason) def abort_merge_train(noteable, project, author, reason)
EE::SystemNotes::MergeTrainService.new(noteable: noteable, project: project, author: author).abort(reason) merge_trains_service(noteable, project, author).abort(reason)
end end
# Called when 'add to merge train when pipeline succeeds' is executed # Called when 'add to merge train when pipeline succeeds' is executed
def add_to_merge_train_when_pipeline_succeeds(noteable, project, author, sha) def add_to_merge_train_when_pipeline_succeeds(noteable, project, author, sha)
EE::SystemNotes::MergeTrainService.new(noteable: noteable, project: project, author: author).add_when_pipeline_succeeds(sha) merge_trains_service(noteable, project, author).add_when_pipeline_succeeds(sha)
end end
# Called when 'add to merge train when pipeline succeeds' is canceled # Called when 'add to merge train when pipeline succeeds' is canceled
def cancel_add_to_merge_train_when_pipeline_succeeds(noteable, project, author) def cancel_add_to_merge_train_when_pipeline_succeeds(noteable, project, author)
EE::SystemNotes::MergeTrainService.new(noteable: noteable, project: project, author: author).cancel_add_when_pipeline_succeeds merge_trains_service(noteable, project, author).cancel_add_when_pipeline_succeeds
end end
# Called when 'add to merge train when pipeline succeeds' is aborted # Called when 'add to merge train when pipeline succeeds' is aborted
def abort_add_to_merge_train_when_pipeline_succeeds(noteable, project, author, reason) def abort_add_to_merge_train_when_pipeline_succeeds(noteable, project, author, reason)
EE::SystemNotes::MergeTrainService.new(noteable: noteable, project: project, author: author).abort_add_when_pipeline_succeeds(reason) merge_trains_service(noteable, project, author).abort_add_when_pipeline_succeeds(reason)
end end
# Called when state is changed for 'vulnerability' # Called when state is changed for 'vulnerability'
def change_vulnerability_state(noteable, author) def change_vulnerability_state(noteable, author)
EE::SystemNotes::VulnerabilitiesService.new(noteable: noteable, project: noteable.project, author: author).change_vulnerability_state vulnerabilities_service(noteable, noteable.project, author).change_vulnerability_state
end end
# Called when quick action to publish an issue to status page is called
def publish_issue_to_status_page(noteable, project, author) def publish_issue_to_status_page(noteable, project, author)
::SystemNotes::IssuablesService.new(noteable: noteable, project: project, author: author).publish_issue_to_status_page issuables_service(noteable, project, author).publish_issue_to_status_page
end
private
def issuables_service(noteable, project, author)
::SystemNotes::IssuablesService.new(noteable: noteable, project: project, author: author)
end
def design_management_service(noteable, project, author)
EE::SystemNotes::DesignManagementService.new(noteable: noteable, project: project, author: author)
end
def epics_service(noteable, author)
EE::SystemNotes::EpicsService.new(noteable: noteable, author: author)
end
def merge_requests_service(noteable, project, author)
::SystemNotes::MergeRequestsService.new(noteable: noteable, project: project, author: author)
end
def merge_trains_service(noteable, project, author)
EE::SystemNotes::MergeTrainService.new(noteable: noteable, project: project, author: author)
end
def vulnerabilities_service(noteable, project, author)
EE::SystemNotes::VulnerabilitiesService.new(noteable: noteable, project: project, author: author)
end end
end end
end end
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