Class: Gitlab::Ci::Build::Rules::Rule::Clause::Exists

Inherits:
Gitlab::Ci::Build::Rules::Rule::Clause show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/ci/build/rules/rule/clause/exists.rb

Constant Summary collapse

MAX_PATTERN_COMPARISONS =

The maximum number of patterned glob comparisons that will be performed before the rule assumes that it has a match

10_000
WILDCARD_NESTED_PATTERN =
"**/*"

Constants inherited from Gitlab::Ci::Build::Rules::Rule::Clause

ParseError, UnknownClauseError

Instance Method Summary collapse

Methods inherited from Gitlab::Ci::Build::Rules::Rule::Clause

fabricate

Constructor Details

#initialize(clause) ⇒ Exists

Returns a new instance of Exists.



15
16
17
18
19
# File 'lib/gitlab/ci/build/rules/rule/clause/exists.rb', line 15

def initialize(clause)
  @globs = Array(clause[:paths])
  @project_path = clause[:project]
  @ref = clause[:ref]
end

Instance Method Details

#satisfied_by?(_pipeline, context) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gitlab/ci/build/rules/rule/clause/exists.rb', line 21

def satisfied_by?(_pipeline, context)
  # Return early to avoid redundant Gitaly calls
  return false unless @globs.any?

  context = change_context(context) if @project_path

  expanded_globs = expand_globs(context)
  top_level_only = expanded_globs.all?(&method(:top_level_glob?))

  paths = worktree_paths(context, top_level_only)
  exact_globs, extension_globs, pattern_globs = separate_globs(expanded_globs)

  exact_matches?(paths, exact_globs) ||
    matches_extension?(paths, extension_globs) ||
    pattern_matches?(paths, pattern_globs, context)
end