Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/config/external/rules.rb')
-rw-r--r--lib/gitlab/ci/config/external/rules.rb27
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/gitlab/ci/config/external/rules.rb b/lib/gitlab/ci/config/external/rules.rb
index 95470537de3..134306332e6 100644
--- a/lib/gitlab/ci/config/external/rules.rb
+++ b/lib/gitlab/ci/config/external/rules.rb
@@ -6,6 +6,7 @@ module Gitlab
module External
class Rules
ALLOWED_KEYS = Entry::Include::Rules::Rule::ALLOWED_KEYS
+ ALLOWED_WHEN = Entry::Include::Rules::Rule::ALLOWED_WHEN
InvalidIncludeRulesError = Class.new(Mapper::Error)
@@ -16,7 +17,17 @@ module Gitlab
end
def evaluate(context)
- Result.new(@rule_list.nil? || match_rule(context))
+ if Feature.enabled?(:ci_support_include_rules_when_never, context.project)
+ if @rule_list.nil?
+ Result.new('always')
+ elsif matched_rule = match_rule(context)
+ Result.new(matched_rule.attributes[:when])
+ else
+ Result.new('never')
+ end
+ else
+ LegacyResult.new(@rule_list.nil? || match_rule(context))
+ end
end
private
@@ -29,13 +40,23 @@ module Gitlab
return unless rule_hashes.is_a?(Array)
rule_hashes.each do |rule_hash|
- next if (rule_hash.keys - ALLOWED_KEYS).empty?
+ next if (rule_hash.keys - ALLOWED_KEYS).empty? && valid_when?(rule_hash)
raise InvalidIncludeRulesError, "invalid include rule: #{rule_hash}"
end
end
- Result = Struct.new(:result) do
+ def valid_when?(rule_hash)
+ rule_hash[:when].nil? || rule_hash[:when].in?(ALLOWED_WHEN)
+ end
+
+ Result = Struct.new(:when) do
+ def pass?
+ self.when != 'never'
+ end
+ end
+
+ LegacyResult = Struct.new(:result) do
def pass?
!!result
end