diff options
Diffstat (limited to 'lib/gitlab/ci/config/external')
-rw-r--r-- | lib/gitlab/ci/config/external/file/remote.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/external/mapper.rb | 12 | ||||
-rw-r--r-- | lib/gitlab/ci/config/external/rules.rb | 31 |
3 files changed, 42 insertions, 3 deletions
diff --git a/lib/gitlab/ci/config/external/file/remote.rb b/lib/gitlab/ci/config/external/file/remote.rb index 567a86c47e5..4bd8e250d7a 100644 --- a/lib/gitlab/ci/config/external/file/remote.rb +++ b/lib/gitlab/ci/config/external/file/remote.rb @@ -45,7 +45,7 @@ module Gitlab errors.push("Remote file `#{location}` could not be fetched because of HTTP code `#{response.code}` error!") end - response.to_s if errors.none? + response.body if errors.none? end end end diff --git a/lib/gitlab/ci/config/external/mapper.rb b/lib/gitlab/ci/config/external/mapper.rb index 3216d4eaac4..97e4922b2a1 100644 --- a/lib/gitlab/ci/config/external/mapper.rb +++ b/lib/gitlab/ci/config/external/mapper.rb @@ -33,6 +33,7 @@ module Gitlab locations .compact .map(&method(:normalize_location)) + .filter_map(&method(:verify_rules)) .flat_map(&method(:expand_project_files)) .flat_map(&method(:expand_wildcard_paths)) .map(&method(:expand_variables)) @@ -56,6 +57,15 @@ module Gitlab end end + def verify_rules(location) + # Behaves like there is no `rules` + return location unless ::Feature.enabled?(:ci_include_rules, context.project, default_enabled: :yaml) + + return unless Rules.new(location[:rules]).evaluate(context).pass? + + location + end + def expand_project_files(location) return location unless location[:project] @@ -65,8 +75,6 @@ module Gitlab end def expand_wildcard_paths(location) - return location unless ::Feature.enabled?(:ci_wildcard_file_paths, context.project, default_enabled: :yaml) - # We only support local files for wildcard paths return location unless location[:local] && location[:local].include?('*') diff --git a/lib/gitlab/ci/config/external/rules.rb b/lib/gitlab/ci/config/external/rules.rb new file mode 100644 index 00000000000..5a788427172 --- /dev/null +++ b/lib/gitlab/ci/config/external/rules.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module Gitlab + module Ci + class Config + module External + class Rules + def initialize(rule_hashes) + @rule_list = Build::Rules::Rule.fabricate_list(rule_hashes) + end + + def evaluate(context) + Result.new(@rule_list.nil? || match_rule(context)) + end + + private + + def match_rule(context) + @rule_list.find { |rule| rule.matches?(nil, context) } + end + + Result = Struct.new(:result) do + def pass? + !!result + end + end + end + end + end + end +end |