summaryrefslogtreecommitdiff
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
parent3880bb61760ef1f69b0df49148202ff6b4208f01 (diff)
downloadgitlab-ce-f808ecf11e5e5664b9617112691efece5ed01980.tar.gz
DRY mentioned in magic note constant
-rw-r--r--app/models/note.rb16
-rw-r--r--app/services/notification_service.rb2
2 files changed, 15 insertions, 3 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?
diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb
index fe39f83b400..36781314278 100644
--- a/app/services/notification_service.rb
+++ b/app/services/notification_service.rb
@@ -119,7 +119,7 @@ class NotificationService
# ignore gitlab service messages
return true if note.note =~ /\A_Status changed to closed_/
- return true if note.note =~ /\A_mentioned in / && note.system == true
+ return true if note.cross_reference? && note.system == true
opts = { noteable_type: note.noteable_type, project_id: note.project_id }