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

Rename `mentioner` to `mentioned_in`

parent ea2de445
......@@ -128,7 +128,7 @@ module Integrations
false
end
def create_cross_reference_note(external_issue, mentioner, author)
def create_cross_reference_note(external_issue, mentioned_in, author)
# implement inside child
end
......
......@@ -234,19 +234,19 @@ module Integrations
end
override :create_cross_reference_note
def create_cross_reference_note(external_issue, mentioner, author)
unless can_cross_reference?(mentioner)
return s_("JiraService|Events for %{noteable_model_name} are disabled.") % { noteable_model_name: mentioner.model_name.plural.humanize(capitalize: false) }
def create_cross_reference_note(external_issue, mentioned_in, author)
unless can_cross_reference?(mentioned_in)
return s_("JiraService|Events for %{noteable_model_name} are disabled.") % { noteable_model_name: mentioned_in.model_name.plural.humanize(capitalize: false) }
end
jira_issue = find_issue(external_issue.id)
return unless jira_issue.present?
mentioner_id = mentioner.respond_to?(:iid) ? mentioner.iid : mentioner.id
mentioner_type = mentionable_name(mentioner)
entity_url = build_entity_url(mentioner_type, mentioner_id)
entity_meta = build_entity_meta(mentioner)
mentioned_in_id = mentioned_in.respond_to?(:iid) ? mentioned_in.iid : mentioned_in.id
mentioned_in_type = mentionable_name(mentioned_in)
entity_url = build_entity_url(mentioned_in_type, mentioned_in_id)
entity_meta = build_entity_meta(mentioned_in)
data = {
user: {
......@@ -259,9 +259,9 @@ module Integrations
},
entity: {
id: entity_meta[:id],
name: mentioner_type.humanize.downcase,
name: mentioned_in_type.humanize.downcase,
url: entity_url,
title: mentioner.title,
title: mentioned_in.title,
description: entity_meta[:description],
branch: entity_meta[:branch]
}
......@@ -316,8 +316,8 @@ module Integrations
end
end
def can_cross_reference?(mentioner)
case mentioner
def can_cross_reference?(mentioned_in)
case mentioned_in
when Commit then commit_events
when MergeRequest then merge_requests_events
else true
......
......@@ -213,12 +213,12 @@ module SystemNoteService
::SystemNotes::MergeRequestsService.new(noteable: issue, project: project, author: author).new_merge_request(merge_request)
end
def cross_reference(mentioned, mentioner, author)
::SystemNotes::IssuablesService.new(noteable: mentioned, author: author).cross_reference(mentioner)
def cross_reference(mentioned, mentioned_in, author)
::SystemNotes::IssuablesService.new(noteable: mentioned, author: author).cross_reference(mentioned_in)
end
def cross_reference_exists?(mentioned, mentioner)
::SystemNotes::IssuablesService.new(noteable: mentioned).cross_reference_exists?(mentioner)
def cross_reference_exists?(mentioned, mentioned_in)
::SystemNotes::IssuablesService.new(noteable: mentioned).cross_reference_exists?(mentioned_in)
end
def change_task_status(noteable, project, author, new_task)
......@@ -249,8 +249,8 @@ module SystemNoteService
::SystemNotes::IssuablesService.new(noteable: issuable, project: issuable.project, author: author).discussion_lock
end
def cross_reference_disallowed?(mentioned, mentioner)
::SystemNotes::IssuablesService.new(noteable: mentioned).cross_reference_disallowed?(mentioner)
def cross_reference_disallowed?(mentioned, mentioned_in)
::SystemNotes::IssuablesService.new(noteable: mentioned).cross_reference_disallowed?(mentioned_in)
end
def zoom_link_added(issue, project, author)
......
......@@ -154,7 +154,7 @@ module SystemNotes
create_note(NoteSummary.new(noteable, project, author, body, action: 'description'))
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`).
#
# Example Note text:
......@@ -167,20 +167,20 @@ module SystemNotes
#
# See cross_reference_note_content.
#
# @param mentioner [Mentionable]
# @param mentioned_in [Mentionable]
# @return [Note]
def cross_reference(mentioner)
return if cross_reference_disallowed?(mentioner)
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,14 +195,14 @@ module SystemNotes
# in a merge request. Additionally, it prevents the creation of references to
# external issues (which would fail).
#
# @param mentioner [Mentionable]
# @param mentioned_in [Mentionable]
# @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 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
......@@ -308,18 +308,19 @@ module SystemNotes
create_resource_state_event(status: status, mentionable_source: source)
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
# 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.
#
# @param mentioner [Mentionable]
# @param mentioned_in [Mentionable]
# @return [Boolean]
def cross_reference_exists?(mentioner)
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
......@@ -396,12 +397,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
......
......@@ -62,9 +62,9 @@ RSpec.describe ::SystemNotes::IssuablesService do
end
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
let(:noteable) { epic }
......
......@@ -287,38 +287,38 @@ RSpec.describe SystemNoteService do
end
describe '.cross_reference' do
let(:mentioner) { double }
let(:mentioned_in) { double }
it 'calls IssuableService' do
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
described_class.cross_reference(double, mentioner, double)
described_class.cross_reference(double, mentioned_in, double)
end
end
describe '.cross_reference_disallowed?' do
let(:mentioner) { double }
let(:mentioned_in) { double }
it 'calls IssuableService' do
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
described_class.cross_reference_disallowed?(double, mentioner)
described_class.cross_reference_disallowed?(double, mentioned_in)
end
end
describe '.cross_reference_exists?' do
let(:mentioner) { double }
let(:mentioned_in) { double }
it 'calls IssuableService' do
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
described_class.cross_reference_exists?(double, mentioner)
described_class.cross_reference_exists?(double, mentioned_in)
end
end
......
......@@ -274,9 +274,9 @@ RSpec.describe ::SystemNotes::IssuablesService do
describe '#cross_reference' do
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
let(:action) { 'cross_reference' }
......@@ -314,35 +314,35 @@ RSpec.describe ::SystemNotes::IssuablesService do
describe 'note_body' do
context 'cross-project' do
let(:project2) { create(:project, :repository) }
let(:mentioner) { create(:issue, project: project2) }
let(:mentioned_in) { create(:issue, project: project2) }
context 'from Commit' do
let(:mentioner) { project2.repository.commit }
let(:mentioned_in) { project2.repository.commit }
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
context 'from non-Commit' 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
context 'within the same project' do
context 'from Commit' do
let(:mentioner) { project.repository.commit }
let(:mentioned_in) { project.repository.commit }
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
context 'from non-Commit' 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
......@@ -350,14 +350,14 @@ RSpec.describe ::SystemNotes::IssuablesService do
context 'with external issue' do
let(:noteable) { ExternalIssue.new('JIRA-123', project) }
let(:mentioner) { project.commit }
let(:mentioned_in) { project.commit }
it 'queues a background worker' do
expect(Integrations::CreateExternalCrossReferenceWorker).to receive(:perform_async).with(
project.id,
'JIRA-123',
'Commit',
mentioner.id,
mentioned_in.id,
author.id
)
......@@ -716,28 +716,28 @@ RSpec.describe ::SystemNotes::IssuablesService do
end
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
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
context 'when mentioner is a MergeRequest' do
let(:mentioner) { create(:merge_request, :simple, source_project: project) }
let(:noteable) { project.commit }
context 'when mentioned_in is a MergeRequest' do
let(:mentioned_in) { create(:merge_request, :simple, source_project: project) }
let(:noteable) { project.commit }
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
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
......
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