diff options
Diffstat (limited to 'app/services/system_note_service.rb')
-rw-r--r-- | app/services/system_note_service.rb | 87 |
1 files changed, 12 insertions, 75 deletions
diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb index b3eee01ea7a..25e3282d3fb 100644 --- a/app/services/system_note_service.rb +++ b/app/services/system_note_service.rb @@ -128,82 +128,37 @@ module SystemNoteService # Called when 'merge when pipeline succeeds' is executed def merge_when_pipeline_succeeds(noteable, project, author, sha) - body = "enabled an automatic merge when the pipeline for #{sha} succeeds" - - create_note(NoteSummary.new(noteable, project, author, body, action: 'merge')) + ::SystemNotes::MergeRequestsService.new(noteable: noteable, project: project, author: author).merge_when_pipeline_succeeds(sha) end # Called when 'merge when pipeline succeeds' is canceled def cancel_merge_when_pipeline_succeeds(noteable, project, author) - body = 'canceled the automatic merge' - - create_note(NoteSummary.new(noteable, project, author, body, action: 'merge')) + ::SystemNotes::MergeRequestsService.new(noteable: noteable, project: project, author: author).cancel_merge_when_pipeline_succeeds end # Called when 'merge when pipeline succeeds' is aborted def abort_merge_when_pipeline_succeeds(noteable, project, author, reason) - body = "aborted the automatic merge because #{reason}" - - ## - # TODO: Abort message should be sent by the system, not a particular user. - # See https://gitlab.com/gitlab-org/gitlab-foss/issues/63187. - create_note(NoteSummary.new(noteable, project, author, body, action: 'merge')) + ::SystemNotes::MergeRequestsService.new(noteable: noteable, project: project, author: author).abort_merge_when_pipeline_succeeds(reason) end def handle_merge_request_wip(noteable, project, author) - prefix = noteable.work_in_progress? ? "marked" : "unmarked" - - body = "#{prefix} as a **Work In Progress**" - - create_note(NoteSummary.new(noteable, project, author, body, action: 'title')) + ::SystemNotes::MergeRequestsService.new(noteable: noteable, project: project, author: author).handle_merge_request_wip end def add_merge_request_wip_from_commit(noteable, project, author, commit) - body = "marked as a **Work In Progress** from #{commit.to_reference(project)}" - - create_note(NoteSummary.new(noteable, project, author, body, action: 'title')) + ::SystemNotes::MergeRequestsService.new(noteable: noteable, project: project, author: author).add_merge_request_wip_from_commit(commit) end def resolve_all_discussions(merge_request, project, author) - body = "resolved all threads" - - create_note(NoteSummary.new(merge_request, project, author, body, action: 'discussion')) + ::SystemNotes::MergeRequestsService.new(noteable: merge_request, project: project, author: author).resolve_all_discussions end def discussion_continued_in_issue(discussion, project, author, issue) - body = "created #{issue.to_reference} to continue this discussion" - note_attributes = discussion.reply_attributes.merge(project: project, author: author, note: body) - - note = Note.create(note_attributes.merge(system: true, created_at: issue.system_note_timestamp)) - note.system_note_metadata = SystemNoteMetadata.new(action: 'discussion') - - note + ::SystemNotes::MergeRequestsService.new(project: project, author: author).discussion_continued_in_issue(discussion, issue) end def diff_discussion_outdated(discussion, project, author, change_position) - merge_request = discussion.noteable - diff_refs = change_position.diff_refs - version_index = merge_request.merge_request_diffs.viewable.count - position_on_text = change_position.on_text? - text_parts = ["changed this #{position_on_text ? 'line' : 'file'} in"] - - if version_params = merge_request.version_params_for(diff_refs) - repository = project.repository - anchor = position_on_text ? change_position.line_code(repository) : change_position.file_hash - url = url_helpers.diffs_project_merge_request_path(project, merge_request, version_params.merge(anchor: anchor)) - - text_parts << "[version #{version_index} of the diff](#{url})" - else - text_parts << "version #{version_index} of the diff" - end - - body = text_parts.join(' ') - note_attributes = discussion.reply_attributes.merge(project: project, author: author, note: body) - - note = Note.create(note_attributes.merge(system: true)) - note.system_note_metadata = SystemNoteMetadata.new(action: 'outdated') - - note + ::SystemNotes::MergeRequestsService.new(project: project, author: author).diff_discussion_outdated(discussion, change_position) end def change_title(noteable, project, author, old_title) @@ -233,9 +188,7 @@ module SystemNoteService # # Returns the created Note object def change_branch(noteable, project, author, branch_type, old_branch, new_branch) - body = "changed #{branch_type} branch from `#{old_branch}` to `#{new_branch}`" - - create_note(NoteSummary.new(noteable, project, author, body, action: 'branch')) + ::SystemNotes::MergeRequestsService.new(noteable: noteable, project: project, author: author).change_branch(branch_type, old_branch, new_branch) end # Called when a branch in Noteable is added or deleted @@ -253,16 +206,7 @@ module SystemNoteService # # Returns the created Note object def change_branch_presence(noteable, project, author, branch_type, branch, presence) - verb = - if presence == :add - 'restored' - else - 'deleted' - end - - body = "#{verb} #{branch_type} branch `#{branch}`" - - create_note(NoteSummary.new(noteable, project, author, body, action: 'branch')) + ::SystemNotes::MergeRequestsService.new(noteable: noteable, project: project, author: author).change_branch_presence(branch_type, branch, presence) end # Called when a branch is created from the 'new branch' button on a issue @@ -270,18 +214,11 @@ module SystemNoteService # # "created branch `201-issue-branch-button`" def new_issue_branch(issue, project, author, branch, branch_project: nil) - branch_project ||= project - link = url_helpers.project_compare_path(branch_project, from: branch_project.default_branch, to: branch) - - body = "created branch [`#{branch}`](#{link}) to address this issue" - - create_note(NoteSummary.new(issue, project, author, body, action: 'branch')) + ::SystemNotes::MergeRequestsService.new(noteable: issue, project: project, author: author).new_issue_branch(branch, branch_project: branch_project) end def new_merge_request(issue, project, author, merge_request) - body = "created merge request #{merge_request.to_reference(project)} to address this issue" - - create_note(NoteSummary.new(issue, project, author, body, action: 'merge')) + ::SystemNotes::MergeRequestsService.new(noteable: issue, project: project, author: author).new_merge_request(merge_request) end def cross_reference(noteable, mentioner, author) |