diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
commit | aee0a117a889461ce8ced6fcf73207fe017f1d99 (patch) | |
tree | 891d9ef189227a8445d83f35c1b0fc99573f4380 /app/services/system_notes | |
parent | 8d46af3258650d305f53b819eabf7ab18d22f59e (diff) |
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'app/services/system_notes')
-rw-r--r-- | app/services/system_notes/issuables_service.rb | 101 |
1 files changed, 65 insertions, 36 deletions
diff --git a/app/services/system_notes/issuables_service.rb b/app/services/system_notes/issuables_service.rb index 94629ae7609..d33dcd65589 100644 --- a/app/services/system_notes/issuables_service.rb +++ b/app/services/system_notes/issuables_service.rb @@ -154,9 +154,8 @@ module SystemNotes create_note(NoteSummary.new(noteable, project, author, body, action: 'description')) end - # Called when a Mentionable references a Noteable - # - # mentioner - Mentionable object + # Called when a Mentionable (the `mentioned_in`) references another Mentionable (the `mentioned`, + # passed to this service as `noteable`). # # Example Note text: # @@ -168,19 +167,20 @@ module SystemNotes # # See cross_reference_note_content. # - # Returns the created Note object - def cross_reference(mentioner) - return if cross_reference_disallowed?(mentioner) + # @param mentioned_in [Mentionable] + # @return [Note] + def cross_reference(mentioned_in) + return if cross_reference_disallowed?(mentioned_in) - gfm_reference = mentioner.gfm_reference(noteable.project || noteable.group) + gfm_reference = mentioned_in.gfm_reference(noteable.project || noteable.group) body = cross_reference_note_content(gfm_reference) if noteable.is_a?(ExternalIssue) Integrations::CreateExternalCrossReferenceWorker.perform_async( noteable.project_id, noteable.id, - mentioner.class.name, - mentioner.id, + mentioned_in.class.name, + mentioned_in.id, author.id ) else @@ -195,15 +195,14 @@ module SystemNotes # in a merge request. Additionally, it prevents the creation of references to # external issues (which would fail). # - # mentioner - Mentionable object - # - # Returns Boolean - def cross_reference_disallowed?(mentioner) + # @param mentioned_in [Mentionable] + # @return [Boolean] + def cross_reference_disallowed?(mentioned_in) return true if noteable.is_a?(ExternalIssue) && !noteable.project&.external_references_supported? - return false unless mentioner.is_a?(MergeRequest) + return false unless mentioned_in.is_a?(MergeRequest) return false unless noteable.is_a?(Commit) - mentioner.commits.include?(noteable) + mentioned_in.commits.include?(noteable) end # Called when the status of a Task has changed @@ -309,38 +308,49 @@ module SystemNotes create_resource_state_event(status: status, mentionable_source: source) end - # Check if a cross reference to a noteable from a mentioner already exists + # Check if a cross reference to a Mentionable from the `mentioned_in` Mentionable + # already exists. # # This method is used to prevent multiple notes being created for a mention - # when a issue is updated, for example. The method also calls notes_for_mentioner - # to check if the mentioner is a commit, and return matches only on commit hash + # when a issue is updated, for example. The method also calls `existing_mentions_for` + # to check if the mention is in a commit, and return matches only on commit hash # instead of project + commit, to avoid repeated mentions from forks. # - # mentioner - Mentionable object - # - # Returns Boolean - def cross_reference_exists?(mentioner) + # @param mentioned_in [Mentionable] + # @return [Boolean] + def cross_reference_exists?(mentioned_in) notes = noteable.notes.system - notes_for_mentioner(mentioner, noteable, notes).exists? + existing_mentions_for(mentioned_in, noteable, notes).exists? end - # Called when a Noteable has been marked as a duplicate of another Issue + # Called when a user's attention has been requested for a Notable # - # canonical_issue - Issue that this is a duplicate of + # user - User's whos attention has been requested # # Example Note text: # - # "marked this issue as a duplicate of #1234" - # - # "marked this issue as a duplicate of other_project#5678" + # "requested attention from @eli.wisoky" # # Returns the created Note object - def mark_duplicate_issue(canonical_issue) - body = "marked this issue as a duplicate of #{canonical_issue.to_reference(project)}" + def request_attention(user) + body = "requested attention from #{user.to_reference}" - issue_activity_counter.track_issue_marked_as_duplicate_action(author: author) if noteable.is_a?(Issue) + create_note(NoteSummary.new(noteable, project, author, body, action: 'attention_requested')) + end - create_note(NoteSummary.new(noteable, project, author, body, action: 'duplicate')) + # Called when a user's attention request has been removed for a Notable + # + # user - User's whos attention request has been removed + # + # Example Note text: + # + # "removed attention request from @eli.wisoky" + # + # Returns the created Note object + def remove_attention_request(user) + body = "removed attention request from #{user.to_reference}" + + create_note(NoteSummary.new(noteable, project, author, body, action: 'attention_request_removed')) end # Called when a Noteable has been marked as the canonical Issue of a duplicate @@ -359,6 +369,25 @@ module SystemNotes create_note(NoteSummary.new(noteable, project, author, body, action: 'duplicate')) end + # Called when a Noteable has been marked as a duplicate of another Issue + # + # canonical_issue - Issue that this is a duplicate of + # + # Example Note text: + # + # "marked this issue as a duplicate of #1234" + # + # "marked this issue as a duplicate of other_project#5678" + # + # Returns the created Note object + def mark_duplicate_issue(canonical_issue) + body = "marked this issue as a duplicate of #{canonical_issue.to_reference(project)}" + + issue_activity_counter.track_issue_marked_as_duplicate_action(author: author) if noteable.is_a?(Issue) + + create_note(NoteSummary.new(noteable, project, author, body, action: 'duplicate')) + end + def add_email_participants(body) create_note(NoteSummary.new(noteable, project, author, body)) end @@ -398,12 +427,12 @@ module SystemNotes "#{self.class.cross_reference_note_prefix}#{gfm_reference}" end - def notes_for_mentioner(mentioner, noteable, notes) - if mentioner.is_a?(Commit) - text = "#{self.class.cross_reference_note_prefix}%#{mentioner.to_reference(nil)}" + def existing_mentions_for(mentioned_in, noteable, notes) + if mentioned_in.is_a?(Commit) + text = "#{self.class.cross_reference_note_prefix}%#{mentioned_in.to_reference(nil)}" notes.like_note_or_capitalized_note(text) else - gfm_reference = mentioner.gfm_reference(noteable.project || noteable.group) + gfm_reference = mentioned_in.gfm_reference(noteable.project || noteable.group) text = cross_reference_note_content(gfm_reference) notes.for_note_or_capitalized_note(text) end |