Class: PactBroker::Client::CLI::Broker

Inherits:
CustomThor
  • Object
show all
Defined in:
lib/pact_broker/client/cli/broker.rb

Instance Method Summary collapse

Instance Method Details

#can_i_deploy(*ignored_but_necessary) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/pact_broker/client/cli/broker.rb', line 36

def can_i_deploy(*ignored_but_necessary)
  selectors = VersionSelectorOptionsParser.call(ARGV)
  validate_can_i_deploy_selectors(selectors)
  can_i_deploy_options = { output: options.output, retry_while_unknown: options.retry_while_unknown, retry_interval: options.retry_interval }
  result = CanIDeploy.call(options.broker_base_url, selectors, {to_tag: options.to}, can_i_deploy_options, pact_broker_client_options)
  $stdout.puts result.message
  exit(1) unless result.success
end

#create_version_tagObject



74
75
76
77
78
79
80
81
# File 'lib/pact_broker/client/cli/broker.rb', line 74

def create_version_tag
  PactBroker::Client::CreateTag.call(
    options.broker_base_url,
    options.pacticipant,
    options.version,
    tags,
    pact_broker_client_options)
end

#create_webhook(webhook_url) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/pact_broker/client/cli/broker.rb', line 126

def create_webhook webhook_url
  require 'pact_broker/client/webhooks/create'

  if !(options.contract_content_changed || options.provider_verification_published)
    raise PactBroker::Client::Error.new("You must select at least one of --contract-content-changed or --provider-verification-published")
  end

  username = options.user ? options.user.split(":", 2).first : nil
  password = options.user ? options.user.split(":", 2).last : nil

  headers = (options.header || []).each_with_object({}) { | header, headers | headers[header.split(":", 2).first.strip] = header.split(":", 2).last.strip }

  body = options.data
  if body && body.start_with?("@")
    filepath = body[1..-1]
    begin
      body = File.read(filepath)
    rescue StandardError => e
      raise PactBroker::Client::Error.new("Couldn't read data from file \"#{filepath}\" due to #{e.class} #{e.message}")
    end
  end

  events = []
  events << 'contract_content_changed' if options.contract_content_changed
  events << 'provider_verification_published' if options.provider_verification_published

  params = {
    http_method: options.request,
    url: webhook_url,
    headers: headers,
    username: username,
    password: password,
    body: body,
    consumer: options.consumer,
    provider: options.provider,
    events: events
  }

  begin
    result = PactBroker::Client::Webhooks::Create.call(params, options.broker_base_url, pact_broker_client_options)
    $stdout.puts result.message
    exit(1) unless result.success
  rescue PactBroker::Client::Error => e
    raise WebhookCreationError, "#{e.class} - #{e.message}"
  end
end

#describe_versionObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/pact_broker/client/cli/broker.rb', line 94

def describe_version
  latest = !options.latest.nil? || (options.latest.nil? && options.version.nil?)
  params = {
    pacticipant: options.pacticipant,
    version: options.version,
    latest: latest,
    tag: options.latest != "latest" ? options.latest : nil
  }
  opts = {
    output: options.output
  }
  result = PactBroker::Client::Versions::Describe.call(params, opts, options.broker_base_url, pact_broker_client_options)
  $stdout.puts result.message
  exit(1) unless result.success
end

#publish(*pact_files) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/pact_broker/client/cli/broker.rb', line 55

def publish(*pact_files)
  validate_pact_files(pact_files)
  success = publish_pacts(pact_files)
  raise PactPublicationError, "One or more pacts failed to be published" unless success
rescue PactBroker::Client::Error => e
  raise PactPublicationError, "#{e.class} - #{e.message}"
end

#versionObject



174
175
176
# File 'lib/pact_broker/client/cli/broker.rb', line 174

def version
  $stdout.puts PactBroker::Client::VERSION
end