Sha256: 8fa0803905f54386deefef47b5bf3789948bd96ede977b22ca79022ed18d01c5

Contents?: true

Size: 1.85 KB

Versions: 17

Compression:

Stored size: 1.85 KB

Contents

require 'pact_broker/domain/webhook_request'
require 'pact_broker/messages'
require 'pact_broker/logging'
require 'pact_broker/api/contracts/webhook_contract'

module PactBroker
  module Domain
    class Webhook

      include Messages
      include Logging

      attr_accessor :uuid, :consumer, :provider, :request, :created_at, :updated_at, :events
      attr_reader :attributes

      def initialize attributes = {}
        @attributes = attributes
        @uuid = attributes[:uuid]
        @request = attributes[:request]
        @consumer = attributes[:consumer]
        @provider = attributes[:provider]
        @events = attributes[:events]
        @created_at = attributes[:created_at]
        @updated_at = attributes[:updated_at]
      end

      def 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

      def request_description
        request && request.description
      end

      def execute pact, verification, options
        logger.info "Executing #{self}"
        request.build(pact: pact, verification: verification).execute(options)
      end

      def to_s
        "webhook for consumer=#{consumer_name} provider=#{provider_name} uuid=#{uuid}"
      end

      def consumer_name
        consumer && consumer.name
      end

      def provider_name
        provider && provider.name
      end

      def trigger_on_contract_content_changed?
        events.any?(&:contract_content_changed?)
      end

      def trigger_on_provider_verification_published?
        events.any?(&:provider_verification_published?)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
pact_broker-2.30.0 lib/pact_broker/domain/webhook.rb
pact_broker-2.29.0 lib/pact_broker/domain/webhook.rb
pact_broker-2.27.6 lib/pact_broker/domain/webhook.rb
pact_broker-2.27.5 lib/pact_broker/domain/webhook.rb
pact_broker-2.27.4 lib/pact_broker/domain/webhook.rb
pact_broker-2.27.3 lib/pact_broker/domain/webhook.rb
pact_broker-2.27.2 lib/pact_broker/domain/webhook.rb
pact_broker-2.27.0 lib/pact_broker/domain/webhook.rb
pact_broker-2.26.1 lib/pact_broker/domain/webhook.rb
pact_broker-2.26.0 lib/pact_broker/domain/webhook.rb
pact_broker-2.25.0 lib/pact_broker/domain/webhook.rb
pact_broker-2.24.0 lib/pact_broker/domain/webhook.rb
pact_broker-2.23.4 lib/pact_broker/domain/webhook.rb
pact_broker-2.23.3 lib/pact_broker/domain/webhook.rb
pact_broker-2.23.2 lib/pact_broker/domain/webhook.rb
pact_broker-2.23.1 lib/pact_broker/domain/webhook.rb
pact_broker-2.23.0 lib/pact_broker/domain/webhook.rb