class PactBroker::Client::PublicationTask

Attributes

auto_detect_version_properties[R]
branch[W]
build_url[RW]
consumer_version[W]
pact_broker_base_url[RW]
pact_broker_basic_auth[RW]
pact_broker_token[RW]
pattern[RW]
tag[RW]
tag_with_git_branch[RW]
tags=[RW]
write_method[RW]

Public Class Methods

new(name = nil, &block) click to toggle source
# File lib/pact_broker/client/tasks/publication_task.rb, line 32
def initialize name = nil, &block
  @name = name
  @auto_detect_version_properties = nil
  @pattern = 'spec/pacts/*.json'
  @pact_broker_base_url = 'http://pact-broker'
  rake_task &block
end

Public Instance Methods

auto_detect_version_properties=(auto_detect_version_properties) click to toggle source
# File lib/pact_broker/client/tasks/publication_task.rb, line 40
def auto_detect_version_properties= auto_detect_version_properties
  @auto_detect_version_properties = auto_detect_version_properties
end

Private Instance Methods

all_tags() click to toggle source
# File lib/pact_broker/client/tasks/publication_task.rb, line 74
def all_tags
  t = [*tags]
  t << PactBroker::Client::Git.branch(raise_error: true) if tag_with_git_branch
  t.compact.uniq
end
branch() click to toggle source

Attempt to detect the branch automatically, but don’t raise an error if the branch can’t be found unless the user has explicitly enabled auto_detect_version_properties. This approach is an attempt to include the branch without the user having to explicitly set it, because people tend to not update things.

# File lib/pact_broker/client/tasks/publication_task.rb, line 84
def branch
  if @branch.nil? && auto_detect_version_properties != false
    @branch = PactBroker::Client::Git.branch(raise_error: auto_detect_version_properties == true)
  else
    @branch
  end
end
consumer_version() click to toggle source
# File lib/pact_broker/client/tasks/publication_task.rb, line 92
def consumer_version
  if @consumer_version.nil? && @auto_detect_version_properties
    @consumer_version = PactBroker::Client::Git.commit(raise_error: true)
  else
    @consumer_version
  end
end
rake_task(&block) click to toggle source
# File lib/pact_broker/client/tasks/publication_task.rb, line 46
def rake_task &block
  namespace :pact do
    desc "Publish pacts to pact broker"
    task task_name do
      block.call(self)
      validate!
      require 'pact_broker/client/publish_pacts'
      pact_broker_client_options = { write: write_method, token: pact_broker_token }
      pact_broker_client_options[:basic_auth] = pact_broker_basic_auth if pact_broker_basic_auth && pact_broker_basic_auth.any?
      pact_broker_client_options.compact!
      consumer_version_params = { number: consumer_version, branch: branch, build_url: build_url, tags: all_tags }.compact
      result = PactBroker::Client::PublishPacts.new(pact_broker_base_url, FileList[pattern], consumer_version_params, {}, pact_broker_client_options).call
      $stdout.puts result.message
      raise PactBroker::Client::Error.new("One or more pacts failed to be published") unless result.success
    end
  end
end
task_name() click to toggle source
# File lib/pact_broker/client/tasks/publication_task.rb, line 70
def task_name
  @name ? "publish:#{@name}" : "publish"
end
validate!() click to toggle source
# File lib/pact_broker/client/tasks/publication_task.rb, line 64
def validate!
  if consumer_version.blank?
    raise PactBroker::Client::Error.new("A consumer version must be provided")
  end
end