Module: PactBroker::Contracts::Service

Extended by:
Service, Messages, Repositories, Services
Includes:
Logging
Included in:
Service
Defined in:
lib/pact_broker/contracts/service.rb

Defined Under Namespace

Classes: TriggeredWebhooksCreatedListener

Constant Summary

Constants included from Repositories

Repositories::REPOSITORY_FACTORIES

Constants included from Services

Services::SERVICE_FACTORIES

Instance Method Summary collapse

Methods included from Repositories

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 Messages

message, pluralize, validation_message, validation_message_at_index

Methods included from Logging

included, #log_error, #log_with_tag, #measure_info

Instance Method Details

#conflict_notices(parsed_contracts, base_url:) ⇒ Object



49
50
51
52
53
54
# File 'lib/pact_broker/contracts/service.rb', line 49

def conflict_notices(parsed_contracts, base_url: )
  notices = []
  add_pact_conflict_notices(notices, parsed_contracts)
  add_pacticipant_conflict_notices(notices, parsed_contracts, base_url)
  notices
end

#create_or_update_integrations(pacts) ⇒ Object

Creating/updating the integrations all at once at the end of the transaction instead of one by one, as each pact is created, reduces the amount of time that a lock is held on the integrations table, therefore reducing contention and potential for deadlocks when there are many pacts being published at once.



311
312
313
# File 'lib/pact_broker/contracts/service.rb', line 311

def create_or_update_integrations(pacts)
  integration_service.handle_bulk_contract_data_published(pacts)
end

#publish(parsed_contracts, base_url:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pact_broker/contracts/service.rb', line 33

def publish(parsed_contracts, base_url: )
  logger.info("Publishing contracts", parsed_contracts.logging_info)
  version, version_notices = create_version(parsed_contracts)
  tags = create_tags(parsed_contracts, version)
  pacts, pact_notices = create_pacts(parsed_contracts, base_url)
  create_or_update_integrations(pacts)
  notices = version_notices + pact_notices
  ContractsPublicationResults.from_hash(
    pacticipant: version.pacticipant,
    version: version,
    tags: tags,
    contracts: pacts,
    notices: notices
  )
end

#triggered_webhook_notices(listener, pact) ⇒ Object



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/pact_broker/contracts/service.rb', line 282

def triggered_webhook_notices(listener, pact)
  triggered_webhooks = listener.detected_events.flat_map(&:triggered_webhooks)
  if triggered_webhooks.any?
    triggered_webhooks.collect do | triggered_webhook |
      base_url = triggered_webhook.event_context[:base_url]
      triggered_webhooks_notices_url = url_for_triggered_webhook(triggered_webhook, base_url)
      text_2_params = { webhook_description: triggered_webhook.webhook.description&.inspect || triggered_webhook.webhook_uuid, event_name: triggered_webhook.event_name }
      text_1 = message("messages.webhooks.webhook_triggered_for_event", text_2_params)
      text_2 = message("messages.webhooks.triggered_webhook_see_logs", url: triggered_webhooks_notices_url)
      Notice.debug("  #{text_1}\n    #{text_2}")
    end
  else
    if webhook_service.any_webhooks_configured_for_pact?(pact)
      # There are some webhooks, just not any for this particular event
      [Notice.debug("  " + message("messages.webhooks.no_webhooks_enabled_for_event"))]
    else
      []
    end
  end
end