debian-mirror-gitlab/lib/gitlab/ci/build/rules/rule/clause/changes.rb

34 lines
976 B
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
module Build
class Rules::Rule::Clause::Changes < Rules::Rule::Clause
def initialize(globs)
@globs = Array(globs)
end
2019-12-26 22:10:19 +05:30
def satisfied_by?(pipeline, context)
2019-12-04 20:38:33 +05:30
return true if pipeline.modified_paths.nil?
2021-01-29 00:20:46 +05:30
expanded_globs = expand_globs(pipeline, context)
2019-12-04 20:38:33 +05:30
pipeline.modified_paths.any? do |path|
2021-01-29 00:20:46 +05:30
expanded_globs.any? do |glob|
2019-12-04 20:38:33 +05:30
File.fnmatch?(glob, path, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB)
end
end
end
2021-01-29 00:20:46 +05:30
def expand_globs(pipeline, context)
return @globs unless ::Feature.enabled?(:ci_variable_expansion_in_rules_changes, pipeline.project, default_enabled: true)
return @globs unless context
@globs.map do |glob|
ExpandVariables.expand_existing(glob, context.variables)
end
end
2019-12-04 20:38:33 +05:30
end
end
end
end