Skip to content
Snippets Groups Projects

Draft: feat: ...

Closed Carl P. Corliss requested to merge rabbixt/gitlab:rabbixt-negated-change-globs into master
1 file
+ 8
6
Compare changes
  • Side-by-side
  • Inline
@@ -5,6 +5,8 @@ module Ci
module Build
module Policy
class Changes < Policy::Specification
FNMATCH_FLAGS = File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB
def initialize(globs)
@globs = Array(globs)
end
@@ -18,18 +20,18 @@ def satisfied_by?(pipeline, context)
positive_matches = []
@globs.each do |glob|
if glob.start_with?('!') # negative glob pattern
negative_matches << File.fnmatch?(glob[1..], path, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB)
if glob.start_with?('!')
negative_matches << File.fnmatch?(glob[1..], path, FNMATCH_FLAGS)
else
positive_matches << File.fnmatch?(glob, path, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB)
positive_matches << File.fnmatch?(glob, path, FNMATCH_FLAGS)
end
end
if positive_matches.empty? && negative_matches.empty?
# Path doesn't match any of our patterns, so not a match
false
false
elsif positive_matches.empty?
# No positive matches means that we were only supplied negated patterns.
# No positive matches means that we were only supplied negated patterns.
# Which is the same as saying "Allow all EXCEPT these (negated) globs." So,
# if none of our negated globs matched, then the path is okay to allow.
!negative_matches.any?
@@ -43,4 +45,4 @@ def satisfied_by?(pipeline, context)
end
end
end
end
\ No newline at end of file
end
Loading