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

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

Constant Summary

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(globs) ⇒ Changes

Returns a new instance of Changes.



9
10
11
# File 'lib/gitlab/ci/build/rules/rule/clause/changes.rb', line 9

def initialize(globs)
  @globs = globs
end

Instance Method Details

#satisfied_by?(pipeline, context) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gitlab/ci/build/rules/rule/clause/changes.rb', line 13

def satisfied_by?(pipeline, context)
  compare_to_sha = find_compare_to_sha(pipeline, context)
  modified_paths = find_modified_paths(pipeline, compare_to_sha)

  return true unless modified_paths
  return false if modified_paths.empty?

  expanded_globs = expand_globs(context).uniq
  return false if expanded_globs.empty?

  cache_key = [
    self.class.to_s,
    '#satisfied_by?',
    pipeline.project_id,
    pipeline.sha,
    compare_to_sha,
    expanded_globs.sort
  ]
  Gitlab::SafeRequestStore.fetch(cache_key) do
    match?(expanded_globs, modified_paths)
  end
end