Sha256: 4671dc7a3bd6e97a6b06c1c1224ac6c5f59218b2b5a1a9ec551e5ae54bababb1

Contents?: true

Size: 1.79 KB

Versions: 68

Compression:

Stored size: 1.79 KB

Contents

require 'pact_broker/client/error'
require 'pact_broker/client/pact_broker_client'
require 'pact_broker/client/retry'

module PactBroker
  module Client
    class CreateTag

      def self.call(pact_broker_base_url, pacticipant_name, version, tags, auto_create_version, pact_broker_client_options={})
        new(pact_broker_base_url, pacticipant_name, version, tags, auto_create_version, pact_broker_client_options).call
      end

      def initialize(pact_broker_base_url, pacticipant_name, version, tags, auto_create_version, pact_broker_client_options)
        @pact_broker_base_url = pact_broker_base_url
        @pacticipant_name = pacticipant_name
        @version = version
        @tags = tags
        @auto_create_version = auto_create_version
        @pact_broker_client_options = pact_broker_client_options
      end

      def call
        ensure_version_exists if !auto_create_version
        tags.each do | tag |
          $stdout.puts "Tagging #{pacticipant_name} version #{version} as #{tag}"
          Retry.while_error do
            pact_broker_client.pacticipants.versions.tag pacticipant: pacticipant_name, version: version, tag: tag
          end
        end
      end

      private

      attr_reader :pact_broker_base_url, :pacticipant_name, :version, :tags, :auto_create_version, :pact_broker_client_options

      def pact_broker_client
        @pact_broker_client ||= PactBroker::Client::PactBrokerClient.new(base_url: pact_broker_base_url, client_options: pact_broker_client_options)
      end

      def ensure_version_exists
        if pact_broker_client.pacticipants.versions.find(pacticipant: pacticipant_name, version: version).nil?
          raise PactBroker::Client::Error.new("Could not create tag. Version #{version} of #{pacticipant_name} does not exist.")
        end
      end
    end
  end
end

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
pact_broker-client-1.63.0 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.62.1 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.62.0 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.61.1 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.61.0 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.60.0 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.59.0 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.58.0 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.57.0 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.56.0 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.55.0 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.54.0 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.53.0 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.52.0 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.51.2 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.51.1 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.51.0 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.50.0 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.49.0 lib/pact_broker/client/create_tag.rb
pact_broker-client-1.48.0 lib/pact_broker/client/create_tag.rb