2018-08-03 13:22:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-04 05:18:54 -05:00
|
|
|
module TriggerableHooks
|
|
|
|
AVAILABLE_TRIGGERS = {
|
|
|
|
repository_update_hooks: :repository_update_events,
|
|
|
|
push_hooks: :push_events,
|
|
|
|
tag_push_hooks: :tag_push_events,
|
|
|
|
issue_hooks: :issues_events,
|
2018-08-17 19:15:21 -04:00
|
|
|
confidential_note_hooks: :confidential_note_events,
|
2017-12-04 05:18:54 -05:00
|
|
|
confidential_issue_hooks: :confidential_issues_events,
|
|
|
|
note_hooks: :note_events,
|
|
|
|
merge_request_hooks: :merge_requests_events,
|
|
|
|
job_hooks: :job_events,
|
|
|
|
pipeline_hooks: :pipeline_events,
|
2020-08-10 11:09:49 -04:00
|
|
|
wiki_page_hooks: :wiki_page_events,
|
2020-10-28 11:08:49 -04:00
|
|
|
deployment_hooks: :deployment_events,
|
2020-11-06 19:08:58 -05:00
|
|
|
feature_flag_hooks: :feature_flag_events,
|
2020-12-16 01:10:11 -05:00
|
|
|
release_hooks: :releases_events,
|
|
|
|
member_hooks: :member_events
|
2017-12-04 05:18:54 -05:00
|
|
|
}.freeze
|
|
|
|
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
class_methods do
|
2017-12-08 08:17:15 -05:00
|
|
|
attr_reader :triggers
|
|
|
|
|
2017-12-04 06:51:39 -05:00
|
|
|
def hooks_for(trigger)
|
2017-12-08 08:17:15 -05:00
|
|
|
callable_scopes = triggers.keys + [:all]
|
2017-12-04 09:29:13 -05:00
|
|
|
return none unless callable_scopes.include?(trigger)
|
2017-12-04 06:51:39 -05:00
|
|
|
|
|
|
|
public_send(trigger) # rubocop:disable GitlabSecurity/PublicSend
|
|
|
|
end
|
|
|
|
|
2018-09-01 11:55:06 -04:00
|
|
|
def select_active(hooks_scope, data)
|
|
|
|
select do |hook|
|
|
|
|
ActiveHookFilter.new(hook).matches?(hooks_scope, data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-04 05:18:54 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def triggerable_hooks(hooks)
|
|
|
|
triggers = AVAILABLE_TRIGGERS.slice(*hooks)
|
2017-12-08 08:17:15 -05:00
|
|
|
@triggers = triggers
|
2017-12-04 05:18:54 -05:00
|
|
|
|
2017-12-08 08:17:15 -05:00
|
|
|
triggers.each do |trigger, event|
|
2017-12-04 05:18:54 -05:00
|
|
|
scope trigger, -> { where(event => true) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|