BigW Consortium Gitlab

cross_project_reference.rb 657 Bytes
Newer Older
1 2
require 'gitlab/markdown'

Robert Speicher committed
3 4
module Gitlab
  module Markdown
5 6
    # Common methods for ReferenceFilters that support an optional cross-project
    # reference.
Robert Speicher committed
7 8 9
    module CrossProjectReference
      # Given a cross-project reference string, get the Project record
      #
10
      # Defaults to value of `context[:project]` if:
11
      # * No reference is given OR
12
      # * Reference given doesn't exist
Robert Speicher committed
13 14 15
      #
      # ref - String reference.
      #
16
      # Returns a Project, or nil if the reference can't be found
Robert Speicher committed
17
      def project_from_ref(ref)
18 19
        return context[:project] unless ref

20
        Project.find_with_namespace(ref)
21
      end
Robert Speicher committed
22 23 24
    end
  end
end