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/ci/gitlab_ci_yaml_processor.rb')
-rw-r--r--lib/ci/gitlab_ci_yaml_processor.rb64
1 files changed, 34 insertions, 30 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb
index efcd2faffc7..0f57a4f53ab 100644
--- a/lib/ci/gitlab_ci_yaml_processor.rb
+++ b/lib/ci/gitlab_ci_yaml_processor.rb
@@ -7,10 +7,11 @@ module Ci
ALLOWED_YAML_KEYS = [:before_script, :image, :services, :types, :stages, :variables]
ALLOWED_JOB_KEYS = [:tags, :script, :only, :except, :type, :image, :services, :allow_failure, :type, :stage, :when]
- attr_reader :before_script, :image, :services, :variables
+ attr_reader :before_script, :image, :services, :variables, :path
- def initialize(config)
+ def initialize(config, path = nil)
@config = YAML.load(config)
+ @path = path
unless @config.is_a? Hash
raise ValidationError, "YAML should be a hash"
@@ -63,26 +64,6 @@ module Ci
end
end
- def process?(only_params, except_params, ref, tag)
- return true if only_params.nil? && except_params.nil?
-
- if only_params
- return true if tag && only_params.include?("tags")
- return true if !tag && only_params.include?("branches")
-
- only_params.find do |pattern|
- match_ref?(pattern, ref)
- end
- else
- return false if tag && except_params.include?("tags")
- return false if !tag && except_params.include?("branches")
-
- except_params.each do |pattern|
- return false if match_ref?(pattern, ref)
- end
- end
- end
-
def build_job(name, job)
{
stage_idx: stages.index(job[:stage]),
@@ -101,14 +82,6 @@ module Ci
}
end
- def match_ref?(pattern, ref)
- if pattern.first == "/" && pattern.last == "/"
- Regexp.new(pattern[1...-1]) =~ ref
- else
- pattern == ref
- end
- end
-
def normalize_script(script)
if script.is_a? Array
script.join("\n")
@@ -208,5 +181,36 @@ module Ci
def validate_string(value)
value.is_a?(String) || value.is_a?(Symbol)
end
+
+ def process?(only_params, except_params, ref, tag)
+ if only_params.present?
+ return false unless matching?(only_params, ref, tag)
+ end
+
+ if except_params.present?
+ return false if matching?(except_params, ref, tag)
+ end
+
+ true
+ end
+
+ def matching?(patterns, ref, tag)
+ patterns.any? do |pattern|
+ match_ref?(pattern, ref, tag)
+ end
+ end
+
+ def match_ref?(pattern, ref, tag)
+ pattern, path = pattern.split('@', 2)
+ return false if path && path != self.path
+ return true if tag && pattern == 'tags'
+ return true if !tag && pattern == 'branches'
+
+ if pattern.first == "/" && pattern.last == "/"
+ Regexp.new(pattern[1...-1]) =~ ref
+ else
+ pattern == ref
+ end
+ end
end
end