debian-mirror-gitlab/lib/banzai/cross_project_reference.rb

24 lines
711 B
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2015-12-23 02:04:40 +05:30
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
#
2018-05-09 12:01:36 +05:30
# Defaults to value of `context[:project]`, or `context[:group]` if:
2015-12-23 02:04:40 +05:30
# * 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
2018-03-17 18:26:18 +05:30
def parent_from_ref(ref)
2018-05-09 12:01:36 +05:30
return context[:project] || context[:group] unless ref
2018-12-05 23:21:45 +05:30
return context[:project] if context[:project]&.full_path == ref
2015-12-23 02:04:40 +05:30
2017-08-17 22:00:37 +05:30
Project.find_by_full_path(ref)
2015-12-23 02:04:40 +05:30
end
end
end