Welcome to mirror list, hosted at ThFree Co, Russian Federation.

active_hook_filter.rb « hooks « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4599ebf8717ef44fdc20b8ae9de39bab09486e8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

class ActiveHookFilter
  def initialize(hook)
    @hook = hook
  end

  def matches?(hooks_scope, data)
    return true unless hooks_scope == :push_hooks

    matches_branch?(data)
  end

  private

  def matches_branch?(data)
    return true if @hook.push_events_branch_filter.blank?

    branch_name = Gitlab::Git.branch_name(data[:ref])

    case @hook.branch_filter_strategy
    when 'all_branches'
      true
    when 'wildcard'
      RefMatcher.new(@hook.push_events_branch_filter).matches?(branch_name)
    when 'regex'
      begin
        Gitlab::UntrustedRegexp.new(@hook.push_events_branch_filter) === branch_name
      rescue RegexpError
        false
      end
    end
  end
end