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
3cb6a338
Commit
3cb6a338
authored
May 26, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More SystemNoteService cleanup
parent
2c1bf717
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
46 deletions
+22
-46
app/models/concerns/mentionable.rb
app/models/concerns/mentionable.rb
+2
-2
app/models/note.rb
app/models/note.rb
+2
-2
app/services/system_note_service.rb
app/services/system_note_service.rb
+18
-42
No files found.
app/models/concerns/mentionable.rb
View file @
3cb6a338
...
...
@@ -24,11 +24,11 @@ module Mentionable
#
# By default this will be the class name and the result of calling
# `to_reference` on the object.
def
gfm_reference
def
gfm_reference
(
from_project
=
nil
)
# "MergeRequest" > "merge_request" > "Merge request" > "merge request"
friendly_name
=
self
.
class
.
to_s
.
underscore
.
humanize
.
downcase
"
#{
friendly_name
}
#{
to_reference
}
"
"
#{
friendly_name
}
#{
to_reference
(
from_project
)
}
"
end
# Construct a String that contains possible GFM references.
...
...
app/models/note.rb
View file @
3cb6a338
...
...
@@ -326,8 +326,8 @@ class Note < ActiveRecord::Base
end
# Mentionable override.
def
gfm_reference
noteable
.
gfm_reference
def
gfm_reference
(
from_project
=
nil
)
noteable
.
gfm_reference
(
from_project
)
end
# Mentionable override.
...
...
app/services/system_note_service.rb
View file @
3cb6a338
...
...
@@ -10,7 +10,7 @@ class SystemNoteService
# 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
# oldrev -
Optional String SHA of a previous Commit
#
# See new_commit_summary and existing_commit_summary.
#
...
...
@@ -138,11 +138,11 @@ class SystemNoteService
#
# Example Note text:
#
# "
M
entioned in #1"
# "
m
entioned in #1"
#
# "
M
entioned in !2"
# "
m
entioned in !2"
#
# "
M
entioned in 54f7727c"
# "
m
entioned in 54f7727c"
#
# See cross_reference_note_content.
#
...
...
@@ -150,7 +150,7 @@ class SystemNoteService
def
self
.
cross_reference
(
noteable
,
mentioner
,
author
)
return
if
cross_reference_disallowed?
(
noteable
,
mentioner
)
gfm_reference
=
mentioner
_gfm_ref
(
noteable
,
mentioner
)
gfm_reference
=
mentioner
.
gfm_reference
(
noteable
.
project
)
note_options
=
{
project:
noteable
.
project
,
...
...
@@ -181,12 +181,21 @@ class SystemNoteService
#
# Returns Boolean
def
self
.
cross_reference_disallowed?
(
noteable
,
mentioner
)
return
false
unless
MergeRequest
===
mentioner
return
false
unless
Commit
===
noteable
return
false
unless
mentioner
.
is_a?
(
MergeRequest
)
return
false
unless
noteable
.
is_a?
(
Commit
)
mentioner
.
commits
.
include?
(
noteable
)
end
# Check if a cross reference to a noteable from a mentioner already exists
#
# This method is used to prevent multiple notes being created for a mention
# when a issue is updated, for example.
#
# noteable - Noteable object being referenced
# mentioner - Mentionable object
#
# Returns Boolean
def
self
.
cross_reference_exists?
(
noteable
,
mentioner
)
# Initial scope should be system notes of this noteable type
notes
=
Note
.
system
.
where
(
noteable_type:
noteable
.
class
)
...
...
@@ -198,7 +207,7 @@ class SystemNoteService
notes
=
notes
.
where
(
noteable_id:
noteable
.
id
)
end
gfm_reference
=
mentioner
_gfm_ref
(
noteable
,
mentioner
,
true
)
gfm_reference
=
mentioner
.
gfm_reference
(
noteable
.
project
)
notes
=
notes
.
where
(
note:
cross_reference_note_content
(
gfm_reference
))
notes
.
count
>
0
...
...
@@ -210,39 +219,6 @@ class SystemNoteService
Note
.
create
(
args
.
merge
(
system:
true
))
end
# Prepend the mentioner's namespaced project path to the GFM reference for
# cross-project references. For same-project references, return the
# unmodified GFM reference.
def
self
.
mentioner_gfm_ref
(
noteable
,
mentioner
,
cross_reference
=
false
)
# FIXME (rspeicher): This was breaking things.
# if mentioner.is_a?(Commit) && cross_reference
# return mentioner.gfm_reference.sub('commit ', 'commit %')
# end
full_gfm_reference
(
mentioner
.
project
,
noteable
.
project
,
mentioner
)
end
# Return the +mentioner+ GFM reference. If the mentioner and noteable
# projects are not the same, add the mentioning project's path to the
# returned value.
def
self
.
full_gfm_reference
(
mentioning_project
,
noteable_project
,
mentioner
)
if
mentioning_project
==
noteable_project
mentioner
.
gfm_reference
else
if
mentioner
.
is_a?
(
Commit
)
mentioner
.
gfm_reference
.
sub
(
/(commit )/
,
"
\\
1
#{
mentioning_project
.
path_with_namespace
}
@"
)
else
mentioner
.
gfm_reference
.
sub
(
/(issue |merge request )/
,
"
\\
1
#{
mentioning_project
.
path_with_namespace
}
"
)
end
end
end
def
self
.
cross_reference_note_prefix
'mentioned in '
end
...
...
@@ -267,7 +243,7 @@ class SystemNoteService
#
# noteable - MergeRequest object
# existing_commits - Array of existing Commit objects
# oldrev - Optional String SHA of
... TODO (rspeicher): I have no idea what this actually does.
# oldrev - Optional String SHA of
a previous Commit
#
# Examples:
#
...
...
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