diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-09-07 22:22:52 +0200 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-09-07 22:22:52 +0200 |
commit | 1e816a972164c515bf99c39bd8880dd23e534c9e (patch) | |
tree | 6a149060c78aaf0460ee4a4084fb9c2f729c0b9a /lib/gitlab | |
parent | 49598c58ebca5807cc63eb7b17872018c6f48503 (diff) | |
download | gitlab-ce-1e816a972164c515bf99c39bd8880dd23e534c9e.tar.gz |
Address MR suggestions
CE mirror of c4578b951e331fe8c75cd4f948ce74cec6587bad
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/ci/config.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/ci/external/file/local.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/ci/external/file/remote.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/ci/external/mapper.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/ci/external/processor.rb | 10 |
5 files changed, 34 insertions, 33 deletions
diff --git a/lib/gitlab/ci/config.rb b/lib/gitlab/ci/config.rb index 1779fbb2a39..19d93c6e785 100644 --- a/lib/gitlab/ci/config.rb +++ b/lib/gitlab/ci/config.rb @@ -76,8 +76,8 @@ module Gitlab end def process_external_files(config, project, opts) - branch_name = opts.fetch(:branch_name, project.default_branch) - ::Gitlab::Ci::External::Processor.new(config, project, branch_name).perform + sha = opts.fetch(:sha, project.repository.commit.sha) + ::Gitlab::Ci::External::Processor.new(config, project, sha).perform end end end diff --git a/lib/gitlab/ci/external/file/local.rb b/lib/gitlab/ci/external/file/local.rb index dc1ba923411..27e827222e5 100644 --- a/lib/gitlab/ci/external/file/local.rb +++ b/lib/gitlab/ci/external/file/local.rb @@ -3,16 +3,16 @@ module Gitlab module External module File class Local - attr_reader :value, :project, :branch_name + attr_reader :location, :project, :branch_name - def initialize(value, project, branch_name) - @value = value - @project = project - @branch_name = branch_name + def initialize(location, opts = {}) + @location = location + @project = opts.fetch(:project) + @sha = opts.fetch(:sha) end def valid? - commit && local_file_content + local_file_content end def content @@ -21,12 +21,8 @@ module Gitlab private - def commit - @commit ||= project.repository.commit(branch_name) - end - def local_file_content - @local_file_content ||= project.repository.blob_data_at(commit.sha, value) + @local_file_content ||= project.repository.blob_data_at(sha, location) end end end diff --git a/lib/gitlab/ci/external/file/remote.rb b/lib/gitlab/ci/external/file/remote.rb index 7d8cd1957ad..aa089860525 100644 --- a/lib/gitlab/ci/external/file/remote.rb +++ b/lib/gitlab/ci/external/file/remote.rb @@ -3,20 +3,24 @@ module Gitlab module External module File class Remote - attr_reader :value + attr_reader :location - def initialize(value) - @value = value + def initialize(location, opts = {}) + @location = location end def valid? - ::Gitlab::UrlSanitizer.valid?(value) && content + ::Gitlab::UrlSanitizer.valid?(location) && content end def content - HTTParty.get(value) - rescue HTTParty::Error, Timeout::Error - false + return @content if defined?(@content) + + @content ||= begin + HTTParty.get(location) + rescue HTTParty::Error, Timeout::Error + false + end end end end diff --git a/lib/gitlab/ci/external/mapper.rb b/lib/gitlab/ci/external/mapper.rb index f2e5ec972df..cc9be317ebe 100644 --- a/lib/gitlab/ci/external/mapper.rb +++ b/lib/gitlab/ci/external/mapper.rb @@ -2,27 +2,28 @@ module Gitlab module Ci module External class Mapper - def initialize(values, project, branch_name) - @paths = Array(values.fetch(:include, [])) + def initialize(values, project, sha) + @locations = Array(values.fetch(:include, [])) @project = project - @branch_name = branch_name + @sha = sha end def process - paths.map { |path| build_external_file(path) } + locations.map { |location| build_external_file(location) } end private - attr_reader :paths, :project, :branch_name + attr_reader :locations, :project, :sha - def build_external_file(path) - remote_file = Gitlab::Ci::External::File::Remote.new(path) + def build_external_file(location) + remote_file = Gitlab::Ci::External::File::Remote.new(location) if remote_file.valid? remote_file else - ::Gitlab::Ci::External::File::Local.new(path, project, branch_name) + options = { project: project, sha: sha } + Gitlab::Ci::External::File::Local.new(location, options) end end end diff --git a/lib/gitlab/ci/external/processor.rb b/lib/gitlab/ci/external/processor.rb index 5cae0166346..44dc3183367 100644 --- a/lib/gitlab/ci/external/processor.rb +++ b/lib/gitlab/ci/external/processor.rb @@ -4,9 +4,9 @@ module Gitlab class Processor FileError = Class.new(StandardError) - def initialize(values, project, branch_name) + def initialize(values, project, sha) @values = values - @external_files = ::Gitlab::Ci::External::Mapper.new(values, project, branch_name).process + @external_files = Gitlab::Ci::External::Mapper.new(values, project, sha).process @content = {} end @@ -18,7 +18,7 @@ module Gitlab @content.merge!(content_of(external_file)) end - append_external_content + append_inline_content remove_include_keyword end @@ -28,7 +28,7 @@ module Gitlab def validate_external_file(external_file) unless external_file.valid? - raise FileError, "External file: '#{external_file.value}' should be a valid local or remote file" + raise FileError, "External file: '#{external_file.location}' should be a valid local or remote file" end end @@ -36,7 +36,7 @@ module Gitlab ::Gitlab::Ci::Config::Loader.new(external_file.content).load! end - def append_external_content + def append_inline_content @content.merge!(@values) end |