Module: ExtractsPath
- Included in:
- Projects::ArtifactsController, Projects::BlameController, Projects::BlobController, Projects::BuildArtifactsController, Projects::CommitsController, Projects::FindFileController, Projects::GraphsController, Projects::NetworkController, Projects::RawController, Projects::RefsController, Projects::RepositoriesController, Projects::TreeController
- Defined in:
- lib/extracts_path.rb
Overview
Module providing methods for dealing with separating a tree-ish string and a file path string when combined in a request parameter rubocop:disable Gitlab/ModuleWithInstanceVariables – will be fixed in gitlab.com/gitlab-org/gitlab/-/issues/425379
Constant Summary collapse
- InvalidPathError =
ExtractsRef::RefExtractor::InvalidPathError
- BRANCH_REF_TYPE =
ExtractsRef::RefExtractor::BRANCH_REF_TYPE
- TAG_REF_TYPE =
ExtractsRef::RefExtractor::TAG_REF_TYPE
- REF_TYPES =
ExtractsRef::RefExtractor::REF_TYPES
Instance Method Summary collapse
-
#assign_ref_vars ⇒ Object
Extends the method to handle if there is no path and the ref doesn’t exist in the repo, try to resolve the ref without an ‘.atom’ suffix.
- #ref_type ⇒ Object
Instance Method Details
#assign_ref_vars ⇒ Object
Extends the method to handle if there is no path and the ref doesn’t exist in the repo, try to resolve the ref without an ‘.atom’ suffix. If that ref is found, set the request’s format to Atom manually.
Automatically renders ‘not_found!` if a valid tree path could not be resolved (e.g., when a user inserts an invalid path or ref).
Automatically redirects to the current default branch if the ref matches a previous default branch that has subsequently been deleted.
Assignments are:
-
@id - A string representing the joined ref and path
-
@ref - A string representing the ref (e.g., the branch, tag, or commit SHA)
-
@path - A string representing the filesystem path
-
@commit - A Commit representing the commit from the given ref
If the :id parameter appears to be requesting a specific response format, that will be handled as well.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/extracts_path.rb', line 31 def assign_ref_vars ref_extractor = ExtractsRef::RefExtractor.new(repository_container, params.permit(:id, :ref, :path, :ref_type)) ref_extractor.extract! @id = ref_extractor.id @ref = ref_extractor.ref @path = ref_extractor.path @repo = ref_extractor.repo if @ref.present? @commit = ref_extractor.commit @fully_qualified_ref = ref_extractor.fully_qualified_ref end rectify_format! rectify_renamed_default_branch! && return raise InvalidPathError unless @commit @hex_path = Digest::SHA1.hexdigest(@path) @logs_path = logs_file_project_ref_path(@project, @ref, @path) rescue RuntimeError, NoMethodError, InvalidPathError render_404 end |
#ref_type ⇒ Object
57 58 59 |
# File 'lib/extracts_path.rb', line 57 def ref_type ExtractsRef::RefExtractor.ref_type(params[:ref_type]) end |