debian-mirror-gitlab/app/models/concerns/mentionable/reference_regexes.rb

41 lines
1.2 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module Mentionable
module ReferenceRegexes
2019-02-15 15:39:39 +05:30
extend Gitlab::Utils::StrongMemoize
2017-09-10 17:25:29 +05:30
def self.reference_pattern(link_patterns, issue_pattern)
Regexp.union(link_patterns,
issue_pattern,
2018-12-05 23:21:45 +05:30
*other_patterns)
end
def self.other_patterns
[
Commit.reference_pattern,
2019-10-31 01:37:42 +05:30
MergeRequest.reference_pattern,
Label.reference_pattern,
Milestone.reference_pattern
2018-12-05 23:21:45 +05:30
]
2017-09-10 17:25:29 +05:30
end
2019-02-15 15:39:39 +05:30
def self.default_pattern
strong_memoize(:default_pattern) do
issue_pattern = Issue.reference_pattern
2021-01-29 00:20:46 +05:30
link_patterns = Regexp.union([Issue, Commit, MergeRequest, Epic, Vulnerability].map(&:link_reference_pattern).compact)
2019-02-15 15:39:39 +05:30
reference_pattern(link_patterns, issue_pattern)
end
2017-09-10 17:25:29 +05:30
end
2019-02-15 15:39:39 +05:30
def self.external_pattern
strong_memoize(:external_pattern) do
issue_pattern = IssueTrackerService.reference_pattern
2020-11-24 15:15:51 +05:30
link_patterns = URI::DEFAULT_PARSER.make_regexp(%w(http https))
2019-02-15 15:39:39 +05:30
reference_pattern(link_patterns, issue_pattern)
end
2017-09-10 17:25:29 +05:30
end
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
Mentionable::ReferenceRegexes.prepend_mod_with('Mentionable::ReferenceRegexes')