d598e4fd93
Enables frozen for the following: * lib/*.rb * lib/banzai/**/*.rb * lib/bitbucket/**/*.rb * lib/constraints/**/*.rb * lib/container_registry/**/*.rb * lib/declarative_policy/**/*.rb Partially addresses #47424.
23 lines
711 B
Ruby
23 lines
711 B
Ruby
# frozen_string_literal: true
|
|
|
|
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]`, or `context[:group]` 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 parent_from_ref(ref)
|
|
return context[:project] || context[:group] unless ref
|
|
return context[:project] if context[:project]&.full_path == ref
|
|
|
|
Project.find_by_full_path(ref)
|
|
end
|
|
end
|
|
end
|