debian-mirror-gitlab/lib/gitlab/ci/config/external/file/local.rb

53 lines
1.3 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
class Config
module External
module File
class Local < Base
2019-12-21 20:55:43 +05:30
extend ::Gitlab::Utils::Override
2018-12-13 13:39:08 +05:30
include Gitlab::Utils::StrongMemoize
2019-02-15 15:39:39 +05:30
def initialize(params, context)
@location = params[:local]
2018-12-13 13:39:08 +05:30
super
end
def content
strong_memoize(:content) { fetch_local_content }
end
private
def validate_content!
2019-07-31 22:56:46 +05:30
if context.project&.repository.nil?
errors.push("Local file `#{location}` does not have project!")
elsif content.nil?
2018-12-13 13:39:08 +05:30
errors.push("Local file `#{location}` does not exist!")
elsif content.blank?
errors.push("Local file `#{location}` is empty!")
end
end
def fetch_local_content
2019-02-15 15:39:39 +05:30
context.project.repository.blob_data_at(context.sha, location)
2018-12-13 13:39:08 +05:30
end
2019-07-07 11:18:12 +05:30
2019-12-21 20:55:43 +05:30
override :expand_context_attrs
def expand_context_attrs
{
2019-07-07 11:18:12 +05:30
project: context.project,
sha: context.sha,
2020-04-08 14:13:33 +05:30
user: context.user,
parent_pipeline: context.parent_pipeline
2019-12-21 20:55:43 +05:30
}
2019-07-07 11:18:12 +05:30
end
2018-12-13 13:39:08 +05:30
end
end
end
end
end
end