class PactBroker::Domain::Webhook
Attributes
attributes[R]
consumer[RW]
request is actually a request_template
created_at[RW]
request is actually a request_template
description[RW]
request is actually a request_template
enabled[RW]
request is actually a request_template
events[RW]
request is actually a request_template
provider[RW]
request is actually a request_template
request[RW]
request is actually a request_template
updated_at[RW]
request is actually a request_template
uuid[RW]
request is actually a request_template
Public Class Methods
new(attributes = {})
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 19 def initialize attributes = {} @attributes = attributes attributes.each do | (name, value) | instance_variable_set("@#{name}", value) if respond_to?(name) end end
Public Instance Methods
consumer_name()
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 65 def consumer_name consumer && (consumer.name || (consumer.label && "#{provider ? 'consumers ' : ''}labeled '#{consumer.label}'")) end
display_description()
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 26 def display_description if description && description.strip.size > 0 description else request_description end end
execute(pact, verification, event_context, options)
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 50 def execute pact, verification, event_context, options logger.info "Executing #{self} event_context=#{event_context}" template_params = template_parameters(pact, verification, event_context, options) webhook_request = request.build(template_params, options.fetch(:user_agent)) http_response, error = execute_request(webhook_request) success = success?(http_response, options) http_request = webhook_request.http_request logs = generate_logs(webhook_request, http_response, success, error, event_context, options.fetch(:logging_options)) result(http_request, http_response, success, logs, error) end
expand_currently_deployed_provider_versions?()
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 93 def expand_currently_deployed_provider_versions? request.uses_parameter?(PactBroker::Webhooks::PactAndVerificationParameters::CURRENTLY_DEPLOYED_PROVIDER_VERSION_NUMBER) end
provider_name()
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 69 def provider_name provider && (provider.name || (provider.label && "#{consumer ? 'providers ' : ''}labeled '#{provider.label}'")) end
request_description()
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 46 def request_description request && request.description end
scope_description()
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 34 def scope_description if consumer && provider "A webhook for the pact between #{consumer_name} and #{provider_name}" elsif provider "A webhook for all pacts with provider #{provider_name}" elsif consumer "A webhook for all pacts with consumer #{consumer_name}" else "A webhook for all pacts" end end
to_s()
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 61 def to_s "webhook for consumer=#{consumer_name} provider=#{provider_name} uuid=#{uuid}" end
trigger_on_contract_content_changed?()
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 73 def trigger_on_contract_content_changed? events.any?(&:contract_content_changed?) end
trigger_on_contract_requiring_verification_published?()
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 89 def trigger_on_contract_requiring_verification_published? events.any?(&:contract_requiring_verification_published?) end
trigger_on_provider_verification_failed?()
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 85 def trigger_on_provider_verification_failed? events.any?(&:provider_verification_failed?) end
trigger_on_provider_verification_published?()
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 77 def trigger_on_provider_verification_published? events.any?(&:provider_verification_published?) end
trigger_on_provider_verification_succeeded?()
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 81 def trigger_on_provider_verification_succeeded? events.any?(&:provider_verification_succeeded?) end
Private Instance Methods
execute_request(webhook_request)
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 99 def execute_request(webhook_request) http_response = nil error = nil begin http_response = webhook_request.execute rescue StandardError => e error = e end return http_response, error end
generate_logs(webhook_request, http_response, success, error, event_context, logging_options)
click to toggle source
rubocop: disable Metrics/ParameterLists
# File lib/pact_broker/domain/webhook.rb, line 119 def generate_logs(webhook_request, http_response, success, error, event_context, logging_options) webhook_request_logger = PactBroker::Webhooks::WebhookRequestLogger.new(logging_options) webhook_request_logger.log( uuid, webhook_request, http_response, success, error, event_context ) end
result(http_request, http_response, success, logs, error)
click to toggle source
robocop: enable Metrics/ParameterLists
# File lib/pact_broker/domain/webhook.rb, line 132 def result(http_request, http_response, success, logs, error) PactBroker::Webhooks::WebhookExecutionResult.new( http_request, http_response, success, logs, error ) end
success?(http_response, options)
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 114 def success?(http_response, options) !http_response.nil? && options.fetch(:http_success_codes).include?(http_response.code.to_i) end
template_parameters(pact, verification, event_context, _options)
click to toggle source
# File lib/pact_broker/domain/webhook.rb, line 110 def template_parameters(pact, verification, event_context, _options) PactBroker::Webhooks::PactAndVerificationParameters.new(pact, verification, event_context).to_hash end