Class: Gitlab::Ci::Config::External::File::Project

Inherits:
Base
  • Object
show all
Extended by:
Utils::Override
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/ci/config/external/file/project.rb

Constant Summary

Constants inherited from Base

Base::YAML_WHITELIST_EXTENSION

Instance Attribute Summary collapse

Attributes inherited from Base

#context, #errors, #location, #params

Instance Method Summary collapse

Methods included from Utils::Override

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

Methods inherited from Base

#eql?, #error_message, #hash, #invalid_extension?, #invalid_location_type?, #load_and_validate_expanded_hash!, #preload_content, #to_hash, #valid?, #validate_location!

Constructor Details

#initialize(params, context) ⇒ Project

Returns a new instance of Project.



14
15
16
17
18
19
20
21
22
23
# File 'lib/gitlab/ci/config/external/file/project.rb', line 14

def initialize(params, context)
  # `Repository#blobs_at` does not support files with the `/` prefix.
  @location = Gitlab::Utils.remove_leading_slashes(params[:file])

  # We are using the same downcase in the `project` method.
  @project_name = get_project_name(params[:project]).to_s.downcase
  @ref_name = params[:ref] || 'HEAD'

  super
end

Instance Attribute Details

#project_nameObject (readonly)

Returns the value of attribute project_name.



12
13
14
# File 'lib/gitlab/ci/config/external/file/project.rb', line 12

def project_name
  @project_name
end

#ref_nameObject (readonly)

Returns the value of attribute ref_name.



12
13
14
# File 'lib/gitlab/ci/config/external/file/project.rb', line 12

def ref_name
  @ref_name
end

Instance Method Details

#contentObject



29
30
31
# File 'lib/gitlab/ci/config/external/file/project.rb', line 29

def content
  strong_memoize(:content) { fetch_local_content }
end

#matching?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/gitlab/ci/config/external/file/project.rb', line 25

def matching?
  super && project_name.present?
end

#metadataObject



33
34
35
36
37
38
39
40
41
# File 'lib/gitlab/ci/config/external/file/project.rb', line 33

def 
  super.merge(
    type: :file,
    location: masked_location,
    blob: masked_blob,
    raw: masked_raw,
    extra: { project: masked_project_name, ref: masked_ref_name }
  )
end

#preload_contextObject



43
44
45
46
47
48
49
50
# File 'lib/gitlab/ci/config/external/file/project.rb', line 43

def preload_context
  #
  # calling these methods lazily loads them via BatchLoader
  #
  project
  can_access_local_content?
  sha
end

#validate_content!Object



60
61
62
63
64
65
66
# File 'lib/gitlab/ci/config/external/file/project.rb', line 60

def validate_content!
  if content.nil?
    errors.push("Project `#{masked_project_name}` file `#{masked_location}` does not exist!")
  elsif content.blank?
    errors.push("Project `#{masked_project_name}` file `#{masked_location}` is empty!")
  end
end

#validate_context!Object



52
53
54
55
56
57
58
# File 'lib/gitlab/ci/config/external/file/project.rb', line 52

def validate_context!
  if !can_access_local_content?
    errors.push("Project `#{masked_project_name}` not found or access denied! Make sure any includes in the pipeline configuration are correctly defined.")
  elsif sha.nil?
    errors.push("Project `#{masked_project_name}` reference `#{masked_ref_name}` does not exist!")
  end
end