diff options
Diffstat (limited to 'app/models/hooks/active_hook_filter.rb')
-rw-r--r-- | app/models/hooks/active_hook_filter.rb | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/app/models/hooks/active_hook_filter.rb b/app/models/hooks/active_hook_filter.rb index 283e2d680f4..cdcfd3f3ff5 100644 --- a/app/models/hooks/active_hook_filter.rb +++ b/app/models/hooks/active_hook_filter.rb @@ -3,14 +3,36 @@ class ActiveHookFilter def initialize(hook) @hook = hook - @push_events_filter_matcher = RefMatcher.new(@hook.push_events_branch_filter) end def matches?(hooks_scope, data) - return true if hooks_scope != :push_hooks + 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]) - @push_events_filter_matcher.matches?(branch_name) + + if Feature.disabled?(:enhanced_webhook_support_regex) + return RefMatcher.new(@hook.push_events_branch_filter).matches?(branch_name) + end + + 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 |