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)
|
2022-04-04 11:22:00 +05:30
|
|
|
return true unless pipeline&.modified_paths
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
expanded_globs = expand_globs(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
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
def expand_globs(context)
|
2021-01-29 00:20:46 +05:30
|
|
|
return @globs unless context
|
|
|
|
|
|
|
|
@globs.map do |glob|
|
2022-01-26 12:08:38 +05:30
|
|
|
ExpandVariables.expand_existing(glob, -> { context.variables_hash })
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|