Commit ce4ff82e authored by Sean McGivern's avatar Sean McGivern Committed by Lin Jen-Shin

Remove EE-specific code from Mentionable

parent 7a0008e4
......@@ -10,6 +10,8 @@
module Mentionable
extend ActiveSupport::Concern
prepend EE::Mentionable
class_methods do
# Indicate which attributes of the Mentionable to search for GFM references.
def attr_mentionable(attr, options = {})
......@@ -86,12 +88,11 @@ module Mentionable
return [] unless matches_cross_reference_regex?
refs = all_references(current_user)
refs = (refs.issues + refs.merge_requests + refs.commits + refs.epics)
# We're using this method instead of Array diffing because that requires
# both of the object's `hash` values to be the same, which may not be the
# case for otherwise identical Commit objects.
refs.reject { |ref| ref == local_reference }
extracted_mentionables(refs).reject { |ref| ref == local_reference }
end
# Uses regex to quickly determine if mentionables might be referenced
......@@ -134,6 +135,10 @@ module Mentionable
private
def extracted_mentionables(refs)
refs.issues + refs.merge_requests + refs.commits
end
# Returns a Hash of changed mentionable fields
#
# Preference is given to the `changes` Hash, but falls back to
......
......@@ -2,17 +2,24 @@
module Mentionable
module ReferenceRegexes
prepend EE::Mentionable::ReferenceRegexes
def self.reference_pattern(link_patterns, issue_pattern)
Regexp.union(link_patterns,
issue_pattern,
Epic.reference_pattern,
Commit.reference_pattern,
MergeRequest.reference_pattern)
*other_patterns)
end
def self.other_patterns
[
Commit.reference_pattern,
MergeRequest.reference_pattern
]
end
DEFAULT_PATTERN = begin
issue_pattern = Issue.reference_pattern
link_patterns = Regexp.union([Issue, Commit, MergeRequest, Epic].map(&:link_reference_pattern))
link_patterns = Regexp.union([Issue, Commit, MergeRequest, Epic].map(&:link_reference_pattern).compact)
reference_pattern(link_patterns, issue_pattern)
end
......
......@@ -5,6 +5,10 @@
class Epic < ActiveRecord::Base
prepend EE::Epic
def self.link_reference_pattern
nil
end
def self.reference_prefix
'&'
end
......
# frozen_string_literal: true
module EE
module Mentionable
extend ::Gitlab::Utils::Override
private
override :extracted_mentionables
def extracted_mentionables(refs)
super + refs.epics
end
end
end
# frozen_string_literal: true
module EE
module Mentionable
module ReferenceRegexes
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
override :other_patterns
def other_patterns
[
::Epic.reference_pattern,
*super
]
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment