class PactBroker::Domain::Webhook
Attributes
request is actually a request_template
request is actually a request_template
request is actually a request_template
request is actually a request_template
request is actually a request_template
request is actually a request_template
request is actually a request_template
request is actually a request_template
request is actually a request_template
Public Class Methods
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
Source
# File lib/pact_broker/domain/webhook.rb, line 65 def consumer_name consumer && (consumer.name || (consumer.label && "#{provider ? 'consumers ' : ''}labeled '#{consumer.label}'")) end
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
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.slice(:user_agent, :disable_ssl_verification, :cert_store)) 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
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
Source
# File lib/pact_broker/domain/webhook.rb, line 69 def provider_name provider && (provider.name || (provider.label && "#{consumer ? 'providers ' : ''}labeled '#{provider.label}'")) end
Source
# File lib/pact_broker/domain/webhook.rb, line 46 def request_description request && request.description end
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
Source
# File lib/pact_broker/domain/webhook.rb, line 61 def to_s "webhook for consumer=#{consumer_name} provider=#{provider_name} uuid=#{uuid}" end
Source
# File lib/pact_broker/domain/webhook.rb, line 73 def trigger_on_contract_content_changed? events.any?(&:contract_content_changed?) end
Source
# File lib/pact_broker/domain/webhook.rb, line 89 def trigger_on_contract_requiring_verification_published? events.any?(&:contract_requiring_verification_published?) end
Source
# File lib/pact_broker/domain/webhook.rb, line 85 def trigger_on_provider_verification_failed? events.any?(&:provider_verification_failed?) end
Source
# File lib/pact_broker/domain/webhook.rb, line 77 def trigger_on_provider_verification_published? events.any?(&:provider_verification_published?) end
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
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
Source
# 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
rubocop: disable Metrics/ParameterLists
Source
# 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
robocop: enable Metrics/ParameterLists
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
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