Module: Integrations::HasWebHook

Extended by:
ActiveSupport::Concern
Included in:
Buildkite, Datadog, DroneCi, Jenkins, Packagist, SquashTm
Defined in:
app/models/concerns/integrations/has_web_hook.rb

Instance Method Summary collapse

Instance Method Details

#execute_web_hook!Object

Execute the webhook, creating it if necessary.



53
54
55
56
# File 'app/models/concerns/integrations/has_web_hook.rb', line 53

def execute_web_hook!(...)
  update_web_hook!
  service_hook.execute(...)
end

#hook_ssl_verificationObject

Return whether the webhook should use SSL verification.



23
24
25
26
27
28
29
# File 'app/models/concerns/integrations/has_web_hook.rb', line 23

def hook_ssl_verification
  if respond_to?(:enable_ssl_verification)
    enable_ssl_verification
  else
    true
  end
end

#hook_urlObject

Return the URL to be used for the webhook.

Raises:

  • (NotImplementedError)


13
14
15
# File 'app/models/concerns/integrations/has_web_hook.rb', line 13

def hook_url
  raise NotImplementedError
end

#update_web_hook!Object

Create or update the webhook, raising an exception if it cannot be saved.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/concerns/integrations/has_web_hook.rb', line 32

def update_web_hook!
  hook = service_hook || build_service_hook

  # Avoid reencryption
  hook.url = hook_url if hook.url != hook_url
  hook.url_variables = url_variables if hook.url_variables != url_variables

  hook.enable_ssl_verification = hook_ssl_verification

  # Set hook sharding key
  integration = hook.integration

  hook.project_id = integration.project_id if integration.project_id
  hook.group_id = integration.group_id if integration.group_id
  hook.organization_id = integration.organization_id if integration.organization_id

  hook.save! if hook.changed?
  hook
end

#url_variablesObject

Return the url variables to be used for the webhook.

Raises:

  • (NotImplementedError)


18
19
20
# File 'app/models/concerns/integrations/has_web_hook.rb', line 18

def url_variables
  raise NotImplementedError
end