summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2019-02-16 15:25:32 +0900
committerShinya Maeda <shinya@gitlab.com>2019-02-16 17:12:30 +0900
commitb8bc14ac64a39e0ddfb90cb15ae1bb9fcc717e2f (patch)
treee2a78baea1a0f64011b6a26a7316ebb820caafe8
parent894ede2631b995f129770b66f81f03f82205c326 (diff)
downloadgitlab-ce-introduce-new-only-keywords.tar.gz
Introduce new only keywords for gitlab-ci.ymlintroduce-new-only-keywords
Add more
-rw-r--r--lib/gitlab/ci/build/policy/branches.rb33
-rw-r--r--lib/gitlab/ci/build/policy/events.rb29
-rw-r--r--lib/gitlab/ci/build/policy/merge_requests.rb33
-rw-r--r--lib/gitlab/ci/build/policy/project_paths.rb33
-rw-r--r--lib/gitlab/ci/build/policy/protected_branches.rb33
-rw-r--r--lib/gitlab/ci/build/policy/tags.rb33
6 files changed, 194 insertions, 0 deletions
diff --git a/lib/gitlab/ci/build/policy/branches.rb b/lib/gitlab/ci/build/policy/branches.rb
new file mode 100644
index 00000000000..90885087f5e
--- /dev/null
+++ b/lib/gitlab/ci/build/policy/branches.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module Build
+ module Policy
+ class Branches < Policy::Specification
+ def initialize(branches)
+ @patterns = Array(branches)
+ end
+
+ def satisfied_by?(pipeline, seed = nil)
+ return false unless pipeline.branch?
+
+ @patterns.any? do |pattern|
+ matches_pattern?(pattern, pipeline.ref)
+ end
+ end
+
+ private
+
+ def matches_pattern?(pattern, subject)
+ if pattern.first == "/" && pattern.last == "/"
+ Regexp.new(pattern[1...-1]) =~ subject
+ else
+ pattern == subject
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/build/policy/events.rb b/lib/gitlab/ci/build/policy/events.rb
new file mode 100644
index 00000000000..8d2fcfbc5ae
--- /dev/null
+++ b/lib/gitlab/ci/build/policy/events.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module Build
+ module Policy
+ class Events < Policy::Specification
+ def initialize(events)
+ @events = Array(events)
+ end
+
+ def satisfied_by?(pipeline, seed = nil)
+ return false unless pipeline.source
+
+ @events.any? do |event|
+ matches_event?(event, pipeline.source)
+ end
+ end
+
+ private
+
+ def matches_event?(event, source)
+ event == source || event == source.pluralize
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/build/policy/merge_requests.rb b/lib/gitlab/ci/build/policy/merge_requests.rb
new file mode 100644
index 00000000000..5d9947f15a0
--- /dev/null
+++ b/lib/gitlab/ci/build/policy/merge_requests.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module Build
+ module Policy
+ class Branches < Policy::Specification
+ def initialize(branches)
+ @patterns = Array(branches)
+ end
+
+ def satisfied_by?(pipeline, seed = nil)
+ return false unless pipeline.merge_request?
+
+ @patterns.any? do |pattern|
+ matches_pattern?(pattern, pipeline.ref)
+ end
+ end
+
+ private
+
+ def matches_pattern?(pattern, subject)
+ if pattern.first == "/" && pattern.last == "/"
+ Regexp.new(pattern[1...-1]) =~ subject
+ else
+ pattern == subject
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/build/policy/project_paths.rb b/lib/gitlab/ci/build/policy/project_paths.rb
new file mode 100644
index 00000000000..d3478cb2f17
--- /dev/null
+++ b/lib/gitlab/ci/build/policy/project_paths.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module Build
+ module Policy
+ class ProjectPaths < Policy::Specification
+ def initialize(project_paths)
+ @patterns = Array(project_paths)
+ end
+
+ def satisfied_by?(pipeline, seed = nil)
+ return false unless pipeline.project && !pipeline.project.pending_delete?
+
+ @patterns.any? do |pattern|
+ matches_pattern?(pattern, pipeline.project_full_path)
+ end
+ end
+
+ private
+
+ def matches_pattern?(pattern, subject)
+ if pattern.first == "/" && pattern.last == "/"
+ Regexp.new(pattern[1...-1]) =~ subject
+ else
+ pattern == subject
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/build/policy/protected_branches.rb b/lib/gitlab/ci/build/policy/protected_branches.rb
new file mode 100644
index 00000000000..5bbdaf4b416
--- /dev/null
+++ b/lib/gitlab/ci/build/policy/protected_branches.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module Build
+ module Policy
+ class ProtectedBranches < Policy::Specification
+ def initialize(protected_branches)
+ @patterns = Array(protected_branches)
+ end
+
+ def satisfied_by?(pipeline, seed = nil)
+ return false unless pipeline.protected?
+
+ @patterns.any? do |pattern|
+ matches_pattern?(pattern, pipeline.ref)
+ end
+ end
+
+ private
+
+ def matches_pattern?(pattern, subject)
+ if pattern.first == "/" && pattern.last == "/"
+ Regexp.new(pattern[1...-1]) =~ subject
+ else
+ pattern == subject
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/build/policy/tags.rb b/lib/gitlab/ci/build/policy/tags.rb
new file mode 100644
index 00000000000..c7d097e28fe
--- /dev/null
+++ b/lib/gitlab/ci/build/policy/tags.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module Build
+ module Policy
+ class Tags < Policy::Specification
+ def initialize(patterns)
+ @patterns = Array(patterns)
+ end
+
+ def satisfied_by?(pipeline, seed = nil)
+ return false unless pipeline.tag?
+
+ @patterns.any? do |pattern|
+ matches_pattern?(pattern, pipeline.ref)
+ end
+ end
+
+ private
+
+ def matches_pattern?(pattern, subject)
+ if pattern.first == "/" && pattern.last == "/"
+ Regexp.new(pattern[1...-1]) =~ subject
+ else
+ pattern == subject
+ end
+ end
+ end
+ end
+ end
+ end
+end