debian-mirror-gitlab/app/models/concerns/triggerable_hooks.rb

53 lines
1.4 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module TriggerableHooks
AVAILABLE_TRIGGERS = {
2022-08-27 11:52:29 +05:30
repository_update_hooks: :repository_update_events,
push_hooks: :push_events,
tag_push_hooks: :tag_push_events,
issue_hooks: :issues_events,
confidential_note_hooks: :confidential_note_events,
2018-03-17 18:26:18 +05:30
confidential_issue_hooks: :confidential_issues_events,
2022-08-27 11:52:29 +05:30
note_hooks: :note_events,
merge_request_hooks: :merge_requests_events,
job_hooks: :job_events,
pipeline_hooks: :pipeline_events,
wiki_page_hooks: :wiki_page_events,
deployment_hooks: :deployment_events,
feature_flag_hooks: :feature_flag_events,
release_hooks: :releases_events,
member_hooks: :member_events,
subgroup_hooks: :subgroup_events
2018-03-17 18:26:18 +05:30
}.freeze
extend ActiveSupport::Concern
class_methods do
attr_reader :triggers
def hooks_for(trigger)
callable_scopes = triggers.keys + [:all]
return none unless callable_scopes.include?(trigger)
2021-06-08 01:23:25 +05:30
executable.public_send(trigger) # rubocop:disable GitlabSecurity/PublicSend
2018-03-17 18:26:18 +05:30
end
2018-11-20 20:47:30 +05:30
def select_active(hooks_scope, data)
2021-06-08 01:23:25 +05:30
executable.select do |hook|
2018-11-20 20:47:30 +05:30
ActiveHookFilter.new(hook).matches?(hooks_scope, data)
end
end
2018-03-17 18:26:18 +05:30
private
def triggerable_hooks(hooks)
triggers = AVAILABLE_TRIGGERS.slice(*hooks)
@triggers = triggers
triggers.each do |trigger, event|
scope trigger, -> { where(event => true) }
end
end
end
end