Skip to content

Commit

Permalink
Do not allow cross reference note in a mr if a mr contains mentioned …
Browse files Browse the repository at this point in the history
…commit.
  • Loading branch information
maxlazio committed Nov 5, 2014
1 parent 5a8ec1f commit 2ee1ec4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/models/note.rb
Expand Up @@ -90,7 +90,7 @@ def create_cross_reference_note(noteable, mentioner, author, project)
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)
Expand Down Expand Up @@ -165,6 +165,15 @@ def build_discussion_id(type, id, line_code)
[: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)
Expand Down

0 comments on commit 2ee1ec4

Please sign in to comment.