summaryrefslogtreecommitdiff
path: root/lib/banzai/cross_project_reference.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-12-15 15:51:16 +0100
committerDouwe Maan <douwe@gitlab.com>2015-12-15 15:51:16 +0100
commit7781bda9bd82997f4a03de4cf911b1156ceb2cde (patch)
treea632a12b295694232205e2190f784f9bb79235ee /lib/banzai/cross_project_reference.rb
parent9451db3819ae45734c4343e55a74d347cdacf70d (diff)
downloadgitlab-ce-7781bda9bd82997f4a03de4cf911b1156ceb2cde.tar.gz
Move Markdown/reference logic from Gitlab::Markdown to Banzai
Diffstat (limited to 'lib/banzai/cross_project_reference.rb')
-rw-r--r--lib/banzai/cross_project_reference.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/banzai/cross_project_reference.rb b/lib/banzai/cross_project_reference.rb
new file mode 100644
index 00000000000..ba2866e1efa
--- /dev/null
+++ b/lib/banzai/cross_project_reference.rb
@@ -0,0 +1,22 @@
+require 'banzai'
+
+module Banzai
+ # Common methods for ReferenceFilters that support an optional cross-project
+ # reference.
+ module CrossProjectReference
+ # Given a cross-project reference string, get the Project record
+ #
+ # Defaults to value of `context[:project]` if:
+ # * No reference is given OR
+ # * Reference given doesn't exist
+ #
+ # ref - String reference.
+ #
+ # Returns a Project, or nil if the reference can't be found
+ def project_from_ref(ref)
+ return context[:project] unless ref
+
+ Project.find_with_namespace(ref)
+ end
+ end
+end