diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-05-09 18:18:50 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-05-11 00:01:15 -0400 |
commit | 686f6855c25ecfc09fdf199cb7e3fb7dd787ed28 (patch) | |
tree | c31f3b13c4607e9b422aa53d385c3c01eff89a82 /app/services | |
parent | ff3a62aad171e4211dd9c5c6e762b1b32f9921ac (diff) | |
download | gitlab-ce-686f6855c25ecfc09fdf199cb7e3fb7dd787ed28.tar.gz |
Update SystemNoteService method naming conventions
Now the verb comes first, and there is no restriction on
singular/plural.
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/issuable_base_service.rb | 6 | ||||
-rw-r--r-- | app/services/issues/close_service.rb | 2 | ||||
-rw-r--r-- | app/services/issues/reopen_service.rb | 2 | ||||
-rw-r--r-- | app/services/merge_requests/base_service.rb | 2 | ||||
-rw-r--r-- | app/services/merge_requests/refresh_service.rb | 6 | ||||
-rw-r--r-- | app/services/system_note_service.rb | 132 |
6 files changed, 73 insertions, 77 deletions
diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb index 4d251cb30db..8960235b093 100644 --- a/app/services/issuable_base_service.rb +++ b/app/services/issuable_base_service.rb @@ -2,17 +2,17 @@ class IssuableBaseService < BaseService private def create_assignee_note(issuable) - SystemNoteService.assignee_change( + SystemNoteService.change_assignee( issuable, issuable.project, current_user, issuable.assignee) end def create_milestone_note(issuable) - SystemNoteService.milestone_change( + SystemNoteService.change_milestone( issuable, issuable.project, current_user, issuable.milestone) end def create_labels_note(issuable, added_labels, removed_labels) - SystemNoteService.label_change( + SystemNoteService.change_label( issuable, issuable.project, current_user, added_labels, removed_labels) end end diff --git a/app/services/issues/close_service.rb b/app/services/issues/close_service.rb index bdc13685fd0..138465859ce 100644 --- a/app/services/issues/close_service.rb +++ b/app/services/issues/close_service.rb @@ -14,7 +14,7 @@ module Issues private def create_note(issue, current_commit) - SystemNoteService.status_change(issue, issue.project, current_user, issue.state, current_commit) + SystemNoteService.change_status(issue, issue.project, current_user, issue.state, current_commit) end end end diff --git a/app/services/issues/reopen_service.rb b/app/services/issues/reopen_service.rb index fbbf573e5a3..e48ca359f4f 100644 --- a/app/services/issues/reopen_service.rb +++ b/app/services/issues/reopen_service.rb @@ -14,7 +14,7 @@ module Issues private def create_note(issue) - SystemNoteService.status_change(issue, issue.project, current_user, issue.state, nil) + SystemNoteService.change_status(issue, issue.project, current_user, issue.state, nil) end end end diff --git a/app/services/merge_requests/base_service.rb b/app/services/merge_requests/base_service.rb index 9b470880adf..e455fe95791 100644 --- a/app/services/merge_requests/base_service.rb +++ b/app/services/merge_requests/base_service.rb @@ -2,7 +2,7 @@ module MergeRequests class BaseService < ::IssuableBaseService def create_note(merge_request) - SystemNoteService.status_change(merge_request, merge_request.target_project, current_user, merge_request.state, nil) + SystemNoteService.change_status(merge_request, merge_request.target_project, current_user, merge_request.state, nil) end def hook_data(merge_request, action) diff --git a/app/services/merge_requests/refresh_service.rb b/app/services/merge_requests/refresh_service.rb index 1d57fd11de7..66610a08a44 100644 --- a/app/services/merge_requests/refresh_service.rb +++ b/app/services/merge_requests/refresh_service.rb @@ -82,9 +82,9 @@ module MergeRequests mr_commit_ids.include?(commit.id) end - SystemNoteService.commit_add(merge_request, merge_request.project, - @current_user, new_commits, - existing_commits, @oldrev) + SystemNoteService.add_commits(merge_request, merge_request.project, + @current_user, new_commits, + existing_commits, @oldrev) end end diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb index c4bc2339e7b..a1de050ca5a 100644 --- a/app/services/system_note_service.rb +++ b/app/services/system_note_service.rb @@ -2,11 +2,30 @@ # # Used for creating system notes (e.g., when a user references a merge request # from an issue, an issue's assignee changes, an issue is closed, etc.) -# -# All methods creating notes should be named using a singular noun and -# present-tense verb (e.g., "assignee_change" not "assignee_changed", -# "label_change" not "labels_change"). class SystemNoteService + # Called when commits are added to a Merge Request + # + # noteable - Noteable object + # project - Project owning noteable + # author - User performing the change + # new_commits - Array of Commits added since last push + # existing_commits - Array of Commits added in a previous push + # oldrev - TODO (rspeicher): I have no idea what this actually does + # + # See new_commit_summary and existing_commit_summary. + # + # Returns the created Note object + def self.add_commits(noteable, project, author, new_commits, existing_commits = [], oldrev = nil) + total_count = new_commits.length + existing_commits.length + commits_text = "#{total_count} commit".pluralize(total_count) + + body = "Added #{commits_text}:\n\n" + body << existing_commit_summary(noteable, existing_commits, oldrev) + body << new_commit_summary(new_commits).join("\n") + + create_note(noteable: noteable, project: project, author: author, note: body) + end + # Called when the assignee of a Noteable is changed or removed # # noteable - Noteable object @@ -21,49 +40,12 @@ class SystemNoteService # "Reassigned to @rspeicher" # # Returns the created Note object - def self.assignee_change(noteable, project, author, assignee) + def self.change_assignee(noteable, project, author, assignee) body = assignee.nil? ? 'Assignee removed' : "Reassigned to @#{assignee.username}" create_note(noteable: noteable, project: project, author: author, note: body) end - # Called when a Mentionable references a Noteable - # - # noteable - Noteable object being referenced - # mentioner - Mentionable object - # author - User performing the reference - # - # Example Note text: - # - # "Mentioned in #1" - # - # "Mentioned in !2" - # - # "Mentioned in 54f7727c" - # - # See cross_reference_note_content. - # - # Returns the created Note object - def self.cross_reference(noteable, mentioner, author) - return if cross_reference_disallowed?(noteable, mentioner) - - gfm_reference = mentioner_gfm_ref(noteable, mentioner) - - note_options = { - project: noteable.project, - author: author, - note: cross_reference_note_content(gfm_reference) - } - - if noteable.kind_of?(Commit) - note_options.merge!(noteable_type: 'Commit', commit_id: noteable.id) - else - note_options.merge!(noteable: noteable) - end - - create_note(note_options) - end - # Called when one or more labels on a Noteable are added and/or removed # # noteable - Noteable object @@ -81,7 +63,7 @@ class SystemNoteService # "Removed ~5 label" # # Returns the created Note object - def self.label_change(noteable, project, author, added_labels, removed_labels) + def self.change_label(noteable, project, author, added_labels, removed_labels) labels_count = added_labels.count + removed_labels.count references = ->(label) { "~#{label.id}" } @@ -119,36 +101,13 @@ class SystemNoteService # "Miletone changed to 7.11" # # Returns the created Note object - def self.milestone_change(noteable, project, author, milestone) + def self.change_milestone(noteable, project, author, milestone) body = 'Milestone ' body += milestone.nil? ? 'removed' : "changed to #{milestone.title}" create_note(noteable: noteable, project: project, author: author, note: body) end - # Called when commits are added to a Merge Request - # - # noteable - Noteable object - # project - Project owning noteable - # author - User performing the change - # new_commits - Array of Commits added since last push - # existing_commits - Array of Commits added in a previous push - # oldrev - TODO (rspeicher): I have no idea what this actually does - # - # See new_commit_summary and existing_commit_summary. - # - # Returns the created Note object - def self.commit_add(noteable, project, author, new_commits, existing_commits = [], oldrev = nil) - total_count = new_commits.length + existing_commits.length - commits_text = "#{total_count} commit".pluralize(total_count) - - body = "Added #{commits_text}:\n\n" - body << existing_commit_summary(noteable, existing_commits, oldrev) - body << new_commit_summary(new_commits).join("\n") - - create_note(noteable: noteable, project: project, author: author, note: body) - end - # Called when the status of a Noteable is changed # # noteable - Noteable object @@ -164,13 +123,50 @@ class SystemNoteService # "Status changed to closed by bc17db76" # # Returns the created Note object - def self.status_change(noteable, project, author, status, source) + def self.change_status(noteable, project, author, status, source) body = "Status changed to #{status}" body += " by #{source.gfm_reference}" if source create_note(noteable: noteable, project: project, author: author, note: body) end + # Called when a Mentionable references a Noteable + # + # noteable - Noteable object being referenced + # mentioner - Mentionable object + # author - User performing the reference + # + # Example Note text: + # + # "Mentioned in #1" + # + # "Mentioned in !2" + # + # "Mentioned in 54f7727c" + # + # See cross_reference_note_content. + # + # Returns the created Note object + def self.cross_reference(noteable, mentioner, author) + return if cross_reference_disallowed?(noteable, mentioner) + + gfm_reference = mentioner_gfm_ref(noteable, mentioner) + + note_options = { + project: noteable.project, + author: author, + note: cross_reference_note_content(gfm_reference) + } + + if noteable.kind_of?(Commit) + note_options.merge!(noteable_type: 'Commit', commit_id: noteable.id) + else + note_options.merge!(noteable: noteable) + end + + create_note(note_options) + end + def self.cross_reference?(note_text) note_text.start_with?(cross_reference_note_prefix) end |