Add all sources as special keywords for only and except
This commit is contained in:
parent
8db63b2628
commit
ecb54cddd1
|
@ -393,7 +393,8 @@ There are a few rules that apply to the usage of refs policy:
|
||||||
* `only` and `except` are inclusive. If both `only` and `except` are defined
|
* `only` and `except` are inclusive. If both `only` and `except` are defined
|
||||||
in a job specification, the ref is filtered by `only` and `except`.
|
in a job specification, the ref is filtered by `only` and `except`.
|
||||||
* `only` and `except` allow the use of regular expressions.
|
* `only` and `except` allow the use of regular expressions.
|
||||||
* `only` and `except` allow the use of special keywords: `branches`, `tags`, `triggers` and `schedules`.
|
* `only` and `except` allow the use of special keywords:
|
||||||
|
`api`, `branches`, `external`, `tags`, `pushes`, `schedules`, `triggers`, and `web`
|
||||||
* `only` and `except` allow to specify a repository path to filter jobs for
|
* `only` and `except` allow to specify a repository path to filter jobs for
|
||||||
forks.
|
forks.
|
||||||
|
|
||||||
|
|
|
@ -207,17 +207,15 @@ module Ci
|
||||||
|
|
||||||
def matching?(patterns, ref, tag, source)
|
def matching?(patterns, ref, tag, source)
|
||||||
patterns.any? do |pattern|
|
patterns.any? do |pattern|
|
||||||
match_ref?(pattern, ref, tag, source)
|
match_ref?(pattern, ref, tag) || match_source?(pattern, source)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def match_ref?(pattern, ref, tag, source)
|
def match_ref?(pattern, ref, tag)
|
||||||
pattern, path = pattern.split('@', 2)
|
pattern, path = pattern.split('@', 2)
|
||||||
return false if path && path != self.path
|
return false if path && path != self.path
|
||||||
return true if tag && pattern == 'tags'
|
return true if tag && pattern == 'tags'
|
||||||
return true if !tag && pattern == 'branches'
|
return true if !tag && pattern == 'branches'
|
||||||
return true if source == 'trigger' && pattern == 'triggers'
|
|
||||||
return true if source == 'schedule' && pattern == 'schedules'
|
|
||||||
|
|
||||||
if pattern.first == "/" && pattern.last == "/"
|
if pattern.first == "/" && pattern.last == "/"
|
||||||
Regexp.new(pattern[1...-1]) =~ ref
|
Regexp.new(pattern[1...-1]) =~ ref
|
||||||
|
@ -225,5 +223,14 @@ module Ci
|
||||||
pattern == ref
|
pattern == ref
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def match_source?(pattern, source)
|
||||||
|
return source_to_pattern(source) == pattern
|
||||||
|
end
|
||||||
|
|
||||||
|
def source_to_pattern(source)
|
||||||
|
return source if ['api', 'external', 'web'].include? source
|
||||||
|
return source.pluralize
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -219,48 +219,44 @@ module Ci
|
||||||
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(0)
|
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns builds if only has a triggers keyword specified and a trigger is provided" do
|
it "returns builds if only has special keywords specified and source matches" do
|
||||||
|
possibilities = [{keyword: 'pushes', source: 'push'},
|
||||||
|
{keyword: 'web', source: 'web'},
|
||||||
|
{keyword: 'triggers', source: 'trigger'},
|
||||||
|
{keyword: 'schedules', source: 'schedule'},
|
||||||
|
{keyword: 'api', source: 'api'},
|
||||||
|
{keyword: 'external', source: 'external'}]
|
||||||
|
|
||||||
|
possibilities.each do |possibility|
|
||||||
config = YAML.dump({
|
config = YAML.dump({
|
||||||
before_script: ["pwd"],
|
before_script: ["pwd"],
|
||||||
rspec: { script: "rspec", type: type, only: ["triggers"] }
|
rspec: { script: "rspec", type: type, only: [possibility[:keyword]] }
|
||||||
})
|
})
|
||||||
|
|
||||||
config_processor = GitlabCiYamlProcessor.new(config, path)
|
config_processor = GitlabCiYamlProcessor.new(config, path)
|
||||||
|
|
||||||
expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, 'trigger').size).to eq(1)
|
expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, possibility[:source]).size).to eq(1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns builds if only has a schedules keyword specified and a schedule is provided" do
|
it "does not return builds if only has special keywords specified and source doesn't match" do
|
||||||
|
possibilities = [{keyword: 'pushes', source: 'web'},
|
||||||
|
{keyword: 'web', source: 'push'},
|
||||||
|
{keyword: 'triggers', source: 'schedule'},
|
||||||
|
{keyword: 'schedules', source: 'external'},
|
||||||
|
{keyword: 'api', source: 'trigger'},
|
||||||
|
{keyword: 'external', source: 'api'}]
|
||||||
|
|
||||||
|
possibilities.each do |possibility|
|
||||||
config = YAML.dump({
|
config = YAML.dump({
|
||||||
before_script: ["pwd"],
|
before_script: ["pwd"],
|
||||||
rspec: { script: "rspec", type: type, only: ["schedules"] }
|
rspec: { script: "rspec", type: type, only: [possibility[:keyword]] }
|
||||||
})
|
})
|
||||||
|
|
||||||
config_processor = GitlabCiYamlProcessor.new(config, path)
|
config_processor = GitlabCiYamlProcessor.new(config, path)
|
||||||
|
|
||||||
expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, 'schedule').size).to eq(1)
|
expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, possibility[:source]).size).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not return builds if only has a triggers keyword specified and no trigger is provided" do
|
|
||||||
config = YAML.dump({
|
|
||||||
before_script: ["pwd"],
|
|
||||||
rspec: { script: "rspec", type: type, only: ["triggers"] }
|
|
||||||
})
|
|
||||||
|
|
||||||
config_processor = GitlabCiYamlProcessor.new(config, path)
|
|
||||||
|
|
||||||
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(0)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "does not return builds if only has a schedules keyword specified and no schedule is provided" do
|
|
||||||
config = YAML.dump({
|
|
||||||
before_script: ["pwd"],
|
|
||||||
rspec: { script: "rspec", type: type, only: ["schedules"] }
|
|
||||||
})
|
|
||||||
|
|
||||||
config_processor = GitlabCiYamlProcessor.new(config, path)
|
|
||||||
|
|
||||||
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(0)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns builds if only has current repository path" do
|
it "returns builds if only has current repository path" do
|
||||||
|
@ -397,48 +393,44 @@ module Ci
|
||||||
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
|
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not return builds if except has a triggers keyword specified and a trigger is provided" do
|
it "does not return builds if except has special keywords specified and source matches" do
|
||||||
|
possibilities = [{keyword: 'pushes', source: 'push'},
|
||||||
|
{keyword: 'web', source: 'web'},
|
||||||
|
{keyword: 'triggers', source: 'trigger'},
|
||||||
|
{keyword: 'schedules', source: 'schedule'},
|
||||||
|
{keyword: 'api', source: 'api'},
|
||||||
|
{keyword: 'external', source: 'external'}]
|
||||||
|
|
||||||
|
possibilities.each do |possibility|
|
||||||
config = YAML.dump({
|
config = YAML.dump({
|
||||||
before_script: ["pwd"],
|
before_script: ["pwd"],
|
||||||
rspec: { script: "rspec", type: type, except: ["triggers"] }
|
rspec: { script: "rspec", type: type, except: [possibility[:keyword]] }
|
||||||
})
|
})
|
||||||
|
|
||||||
config_processor = GitlabCiYamlProcessor.new(config, path)
|
config_processor = GitlabCiYamlProcessor.new(config, path)
|
||||||
|
|
||||||
expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, 'trigger').size).to eq(0)
|
expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, possibility[:source]).size).to eq(0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not return builds if except has a schedules keyword specified and a schedule is provided" do
|
it "returns builds if except has special keywords specified and source doesn't match" do
|
||||||
|
possibilities = [{keyword: 'pushes', source: 'web'},
|
||||||
|
{keyword: 'web', source: 'push'},
|
||||||
|
{keyword: 'triggers', source: 'schedule'},
|
||||||
|
{keyword: 'schedules', source: 'external'},
|
||||||
|
{keyword: 'api', source: 'trigger'},
|
||||||
|
{keyword: 'external', source: 'api'}]
|
||||||
|
|
||||||
|
possibilities.each do |possibility|
|
||||||
config = YAML.dump({
|
config = YAML.dump({
|
||||||
before_script: ["pwd"],
|
before_script: ["pwd"],
|
||||||
rspec: { script: "rspec", type: type, except: ["schedules"] }
|
rspec: { script: "rspec", type: type, only: [possibility[:keyword]] }
|
||||||
})
|
})
|
||||||
|
|
||||||
config_processor = GitlabCiYamlProcessor.new(config, path)
|
config_processor = GitlabCiYamlProcessor.new(config, path)
|
||||||
|
|
||||||
expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, 'schedule').size).to eq(0)
|
expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, possibility[:source]).size).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns builds if except has a triggers keyword specified and no trigger is provided" do
|
|
||||||
config = YAML.dump({
|
|
||||||
before_script: ["pwd"],
|
|
||||||
rspec: { script: "rspec", type: type, except: ["triggers"] }
|
|
||||||
})
|
|
||||||
|
|
||||||
config_processor = GitlabCiYamlProcessor.new(config, path)
|
|
||||||
|
|
||||||
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns builds if except has a schedules keyword specified and no schedule is provided" do
|
|
||||||
config = YAML.dump({
|
|
||||||
before_script: ["pwd"],
|
|
||||||
rspec: { script: "rspec", type: type, except: ["schedules"] }
|
|
||||||
})
|
|
||||||
|
|
||||||
config_processor = GitlabCiYamlProcessor.new(config, path)
|
|
||||||
|
|
||||||
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not return builds if except has current repository path" do
|
it "does not return builds if except has current repository path" do
|
||||||
|
|
Loading…
Reference in New Issue