Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
04cb4dc5
Commit
04cb4dc5
authored
Nov 22, 2021
by
Markus Koller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename `mentioner` to `mentioned_in`
parent
ea2de445
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
72 additions
and
71 deletions
+72
-71
app/models/integrations/base_issue_tracker.rb
app/models/integrations/base_issue_tracker.rb
+1
-1
app/models/integrations/jira.rb
app/models/integrations/jira.rb
+11
-11
app/services/system_note_service.rb
app/services/system_note_service.rb
+6
-6
app/services/system_notes/issuables_service.rb
app/services/system_notes/issuables_service.rb
+22
-21
ee/spec/services/ee/system_notes/issuables_service_spec.rb
ee/spec/services/ee/system_notes/issuables_service_spec.rb
+2
-2
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+9
-9
spec/services/system_notes/issuables_service_spec.rb
spec/services/system_notes/issuables_service_spec.rb
+21
-21
No files found.
app/models/integrations/base_issue_tracker.rb
View file @
04cb4dc5
...
...
@@ -128,7 +128,7 @@ module Integrations
false
end
def
create_cross_reference_note
(
external_issue
,
mentione
r
,
author
)
def
create_cross_reference_note
(
external_issue
,
mentione
d_in
,
author
)
# implement inside child
end
...
...
app/models/integrations/jira.rb
View file @
04cb4dc5
...
...
@@ -234,19 +234,19 @@ module Integrations
end
override
:create_cross_reference_note
def
create_cross_reference_note
(
external_issue
,
mentione
r
,
author
)
unless
can_cross_reference?
(
mentione
r
)
return
s_
(
"JiraService|Events for %{noteable_model_name} are disabled."
)
%
{
noteable_model_name:
mentione
r
.
model_name
.
plural
.
humanize
(
capitalize:
false
)
}
def
create_cross_reference_note
(
external_issue
,
mentione
d_in
,
author
)
unless
can_cross_reference?
(
mentione
d_in
)
return
s_
(
"JiraService|Events for %{noteable_model_name} are disabled."
)
%
{
noteable_model_name:
mentione
d_in
.
model_name
.
plural
.
humanize
(
capitalize:
false
)
}
end
jira_issue
=
find_issue
(
external_issue
.
id
)
return
unless
jira_issue
.
present?
mentione
r_id
=
mentioner
.
respond_to?
(
:iid
)
?
mentioner
.
iid
:
mentioner
.
id
mentione
r_type
=
mentionable_name
(
mentioner
)
entity_url
=
build_entity_url
(
mentione
r_type
,
mentioner
_id
)
entity_meta
=
build_entity_meta
(
mentione
r
)
mentione
d_in_id
=
mentioned_in
.
respond_to?
(
:iid
)
?
mentioned_in
.
iid
:
mentioned_in
.
id
mentione
d_in_type
=
mentionable_name
(
mentioned_in
)
entity_url
=
build_entity_url
(
mentione
d_in_type
,
mentioned_in
_id
)
entity_meta
=
build_entity_meta
(
mentione
d_in
)
data
=
{
user:
{
...
...
@@ -259,9 +259,9 @@ module Integrations
},
entity:
{
id:
entity_meta
[
:id
],
name:
mentione
r
_type
.
humanize
.
downcase
,
name:
mentione
d_in
_type
.
humanize
.
downcase
,
url:
entity_url
,
title:
mentione
r
.
title
,
title:
mentione
d_in
.
title
,
description:
entity_meta
[
:description
],
branch:
entity_meta
[
:branch
]
}
...
...
@@ -316,8 +316,8 @@ module Integrations
end
end
def
can_cross_reference?
(
mentione
r
)
case
mentione
r
def
can_cross_reference?
(
mentione
d_in
)
case
mentione
d_in
when
Commit
then
commit_events
when
MergeRequest
then
merge_requests_events
else
true
...
...
app/services/system_note_service.rb
View file @
04cb4dc5
...
...
@@ -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
,
mentione
r
,
author
)
::
SystemNotes
::
IssuablesService
.
new
(
noteable:
mentioned
,
author:
author
).
cross_reference
(
mentione
r
)
def
cross_reference
(
mentioned
,
mentione
d_in
,
author
)
::
SystemNotes
::
IssuablesService
.
new
(
noteable:
mentioned
,
author:
author
).
cross_reference
(
mentione
d_in
)
end
def
cross_reference_exists?
(
mentioned
,
mentione
r
)
::
SystemNotes
::
IssuablesService
.
new
(
noteable:
mentioned
).
cross_reference_exists?
(
mentione
r
)
def
cross_reference_exists?
(
mentioned
,
mentione
d_in
)
::
SystemNotes
::
IssuablesService
.
new
(
noteable:
mentioned
).
cross_reference_exists?
(
mentione
d_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
,
mentione
r
)
::
SystemNotes
::
IssuablesService
.
new
(
noteable:
mentioned
).
cross_reference_disallowed?
(
mentione
r
)
def
cross_reference_disallowed?
(
mentioned
,
mentione
d_in
)
::
SystemNotes
::
IssuablesService
.
new
(
noteable:
mentioned
).
cross_reference_disallowed?
(
mentione
d_in
)
end
def
zoom_link_added
(
issue
,
project
,
author
)
...
...
app/services/system_notes/issuables_service.rb
View file @
04cb4dc5
...
...
@@ -154,7 +154,7 @@ module SystemNotes
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'description'
))
end
# Called when a Mentionable (the `mentione
r
`) references another Mentionable (the `mentioned`,
# Called when a Mentionable (the `mentione
d_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 mentione
r
[Mentionable]
# @param mentione
d_in
[Mentionable]
# @return [Note]
def
cross_reference
(
mentione
r
)
return
if
cross_reference_disallowed?
(
mentione
r
)
def
cross_reference
(
mentione
d_in
)
return
if
cross_reference_disallowed?
(
mentione
d_in
)
gfm_reference
=
mentione
r
.
gfm_reference
(
noteable
.
project
||
noteable
.
group
)
gfm_reference
=
mentione
d_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
,
mentione
r
.
class
.
name
,
mentione
r
.
id
,
mentione
d_in
.
class
.
name
,
mentione
d_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 mentione
r
[Mentionable]
# @param mentione
d_in
[Mentionable]
# @return [Boolean]
def
cross_reference_disallowed?
(
mentione
r
)
def
cross_reference_disallowed?
(
mentione
d_in
)
return
true
if
noteable
.
is_a?
(
ExternalIssue
)
&&
!
noteable
.
project
&
.
external_references_supported?
return
false
unless
mentione
r
.
is_a?
(
MergeRequest
)
return
false
unless
mentione
d_in
.
is_a?
(
MergeRequest
)
return
false
unless
noteable
.
is_a?
(
Commit
)
mentione
r
.
commits
.
include?
(
noteable
)
mentione
d_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 mention
er 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 mentione
r
[Mentionable]
# @param mentione
d_in
[Mentionable]
# @return [Boolean]
def
cross_reference_exists?
(
mentione
r
)
def
cross_reference_exists?
(
mentione
d_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
mentione
r
.
is_a?
(
Commit
)
text
=
"
#{
self
.
class
.
cross_reference_note_prefix
}
%
#{
mentione
r
.
to_reference
(
nil
)
}
"
def
existing_mentions_for
(
mentioned_in
,
noteable
,
notes
)
if
mentione
d_in
.
is_a?
(
Commit
)
text
=
"
#{
self
.
class
.
cross_reference_note_prefix
}
%
#{
mentione
d_in
.
to_reference
(
nil
)
}
"
notes
.
like_note_or_capitalized_note
(
text
)
else
gfm_reference
=
mentione
r
.
gfm_reference
(
noteable
.
project
||
noteable
.
group
)
gfm_reference
=
mentione
d_in
.
gfm_reference
(
noteable
.
project
||
noteable
.
group
)
text
=
cross_reference_note_content
(
gfm_reference
)
notes
.
for_note_or_capitalized_note
(
text
)
end
...
...
ee/spec/services/ee/system_notes/issuables_service_spec.rb
View file @
04cb4dc5
...
...
@@ -62,9 +62,9 @@ RSpec.describe ::SystemNotes::IssuablesService do
end
describe
'#cross_reference'
do
let
(
:mentione
r
)
{
create
(
:issue
,
project:
project
)
}
let
(
:mentione
d_in
)
{
create
(
:issue
,
project:
project
)
}
subject
{
service
.
cross_reference
(
mentione
r
)
}
subject
{
service
.
cross_reference
(
mentione
d_in
)
}
context
'when noteable is an epic'
do
let
(
:noteable
)
{
epic
}
...
...
spec/services/system_note_service_spec.rb
View file @
04cb4dc5
...
...
@@ -287,38 +287,38 @@ RSpec.describe SystemNoteService do
end
describe
'.cross_reference'
do
let
(
:mentione
r
)
{
double
}
let
(
:mentione
d_in
)
{
double
}
it
'calls IssuableService'
do
expect_next_instance_of
(
::
SystemNotes
::
IssuablesService
)
do
|
service
|
expect
(
service
).
to
receive
(
:cross_reference
).
with
(
mentione
r
)
expect
(
service
).
to
receive
(
:cross_reference
).
with
(
mentione
d_in
)
end
described_class
.
cross_reference
(
double
,
mentione
r
,
double
)
described_class
.
cross_reference
(
double
,
mentione
d_in
,
double
)
end
end
describe
'.cross_reference_disallowed?'
do
let
(
:mentione
r
)
{
double
}
let
(
:mentione
d_in
)
{
double
}
it
'calls IssuableService'
do
expect_next_instance_of
(
::
SystemNotes
::
IssuablesService
)
do
|
service
|
expect
(
service
).
to
receive
(
:cross_reference_disallowed?
).
with
(
mentione
r
)
expect
(
service
).
to
receive
(
:cross_reference_disallowed?
).
with
(
mentione
d_in
)
end
described_class
.
cross_reference_disallowed?
(
double
,
mentione
r
)
described_class
.
cross_reference_disallowed?
(
double
,
mentione
d_in
)
end
end
describe
'.cross_reference_exists?'
do
let
(
:mentione
r
)
{
double
}
let
(
:mentione
d_in
)
{
double
}
it
'calls IssuableService'
do
expect_next_instance_of
(
::
SystemNotes
::
IssuablesService
)
do
|
service
|
expect
(
service
).
to
receive
(
:cross_reference_exists?
).
with
(
mentione
r
)
expect
(
service
).
to
receive
(
:cross_reference_exists?
).
with
(
mentione
d_in
)
end
described_class
.
cross_reference_exists?
(
double
,
mentione
r
)
described_class
.
cross_reference_exists?
(
double
,
mentione
d_in
)
end
end
...
...
spec/services/system_notes/issuables_service_spec.rb
View file @
04cb4dc5
...
...
@@ -274,9 +274,9 @@ RSpec.describe ::SystemNotes::IssuablesService do
describe
'#cross_reference'
do
let
(
:service
)
{
described_class
.
new
(
noteable:
noteable
,
author:
author
)
}
let
(
:mentione
r
)
{
create
(
:issue
,
project:
project
)
}
let
(
:mentione
d_in
)
{
create
(
:issue
,
project:
project
)
}
subject
{
service
.
cross_reference
(
mentione
r
)
}
subject
{
service
.
cross_reference
(
mentione
d_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
(
:mentione
r
)
{
create
(
:issue
,
project:
project2
)
}
let
(
:mentione
d_in
)
{
create
(
:issue
,
project:
project2
)
}
context
'from Commit'
do
let
(
:mentione
r
)
{
project2
.
repository
.
commit
}
let
(
:mentione
d_in
)
{
project2
.
repository
.
commit
}
it
'references the mentioning commit'
do
expect
(
subject
.
note
).
to
eq
"mentioned in commit
#{
mentione
r
.
to_reference
(
project
)
}
"
expect
(
subject
.
note
).
to
eq
"mentioned in commit
#{
mentione
d_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
#{
mentione
r
.
to_reference
(
project
)
}
"
expect
(
subject
.
note
).
to
eq
"mentioned in issue
#{
mentione
d_in
.
to_reference
(
project
)
}
"
end
end
end
context
'within the same project'
do
context
'from Commit'
do
let
(
:mentione
r
)
{
project
.
repository
.
commit
}
let
(
:mentione
d_in
)
{
project
.
repository
.
commit
}
it
'references the mentioning commit'
do
expect
(
subject
.
note
).
to
eq
"mentioned in commit
#{
mentione
r
.
to_reference
}
"
expect
(
subject
.
note
).
to
eq
"mentioned in commit
#{
mentione
d_in
.
to_reference
}
"
end
end
context
'from non-Commit'
do
it
'references the mentioning object'
do
expect
(
subject
.
note
).
to
eq
"mentioned in issue
#{
mentione
r
.
to_reference
}
"
expect
(
subject
.
note
).
to
eq
"mentioned in issue
#{
mentione
d_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
(
:mentione
r
)
{
project
.
commit
}
let
(
:mentione
d_in
)
{
project
.
commit
}
it
'queues a background worker'
do
expect
(
Integrations
::
CreateExternalCrossReferenceWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
'JIRA-123'
,
'Commit'
,
mentione
r
.
id
,
mentione
d_in
.
id
,
author
.
id
)
...
...
@@ -716,28 +716,28 @@ RSpec.describe ::SystemNotes::IssuablesService do
end
describe
'#cross_reference_disallowed?'
do
context
'when mentione
r
is not a MergeRequest'
do
context
'when mentione
d_in
is not a MergeRequest'
do
it
'is falsey'
do
mentione
r
=
noteable
.
dup
mentione
d_in
=
noteable
.
dup
expect
(
service
.
cross_reference_disallowed?
(
mentione
r
)).
to
be_falsey
expect
(
service
.
cross_reference_disallowed?
(
mentione
d_in
)).
to
be_falsey
end
end
context
'when mentione
r
is a MergeRequest'
do
let
(
:mentione
r
)
{
create
(
:merge_request
,
:simple
,
source_project:
project
)
}
let
(
:noteable
)
{
project
.
commit
}
context
'when mentione
d_in
is a MergeRequest'
do
let
(
:mentione
d_in
)
{
create
(
:merge_request
,
:simple
,
source_project:
project
)
}
let
(
:noteable
)
{
project
.
commit
}
it
'is truthy when noteable is in commits'
do
expect
(
mentione
r
).
to
receive
(
:commits
).
and_return
([
noteable
])
expect
(
mentione
d_in
).
to
receive
(
:commits
).
and_return
([
noteable
])
expect
(
service
.
cross_reference_disallowed?
(
mentione
r
)).
to
be_truthy
expect
(
service
.
cross_reference_disallowed?
(
mentione
d_in
)).
to
be_truthy
end
it
'is falsey when noteable is not in commits'
do
expect
(
mentione
r
).
to
receive
(
:commits
).
and_return
([])
expect
(
mentione
d_in
).
to
receive
(
:commits
).
and_return
([])
expect
(
service
.
cross_reference_disallowed?
(
mentione
r
)).
to
be_falsey
expect
(
service
.
cross_reference_disallowed?
(
mentione
d_in
)).
to
be_falsey
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment