diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2018-09-05 13:39:41 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2018-09-05 13:39:41 +0000 |
commit | 464b0de1acfc9383a551a05efa8c8a705c8bf70c (patch) | |
tree | 6766e8c53a968ed40cd71748c0e0b7d622f8c3df /app/models/concerns | |
parent | 97ee68b1750bade46ef6c1d7c813bc917a13d89d (diff) | |
parent | 9d742e61a79dcc85589598259e2fdac030b7ac00 (diff) | |
download | gitlab-ce-464b0de1acfc9383a551a05efa8c8a705c8bf70c.tar.gz |
Merge branch 'filter-web-hooks-by-branch' into 'master'
Filter web hooks by branch
See merge request gitlab-org/gitlab-ce!19513
Diffstat (limited to 'app/models/concerns')
-rw-r--r-- | app/models/concerns/protected_ref.rb | 10 | ||||
-rw-r--r-- | app/models/concerns/triggerable_hooks.rb | 6 |
2 files changed, 14 insertions, 2 deletions
diff --git a/app/models/concerns/protected_ref.rb b/app/models/concerns/protected_ref.rb index e62e680af6e..af387c99f3d 100644 --- a/app/models/concerns/protected_ref.rb +++ b/app/models/concerns/protected_ref.rb @@ -50,14 +50,20 @@ module ProtectedRef .map(&:"#{action}_access_levels").flatten end + # Returns all protected refs that match the given ref name. + # This checks all records from the scope built up so far, and does + # _not_ return a relation. + # + # This method optionally takes in a list of `protected_refs` to search + # through, to avoid calling out to the database. def matching(ref_name, protected_refs: nil) - ProtectedRefMatcher.matching(self, ref_name, protected_refs: protected_refs) + (protected_refs || self.all).select { |protected_ref| protected_ref.matches?(ref_name) } end end private def ref_matcher - @ref_matcher ||= ProtectedRefMatcher.new(self) + @ref_matcher ||= RefMatcher.new(self.name) end end diff --git a/app/models/concerns/triggerable_hooks.rb b/app/models/concerns/triggerable_hooks.rb index 223a61119e5..c52baa0524c 100644 --- a/app/models/concerns/triggerable_hooks.rb +++ b/app/models/concerns/triggerable_hooks.rb @@ -29,6 +29,12 @@ module TriggerableHooks public_send(trigger) # rubocop:disable GitlabSecurity/PublicSend end + def select_active(hooks_scope, data) + select do |hook| + ActiveHookFilter.new(hook).matches?(hooks_scope, data) + end + end + private def triggerable_hooks(hooks) |