summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2015-11-03 12:13:21 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2015-11-03 12:13:21 +0000
commit86c0d8d28983c4f6abbcbf461e422b2fe5962847 (patch)
tree54dbd46b12b64bc655ba329e2698e7ca90bf5b4d /lib
parent819cfcef59f127a9ad92dc969570b479088a6974 (diff)
parentfe34b745e71a3e4ebb18d77a186d24de23b50863 (diff)
downloadgitlab-ce-86c0d8d28983c4f6abbcbf461e422b2fe5962847.tar.gz
Merge branch 'only-syntax' into 'master'
Extend yml syntax for only and except to support specifying repository path This allows to limit execution of jobs to specific repository. For example: ```yaml job: only: - branches@gitlab-org/gitlab-ce except: - master@gitlab-org/gitlab-ce ``` The above will run `job` for all branches on `gitlab-org/gitlab-ce`, except master. @dzaporozhets @JobV @vsizov Please review. See merge request !1720
Diffstat (limited to 'lib')
-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