debian-mirror-gitlab/app/models/concerns/integrations/has_web_hook.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.3 KiB
Ruby
Raw Normal View History

2021-09-30 23:02:18 +05:30
# frozen_string_literal: true
module Integrations
module HasWebHook
extend ActiveSupport::Concern
included do
after_save :update_web_hook!, if: :activated?
2022-11-25 23:54:43 +05:30
has_one :service_hook, inverse_of: :integration, foreign_key: :integration_id
2021-09-30 23:02:18 +05:30
end
# Return the URL to be used for the webhook.
def hook_url
raise NotImplementedError
end
2022-10-02 17:18:49 +05:30
# Return the url variables to be used for the webhook.
def url_variables
raise NotImplementedError
end
2021-09-30 23:02:18 +05:30
# Return whether the webhook should use SSL verification.
def hook_ssl_verification
2022-02-05 19:09:49 +05:30
if respond_to?(:enable_ssl_verification)
enable_ssl_verification
else
true
end
2021-09-30 23:02:18 +05:30
end
# Create or update the webhook, raising an exception if it cannot be saved.
def update_web_hook!
hook = service_hook || build_service_hook
2022-10-02 17:18:49 +05:30
# Avoid reencryption
hook.url = hook_url if hook.url != hook_url
hook.url_variables = url_variables if hook.url_variables != url_variables
2021-09-30 23:02:18 +05:30
hook.enable_ssl_verification = hook_ssl_verification
hook.save! if hook.changed?
hook
end
# Execute the webhook, creating it if necessary.
2023-04-23 21:23:45 +05:30
def execute_web_hook!(...)
2021-09-30 23:02:18 +05:30
update_web_hook!
2023-04-23 21:23:45 +05:30
service_hook.execute(...)
2021-09-30 23:02:18 +05:30
end
end
end