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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.1 KiB
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
2022-08-13 15:12:31 +05:30
include Gitlab::Utils::StrongMemoize
2019-12-04 20:38:33 +05:30
def initialize(globs)
2022-08-13 15:12:31 +05:30
@globs = globs
2019-12-04 20:38:33 +05:30
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
2022-08-13 15:12:31 +05:30
private
2021-02-22 17:27:13 +05:30
def expand_globs(context)
2022-08-13 15:12:31 +05:30
return paths unless context
2021-01-29 00:20:46 +05:30
2022-08-13 15:12:31 +05:30
paths.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
2022-08-13 15:12:31 +05:30
def paths
strong_memoize(:paths) do
if @globs.is_a?(Array)
@globs
else
Array(@globs[:paths])
end
end
end
2019-12-04 20:38:33 +05:30
end
end
end
end