Module: ExtractsPath

Overview

Module providing methods for dealing with separating a tree-ish string and a file path string when combined in a request parameter

Constant Summary

Constants included from ExtractsRef

ExtractsRef::InvalidPathError

Instance Method Summary collapse

Methods included from Gitlab::Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods included from ExtractsRef

#extract_ref, #extract_ref_path, #tree

Instance Method Details

#assign_ref_varsObject


36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/extracts_path.rb', line 36

def assign_ref_vars
  super

  rectify_atom!

  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

#extract_ref_without_atom(id) ⇒ Object

If we have an ID of 'foo.atom', and the controller provides Atom and HTML formats, then we have to check if the request was for the Atom version of the ID without the '.atom' suffix, or the HTML version of the ID including the suffix. We only check this if the version including the suffix doesn't match, so it is possible to create a branch which has an unroutable Atom feed.

Raises:


15
16
17
18
19
20
21
22
# File 'lib/extracts_path.rb', line 15

def extract_ref_without_atom(id)
  id_without_atom = id.sub(/\.atom$/, '')
  valid_refs = ref_names.select { |v| "#{id_without_atom}/".start_with?("#{v}/") }

  raise InvalidPathError if valid_refs.blank?

  valid_refs.max_by(&:length)
end