Class: PactBroker::Domain::Webhook

Inherits:
Object
  • Object
show all
Includes:
Logging, Messages
Defined in:
lib/pact_broker/domain/webhook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, #log_error, #log_with_tag, #measure_info

Methods included from Messages

#message, #pluralize, #validation_message, #validation_message_at_index

Constructor Details

#initialize(attributes = {}) ⇒ Webhook

Returns a new instance of Webhook.



19
20
21
22
23
24
# 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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



17
18
19
# File 'lib/pact_broker/domain/webhook.rb', line 17

def attributes
  @attributes
end

#consumerObject

request is actually a request_template



16
17
18
# File 'lib/pact_broker/domain/webhook.rb', line 16

def consumer
  @consumer
end

#created_atObject

request is actually a request_template



16
17
18
# File 'lib/pact_broker/domain/webhook.rb', line 16

def created_at
  @created_at
end

#descriptionObject

request is actually a request_template



16
17
18
# File 'lib/pact_broker/domain/webhook.rb', line 16

def description
  @description
end

#enabledObject

request is actually a request_template



16
17
18
# File 'lib/pact_broker/domain/webhook.rb', line 16

def enabled
  @enabled
end

#eventsObject

request is actually a request_template



16
17
18
# File 'lib/pact_broker/domain/webhook.rb', line 16

def events
  @events
end

#providerObject

request is actually a request_template



16
17
18
# File 'lib/pact_broker/domain/webhook.rb', line 16

def provider
  @provider
end

#requestObject

request is actually a request_template



16
17
18
# File 'lib/pact_broker/domain/webhook.rb', line 16

def request
  @request
end

#updated_atObject

request is actually a request_template



16
17
18
# File 'lib/pact_broker/domain/webhook.rb', line 16

def updated_at
  @updated_at
end

#uuidObject

request is actually a request_template



16
17
18
# File 'lib/pact_broker/domain/webhook.rb', line 16

def uuid
  @uuid
end

Instance Method Details

#consumer_nameObject



65
66
67
# File 'lib/pact_broker/domain/webhook.rb', line 65

def consumer_name
  consumer && (consumer.name || (consumer.label && "#{provider ? 'consumers ' : ''}labeled '#{consumer.label}'"))
end

#display_descriptionObject



26
27
28
29
30
31
32
# 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) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# 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

#expand_currently_deployed_provider_versions?Boolean

Returns:

  • (Boolean)


93
94
95
# 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_nameObject



69
70
71
# File 'lib/pact_broker/domain/webhook.rb', line 69

def provider_name
  provider && (provider.name || (provider.label && "#{consumer ? 'providers ' : ''}labeled '#{provider.label}'"))
end

#request_descriptionObject



46
47
48
# File 'lib/pact_broker/domain/webhook.rb', line 46

def request_description
  request && request.description
end

#scope_descriptionObject



34
35
36
37
38
39
40
41
42
43
44
# 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_sObject



61
62
63
# 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?Boolean

Returns:

  • (Boolean)


73
74
75
# 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?Boolean

Returns:

  • (Boolean)


89
90
91
# 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?Boolean

Returns:

  • (Boolean)


85
86
87
# 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?Boolean

Returns:

  • (Boolean)


77
78
79
# 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?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/pact_broker/domain/webhook.rb', line 81

def trigger_on_provider_verification_succeeded?
  events.any?(&:provider_verification_succeeded?)
end