summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/build/rules/rule/clause/changes.rb
blob: 81d2ee6c24c41812b083dc2b039a0776155ac74e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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

        def satisfied_by?(pipeline, seed)
          return true if pipeline.modified_paths.nil?

          pipeline.modified_paths.any? do |path|
            @globs.any? do |glob|
              File.fnmatch?(glob, path, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB)
            end
          end
        end
      end
    end
  end
end