Commit 04cb4dc5 authored by Markus Koller's avatar Markus Koller

Rename `mentioner` to `mentioned_in`

parent ea2de445
...@@ -128,7 +128,7 @@ module Integrations ...@@ -128,7 +128,7 @@ module Integrations
false false
end end
def create_cross_reference_note(external_issue, mentioner, author) def create_cross_reference_note(external_issue, mentioned_in, author)
# implement inside child # implement inside child
end end
......
...@@ -234,19 +234,19 @@ module Integrations ...@@ -234,19 +234,19 @@ module Integrations
end end
override :create_cross_reference_note override :create_cross_reference_note
def create_cross_reference_note(external_issue, mentioner, author) def create_cross_reference_note(external_issue, mentioned_in, author)
unless can_cross_reference?(mentioner) unless can_cross_reference?(mentioned_in)
return s_("JiraService|Events for %{noteable_model_name} are disabled.") % { noteable_model_name: mentioner.model_name.plural.humanize(capitalize: false) } return s_("JiraService|Events for %{noteable_model_name} are disabled.") % { noteable_model_name: mentioned_in.model_name.plural.humanize(capitalize: false) }
end end
jira_issue = find_issue(external_issue.id) jira_issue = find_issue(external_issue.id)
return unless jira_issue.present? return unless jira_issue.present?
mentioner_id = mentioner.respond_to?(:iid) ? mentioner.iid : mentioner.id mentioned_in_id = mentioned_in.respond_to?(:iid) ? mentioned_in.iid : mentioned_in.id
mentioner_type = mentionable_name(mentioner) mentioned_in_type = mentionable_name(mentioned_in)
entity_url = build_entity_url(mentioner_type, mentioner_id) entity_url = build_entity_url(mentioned_in_type, mentioned_in_id)
entity_meta = build_entity_meta(mentioner) entity_meta = build_entity_meta(mentioned_in)
data = { data = {
user: { user: {
...@@ -259,9 +259,9 @@ module Integrations ...@@ -259,9 +259,9 @@ module Integrations
}, },
entity: { entity: {
id: entity_meta[:id], id: entity_meta[:id],
name: mentioner_type.humanize.downcase, name: mentioned_in_type.humanize.downcase,
url: entity_url, url: entity_url,
title: mentioner.title, title: mentioned_in.title,
description: entity_meta[:description], description: entity_meta[:description],
branch: entity_meta[:branch] branch: entity_meta[:branch]
} }
...@@ -316,8 +316,8 @@ module Integrations ...@@ -316,8 +316,8 @@ module Integrations
end end
end end
def can_cross_reference?(mentioner) def can_cross_reference?(mentioned_in)
case mentioner case mentioned_in
when Commit then commit_events when Commit then commit_events
when MergeRequest then merge_requests_events when MergeRequest then merge_requests_events
else true else true
......
...@@ -213,12 +213,12 @@ module SystemNoteService ...@@ -213,12 +213,12 @@ module SystemNoteService
::SystemNotes::MergeRequestsService.new(noteable: issue, project: project, author: author).new_merge_request(merge_request) ::SystemNotes::MergeRequestsService.new(noteable: issue, project: project, author: author).new_merge_request(merge_request)
end end
def cross_reference(mentioned, mentioner, author) def cross_reference(mentioned, mentioned_in, author)
::SystemNotes::IssuablesService.new(noteable: mentioned, author: author).cross_reference(mentioner) ::SystemNotes::IssuablesService.new(noteable: mentioned, author: author).cross_reference(mentioned_in)
end end
def cross_reference_exists?(mentioned, mentioner) def cross_reference_exists?(mentioned, mentioned_in)
::SystemNotes::IssuablesService.new(noteable: mentioned).cross_reference_exists?(mentioner) ::SystemNotes::IssuablesService.new(noteable: mentioned).cross_reference_exists?(mentioned_in)
end end
def change_task_status(noteable, project, author, new_task) def change_task_status(noteable, project, author, new_task)
...@@ -249,8 +249,8 @@ module SystemNoteService ...@@ -249,8 +249,8 @@ module SystemNoteService
::SystemNotes::IssuablesService.new(noteable: issuable, project: issuable.project, author: author).discussion_lock ::SystemNotes::IssuablesService.new(noteable: issuable, project: issuable.project, author: author).discussion_lock
end end
def cross_reference_disallowed?(mentioned, mentioner) def cross_reference_disallowed?(mentioned, mentioned_in)
::SystemNotes::IssuablesService.new(noteable: mentioned).cross_reference_disallowed?(mentioner) ::SystemNotes::IssuablesService.new(noteable: mentioned).cross_reference_disallowed?(mentioned_in)
end end
def zoom_link_added(issue, project, author) def zoom_link_added(issue, project, author)
......
...@@ -154,7 +154,7 @@ module SystemNotes ...@@ -154,7 +154,7 @@ module SystemNotes
create_note(NoteSummary.new(noteable, project, author, body, action: 'description')) create_note(NoteSummary.new(noteable, project, author, body, action: 'description'))
end end
# Called when a Mentionable (the `mentioner`) references another Mentionable (the `mentioned`, # Called when a Mentionable (the `mentioned_in`) references another Mentionable (the `mentioned`,
# passed to this service as `noteable`). # passed to this service as `noteable`).
# #
# Example Note text: # Example Note text:
...@@ -167,20 +167,20 @@ module SystemNotes ...@@ -167,20 +167,20 @@ module SystemNotes
# #
# See cross_reference_note_content. # See cross_reference_note_content.
# #
# @param mentioner [Mentionable] # @param mentioned_in [Mentionable]
# @return [Note] # @return [Note]
def cross_reference(mentioner) def cross_reference(mentioned_in)
return if cross_reference_disallowed?(mentioner) 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) body = cross_reference_note_content(gfm_reference)
if noteable.is_a?(ExternalIssue) if noteable.is_a?(ExternalIssue)
Integrations::CreateExternalCrossReferenceWorker.perform_async( Integrations::CreateExternalCrossReferenceWorker.perform_async(
noteable.project_id, noteable.project_id,
noteable.id, noteable.id,
mentioner.class.name, mentioned_in.class.name,
mentioner.id, mentioned_in.id,
author.id author.id
) )
else else
...@@ -195,14 +195,14 @@ module SystemNotes ...@@ -195,14 +195,14 @@ module SystemNotes
# in a merge request. Additionally, it prevents the creation of references to # in a merge request. Additionally, it prevents the creation of references to
# external issues (which would fail). # external issues (which would fail).
# #
# @param mentioner [Mentionable] # @param mentioned_in [Mentionable]
# @return [Boolean] # @return [Boolean]
def cross_reference_disallowed?(mentioner) def cross_reference_disallowed?(mentioned_in)
return true if noteable.is_a?(ExternalIssue) && !noteable.project&.external_references_supported? 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) return false unless noteable.is_a?(Commit)
mentioner.commits.include?(noteable) mentioned_in.commits.include?(noteable)
end end
# Called when the status of a Task has changed # Called when the status of a Task has changed
...@@ -308,18 +308,19 @@ module SystemNotes ...@@ -308,18 +308,19 @@ module SystemNotes
create_resource_state_event(status: status, mentionable_source: source) create_resource_state_event(status: status, mentionable_source: source)
end end
# Check if a cross reference to a Mentionable 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 # 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 # when a issue is updated, for example. The method also calls `existing_mentions_for`
# to check if the mentioner is a commit, and return matches only on commit hash # 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. # instead of project + commit, to avoid repeated mentions from forks.
# #
# @param mentioner [Mentionable] # @param mentioned_in [Mentionable]
# @return [Boolean] # @return [Boolean]
def cross_reference_exists?(mentioner) def cross_reference_exists?(mentioned_in)
notes = noteable.notes.system notes = noteable.notes.system
notes_for_mentioner(mentioner, noteable, notes).exists? existing_mentions_for(mentioned_in, noteable, notes).exists?
end end
# Called when a Noteable has been marked as a duplicate of another Issue # Called when a Noteable has been marked as a duplicate of another Issue
...@@ -396,12 +397,12 @@ module SystemNotes ...@@ -396,12 +397,12 @@ module SystemNotes
"#{self.class.cross_reference_note_prefix}#{gfm_reference}" "#{self.class.cross_reference_note_prefix}#{gfm_reference}"
end end
def notes_for_mentioner(mentioner, noteable, notes) def existing_mentions_for(mentioned_in, noteable, notes)
if mentioner.is_a?(Commit) if mentioned_in.is_a?(Commit)
text = "#{self.class.cross_reference_note_prefix}%#{mentioner.to_reference(nil)}" text = "#{self.class.cross_reference_note_prefix}%#{mentioned_in.to_reference(nil)}"
notes.like_note_or_capitalized_note(text) notes.like_note_or_capitalized_note(text)
else 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) text = cross_reference_note_content(gfm_reference)
notes.for_note_or_capitalized_note(text) notes.for_note_or_capitalized_note(text)
end end
......
...@@ -62,9 +62,9 @@ RSpec.describe ::SystemNotes::IssuablesService do ...@@ -62,9 +62,9 @@ RSpec.describe ::SystemNotes::IssuablesService do
end end
describe '#cross_reference' do describe '#cross_reference' do
let(:mentioner) { create(:issue, project: project) } let(:mentioned_in) { create(:issue, project: project) }
subject { service.cross_reference(mentioner) } subject { service.cross_reference(mentioned_in) }
context 'when noteable is an epic' do context 'when noteable is an epic' do
let(:noteable) { epic } let(:noteable) { epic }
......
...@@ -287,38 +287,38 @@ RSpec.describe SystemNoteService do ...@@ -287,38 +287,38 @@ RSpec.describe SystemNoteService do
end end
describe '.cross_reference' do describe '.cross_reference' do
let(:mentioner) { double } let(:mentioned_in) { double }
it 'calls IssuableService' do it 'calls IssuableService' do
expect_next_instance_of(::SystemNotes::IssuablesService) do |service| expect_next_instance_of(::SystemNotes::IssuablesService) do |service|
expect(service).to receive(:cross_reference).with(mentioner) expect(service).to receive(:cross_reference).with(mentioned_in)
end end
described_class.cross_reference(double, mentioner, double) described_class.cross_reference(double, mentioned_in, double)
end end
end end
describe '.cross_reference_disallowed?' do describe '.cross_reference_disallowed?' do
let(:mentioner) { double } let(:mentioned_in) { double }
it 'calls IssuableService' do it 'calls IssuableService' do
expect_next_instance_of(::SystemNotes::IssuablesService) do |service| expect_next_instance_of(::SystemNotes::IssuablesService) do |service|
expect(service).to receive(:cross_reference_disallowed?).with(mentioner) expect(service).to receive(:cross_reference_disallowed?).with(mentioned_in)
end end
described_class.cross_reference_disallowed?(double, mentioner) described_class.cross_reference_disallowed?(double, mentioned_in)
end end
end end
describe '.cross_reference_exists?' do describe '.cross_reference_exists?' do
let(:mentioner) { double } let(:mentioned_in) { double }
it 'calls IssuableService' do it 'calls IssuableService' do
expect_next_instance_of(::SystemNotes::IssuablesService) do |service| expect_next_instance_of(::SystemNotes::IssuablesService) do |service|
expect(service).to receive(:cross_reference_exists?).with(mentioner) expect(service).to receive(:cross_reference_exists?).with(mentioned_in)
end end
described_class.cross_reference_exists?(double, mentioner) described_class.cross_reference_exists?(double, mentioned_in)
end end
end end
......
...@@ -274,9 +274,9 @@ RSpec.describe ::SystemNotes::IssuablesService do ...@@ -274,9 +274,9 @@ RSpec.describe ::SystemNotes::IssuablesService do
describe '#cross_reference' do describe '#cross_reference' do
let(:service) { described_class.new(noteable: noteable, author: author) } let(:service) { described_class.new(noteable: noteable, author: author) }
let(:mentioner) { create(:issue, project: project) } let(:mentioned_in) { create(:issue, project: project) }
subject { service.cross_reference(mentioner) } subject { service.cross_reference(mentioned_in) }
it_behaves_like 'a system note' do it_behaves_like 'a system note' do
let(:action) { 'cross_reference' } let(:action) { 'cross_reference' }
...@@ -314,35 +314,35 @@ RSpec.describe ::SystemNotes::IssuablesService do ...@@ -314,35 +314,35 @@ RSpec.describe ::SystemNotes::IssuablesService do
describe 'note_body' do describe 'note_body' do
context 'cross-project' do context 'cross-project' do
let(:project2) { create(:project, :repository) } let(:project2) { create(:project, :repository) }
let(:mentioner) { create(:issue, project: project2) } let(:mentioned_in) { create(:issue, project: project2) }
context 'from Commit' do context 'from Commit' do
let(:mentioner) { project2.repository.commit } let(:mentioned_in) { project2.repository.commit }
it 'references the mentioning commit' do it 'references the mentioning commit' do
expect(subject.note).to eq "mentioned in commit #{mentioner.to_reference(project)}" expect(subject.note).to eq "mentioned in commit #{mentioned_in.to_reference(project)}"
end end
end end
context 'from non-Commit' do context 'from non-Commit' do
it 'references the mentioning object' do it 'references the mentioning object' do
expect(subject.note).to eq "mentioned in issue #{mentioner.to_reference(project)}" expect(subject.note).to eq "mentioned in issue #{mentioned_in.to_reference(project)}"
end end
end end
end end
context 'within the same project' do context 'within the same project' do
context 'from Commit' do context 'from Commit' do
let(:mentioner) { project.repository.commit } let(:mentioned_in) { project.repository.commit }
it 'references the mentioning commit' do it 'references the mentioning commit' do
expect(subject.note).to eq "mentioned in commit #{mentioner.to_reference}" expect(subject.note).to eq "mentioned in commit #{mentioned_in.to_reference}"
end end
end end
context 'from non-Commit' do context 'from non-Commit' do
it 'references the mentioning object' do it 'references the mentioning object' do
expect(subject.note).to eq "mentioned in issue #{mentioner.to_reference}" expect(subject.note).to eq "mentioned in issue #{mentioned_in.to_reference}"
end end
end end
end end
...@@ -350,14 +350,14 @@ RSpec.describe ::SystemNotes::IssuablesService do ...@@ -350,14 +350,14 @@ RSpec.describe ::SystemNotes::IssuablesService do
context 'with external issue' do context 'with external issue' do
let(:noteable) { ExternalIssue.new('JIRA-123', project) } let(:noteable) { ExternalIssue.new('JIRA-123', project) }
let(:mentioner) { project.commit } let(:mentioned_in) { project.commit }
it 'queues a background worker' do it 'queues a background worker' do
expect(Integrations::CreateExternalCrossReferenceWorker).to receive(:perform_async).with( expect(Integrations::CreateExternalCrossReferenceWorker).to receive(:perform_async).with(
project.id, project.id,
'JIRA-123', 'JIRA-123',
'Commit', 'Commit',
mentioner.id, mentioned_in.id,
author.id author.id
) )
...@@ -716,28 +716,28 @@ RSpec.describe ::SystemNotes::IssuablesService do ...@@ -716,28 +716,28 @@ RSpec.describe ::SystemNotes::IssuablesService do
end end
describe '#cross_reference_disallowed?' do describe '#cross_reference_disallowed?' do
context 'when mentioner is not a MergeRequest' do context 'when mentioned_in is not a MergeRequest' do
it 'is falsey' do it 'is falsey' do
mentioner = noteable.dup mentioned_in = noteable.dup
expect(service.cross_reference_disallowed?(mentioner)).to be_falsey expect(service.cross_reference_disallowed?(mentioned_in)).to be_falsey
end end
end end
context 'when mentioner is a MergeRequest' do context 'when mentioned_in is a MergeRequest' do
let(:mentioner) { create(:merge_request, :simple, source_project: project) } let(:mentioned_in) { create(:merge_request, :simple, source_project: project) }
let(:noteable) { project.commit } let(:noteable) { project.commit }
it 'is truthy when noteable is in commits' do it 'is truthy when noteable is in commits' do
expect(mentioner).to receive(:commits).and_return([noteable]) expect(mentioned_in).to receive(:commits).and_return([noteable])
expect(service.cross_reference_disallowed?(mentioner)).to be_truthy expect(service.cross_reference_disallowed?(mentioned_in)).to be_truthy
end end
it 'is falsey when noteable is not in commits' do it 'is falsey when noteable is not in commits' do
expect(mentioner).to receive(:commits).and_return([]) expect(mentioned_in).to receive(:commits).and_return([])
expect(service.cross_reference_disallowed?(mentioner)).to be_falsey expect(service.cross_reference_disallowed?(mentioned_in)).to be_falsey
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