summaryrefslogtreecommitdiff
path: root/app/models/note.rb
diff options
context:
space:
mode:
authorCiro Santilli <ciro.santilli@gmail.com>2014-10-19 16:24:22 +0200
committerCiro Santilli <ciro.santilli@gmail.com>2014-10-19 22:19:56 +0200
commitf808ecf11e5e5664b9617112691efece5ed01980 (patch)
tree1ad1efb2e678bc9fb4024aa8523b1746197f0e62 /app/models/note.rb
parent3880bb61760ef1f69b0df49148202ff6b4208f01 (diff)
downloadgitlab-ce-f808ecf11e5e5664b9617112691efece5ed01980.tar.gz
DRY mentioned in magic note constant
Diffstat (limited to 'app/models/note.rb')
-rw-r--r--app/models/note.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index 6f1b1a4da94..f0ed7580b4c 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -80,7 +80,7 @@ class Note < ActiveRecord::Base
note_options = {
project: project,
author: author,
- note: "_mentioned in #{gfm_reference}_",
+ note: cross_reference_note_content(gfm_reference),
system: true
}
@@ -174,7 +174,7 @@ class Note < ActiveRecord::Base
where(noteable_id: noteable.id)
end
- notes.where('note like ?', "_mentioned in #{gfm_reference}_").
+ notes.where('note like ?', cross_reference_note_content(gfm_reference)).
system.any?
end
@@ -182,8 +182,16 @@ class Note < ActiveRecord::Base
where("note like :query", query: "%#{query}%")
end
+ def cross_reference_note_prefix
+ '_mentioned in '
+ end
+
private
+ def cross_reference_note_content(gfm_reference)
+ cross_reference_note_prefix + "#{gfm_reference}_"
+ 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.
@@ -249,6 +257,10 @@ class Note < ActiveRecord::Base
nil
end
+ def cross_reference?
+ note.start_with?(self.class.cross_reference_note_prefix)
+ end
+
def find_diff
return nil unless noteable && noteable.diffs.present?