Module: PactBroker::Webhooks::TriggerService
Constant Summary
collapse
- RESOURCE_CREATION =
PactBroker::Webhooks::TriggeredWebhook::TRIGGER_TYPE_RESOURCE_CREATION
- USER =
PactBroker::Webhooks::TriggeredWebhook::TRIGGER_TYPE_USER
Repositories::REPOSITORY_FACTORIES
Constants included
from Services
Services::SERVICE_FACTORIES
Instance Method Summary
collapse
branch_repository, branch_version_repository, get_repository, integration_repository, label_repository, matrix_repository, pact_repository, pacticipant_repository, register_default_repositories, register_repository, tag_repository, verification_repository, version_repository, webhook_repository
Methods included from Services
badge_service, branch_service, certificate_service, contract_service, deployed_version_service, environment_service, get_service, group_service, index_service, integration_service, label_service, matrix_service, metrics_service, pact_service, pacticipant_service, register_default_services, register_service, released_version_service, tag_service, verification_service, version_service, webhook_service, webhook_trigger_service
Methods included from Logging
included, #log_error, #log_with_tag, #measure_info
Instance Method Details
#create_triggered_webhooks_for_event(pact, verification, event_name, event_context) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/pact_broker/webhooks/trigger_service.rb', line 17
def create_triggered_webhooks_for_event pact, verification, event_name, event_context
webhooks = webhook_repository.find_webhooks_to_trigger(consumer: pact.consumer, provider: pact.provider, event_name: event_name)
if webhooks.any?
create_triggered_webhooks_for_webhooks(webhooks, pact, verification, event_name, event_context.merge(event_name: event_name))
else
[]
end
end
|
#execute_triggered_webhook_now(triggered_webhook, webhook_execution_configuration_hash) ⇒ Object
43
44
45
46
47
|
# File 'lib/pact_broker/webhooks/trigger_service.rb', line 43
def execute_triggered_webhook_now triggered_webhook, webhook_execution_configuration_hash
webhook_execution_result = triggered_webhook.execute(webhook_execution_configuration_hash)
webhook_repository.create_execution(triggered_webhook, webhook_execution_result)
webhook_execution_result
end
|
#expand_events_for_required_verifications(event_name, pact, event_contexts) ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/pact_broker/webhooks/trigger_service.rb', line 132
def expand_events_for_required_verifications(event_name, pact, event_contexts)
if event_name == PactBroker::Webhooks::WebhookEvent::CONTRACT_REQUIRING_VERIFICATION_PUBLISHED
required_verifications = verification_service.calculate_required_verifications_for_pact(pact)
event_contexts.flat_map do | event_context |
required_verifications.collect do | required_verification |
event_context.merge(
provider_version_number: required_verification.provider_version.number,
provider_version_branch: provider_version_branch_for_required_verification(required_verification, ),
provider_version_descriptions: required_verification.provider_version_descriptions.uniq
)
end
end
else
event_contexts
end
end
|
#next_uuid ⇒ Object
27
28
29
|
# File 'lib/pact_broker/webhooks/trigger_service.rb', line 27
def next_uuid
SecureRandom.uuid
end
|
#provider_version_branch_for_required_verification(required_verification) ⇒ Object
149
150
151
|
# File 'lib/pact_broker/webhooks/trigger_service.rb', line 149
def provider_version_branch_for_required_verification(required_verification)
required_verification.provider_version_selectors.find(&:latest_for_main_branch?)&.resolved_branch_name || required_verification.provider_version.branch_versions.last&.branch_name
end
|
#schedule_webhooks(triggered_webhooks, options) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/pact_broker/webhooks/trigger_service.rb', line 49
def schedule_webhooks(triggered_webhooks, options)
triggered_webhooks.each_with_index do | triggered_webhook, i |
logger.info "Scheduling job for webhook with uuid #{triggered_webhook.webhook.uuid}, context: #{triggered_webhook.event_context}"
logger.debug "Schedule webhook with options #{options}"
job_data = { triggered_webhook: triggered_webhook }.deep_merge(options)
begin
Job.perform_in(5 + (i * 3), job_data)
rescue StandardError => e
logger.warn("Error scheduling webhook execution for webhook with uuid #{triggered_webhook&.webhook&.uuid}", e)
nil
end
end
end
|
#test_execution(webhook, event_context, execution_configuration) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/pact_broker/webhooks/trigger_service.rb', line 31
def test_execution webhook, event_context, execution_configuration
merged_options = execution_configuration.with_failure_log_message("Webhook execution failed").to_hash
verification = nil
if webhook.trigger_on_provider_verification_published?
verification = verification_service.search_for_latest(webhook.consumer_name, webhook.provider_name) || PactBroker::Verifications::PlaceholderVerification.new
end
pact = pact_service.search_for_latest_pact(consumer_name: webhook.consumer_name, provider_name: webhook.provider_name) || PactBroker::Pacts::PlaceholderPact.new
webhook.execute(pact, verification, event_context.merge(event_name: "test"), merged_options)
end
|