class PactBroker::Integrations::Service

Public Class Methods

delete(consumer_name, provider_name) click to toggle source
# File lib/pact_broker/integrations/service.rb, line 35
def self.delete(consumer_name, provider_name)
  consumer = pacticipant_service.find_pacticipant_by_name!(consumer_name)
  provider = pacticipant_service.find_pacticipant_by_name!(provider_name)
  # this takes care of the triggered webhooks and webhook executions
  pact_service.delete_all_pact_publications_between(consumer_name, and: provider_name)
  verification_service.delete_all_verifications_between(consumer_name, and: provider_name)
  pact_service.delete_all_pact_versions_between(consumer_name, and: provider_name)
  webhook_repository.delete_by_consumer_and_provider(consumer, provider)
  version_repository.delete_orphan_versions(consumer, provider)

  pacticipant_service.delete_if_orphan(consumer)
  pacticipant_service.delete_if_orphan(provider) unless consumer == provider
end
delete_all() click to toggle source
# File lib/pact_broker/integrations/service.rb, line 49
def self.delete_all
  # TODO move all these into their own repositories
  PactBroker::DB.each_integration_model do | model |
    if PactBroker::Repositories::Helpers.postgres?
      logger.info("Truncating ", model.table_name)
      model.truncate(cascade: true)
    else
      logger.info("Deleting all from ", model.table_name)
      # Mysql adapter needs to support cascade truncate
      # https://travis-ci.org/pact-foundation/pact_broker/jobs/633050220#L841
      # https://travis-ci.org/pact-foundation/pact_broker/jobs/633053228#L849
      model.dataset.delete
    end
  end
end
find_all() click to toggle source
# File lib/pact_broker/integrations/service.rb, line 17
def self.find_all
  # The only reason the pact_version needs to be loaded is that
  # the Verification::PseudoBranchStatus uses it to determine if
  # the pseudo branch is 'stale'.
  # Because this is the status for a pact, and not a pseudo branch,
  # the status can never be 'stale',
  # so it would be better to create a Verification::PactStatus class
  # that doesn't have the 'stale' logic in it.
  # Then we can remove the eager loading of the pact_version
  scope_for(PactBroker::Integrations::Integration)
    .eager(:consumer)
    .eager(:provider)
    .eager(latest_pact: [:latest_verification, :pact_version])
    .eager(:latest_verification)
    .all
    .sort { | a, b| b.latest_pact_or_verification_publication_date <=> a.latest_pact_or_verification_publication_date }
end
find_for_provider(provider) click to toggle source
# File lib/pact_broker/integrations/service.rb, line 65
def self.find_for_provider(provider)
  scope_for(PactBroker::Integrations::Integration).where(provider_id: provider.id).eager(:consumer).eager(:provider).all.sort
end