summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Jankovski <maxlazio@gmail.com>2014-11-05 12:53:10 +0100
committerMarin Jankovski <maxlazio@gmail.com>2014-11-05 12:53:10 +0100
commit2ee1ec430012e4489ea1d70a13bcb827cafede2e (patch)
tree4886d7b410d895c9d34dc1688e62061405343974
parent5a8ec1f6712ea044500c015e55f7515007a8285e (diff)
downloadgitlab-ce-2ee1ec430012e4489ea1d70a13bcb827cafede2e.tar.gz
Do not allow cross reference note in a mr if a mr contains mentioned commit.
-rw-r--r--app/models/note.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index f0ed7580b4c..4252d57ccb1 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -90,7 +90,7 @@ class Note < ActiveRecord::Base
note_options.merge!(noteable: noteable)
end
- create(note_options)
+ create(note_options) unless cross_reference_disallowed?(noteable, mentioner)
end
def create_milestone_change_note(noteable, project, author, milestone)
@@ -165,6 +165,15 @@ class Note < ActiveRecord::Base
[:discussion, type.try(:underscore), id, line_code].join("-").to_sym
end
+ # Determine if cross reference note should be created.
+ # eg. mentioning a commit in MR comments which exists inside a MR
+ # should not create "mentioned in" note.
+ def cross_reference_disallowed?(noteable, mentioner)
+ if mentioner.kind_of?(MergeRequest)
+ mentioner.commits.map(&:id).include? noteable.id
+ end
+ end
+
# Determine whether or not a cross-reference note already exists.
def cross_reference_exists?(noteable, mentioner)
gfm_reference = mentioner_gfm_ref(noteable, mentioner)