Files
gitlabhq/lib/gitlab/markdown/cross_project_reference.rb
T
Robert Speicher 96c2b94048 Reference filters
Commit ranges, commits, external issues, issues, labels, merge requests,
snippets, users.
2015-04-20 13:01:42 -04:00

27 lines
747 B
Ruby

module Gitlab
module Markdown
# Includes shared code for reference filters that support an optional
# cross-project reference.
module CrossProjectReference
NAMING_PATTERN = Gitlab::Regex::NAMESPACE_REGEX_STR
PROJECT_PATTERN = "(?<project>#{NAMING_PATTERN}/#{NAMING_PATTERN})"
# Given a cross-project reference string, get the Project record
#
# If no valid reference is given, returns the `:project` value for the
# current context.
#
# ref - String reference.
#
# Returns a Project
def project_from_ref(ref)
if ref && other = Project.find_with_namespace(ref)
other
else
context[:project]
end
end
end
end
end