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



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

def can_i_deploy(*ignored_but_necessary)
  require 'pact_broker/client/cli/version_selector_options_parser'
  require 'pact_broker/client/can_i_deploy'

  validate_credentials
  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, to_environment: options.to_environment, limit: options.limit }, can_i_deploy_options, pact_broker_client_options)
  $stdout.puts result.message
  $stdout.flush
  exit(can_i_deploy_exit_status) unless result.success
end

#create_or_update_pacticipant(*required_but_ignored) ⇒ Object

Raises:

  • (::Thor::RequiredArgumentMissingError)


156
157
158
159
160
161
162
# File 'lib/pact_broker/client/cli/broker.rb', line 156

def create_or_update_pacticipant(*required_but_ignored)
  raise ::Thor::RequiredArgumentMissingError, "Pacticipant name cannot be blank" if options.name.strip.size == 0
  require 'pact_broker/client/pacticipants/create'
  result = PactBroker::Client::Pacticipants2::Create.call({ name: options.name, repository_url: options.repository_url }, options.broker_base_url, pact_broker_client_options)
  $stdout.puts result.message
  exit(1) unless result.success
end

#create_or_update_webhook(webhook_url) ⇒ Object



130
131
132
# File 'lib/pact_broker/client/cli/broker.rb', line 130

def create_or_update_webhook webhook_url
  run_webhook_commands webhook_url
end

#create_version_tagObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pact_broker/client/cli/broker.rb', line 76

def create_version_tag
  require 'pact_broker/client/create_tag'

  validate_credentials
  PactBroker::Client::CreateTag.call(
    options.broker_base_url,
    options.pacticipant,
    options.version,
    tags,
    options.auto_create_version,
    pact_broker_client_options)
rescue PactBroker::Client::Error => e
  raise VersionCreationError.new(e.message)
end

#create_webhook(webhook_url) ⇒ Object



121
122
123
# File 'lib/pact_broker/client/cli/broker.rb', line 121

def create_webhook webhook_url
  run_webhook_commands webhook_url
end

#describe_versionObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/pact_broker/client/cli/broker.rb', line 98

def describe_version
  require 'pact_broker/client/versions/describe'

  validate_credentials
  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

#generate_uuidObject



145
146
147
148
149
# File 'lib/pact_broker/client/cli/broker.rb', line 145

def generate_uuid
  require 'securerandom'

  puts SecureRandom.uuid
end

#list_latest_pact_versions(*required_but_ignored) ⇒ Object



167
168
169
170
171
172
# File 'lib/pact_broker/client/cli/broker.rb', line 167

def list_latest_pact_versions(*required_but_ignored)
  require 'pact_broker/client/pacts/list_latest_versions'
  result = PactBroker::Client::Pacts::ListLatestVersions.call(options.broker_base_url, options.output, pact_broker_client_options)
  $stdout.puts result.message
  exit(1) unless result.success
end

#publish(*pact_files) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/pact_broker/client/cli/broker.rb', line 57

def publish(*pact_files)
  require 'pact_broker/client/error'
  validate_credentials
  validate_pact_files(pact_files)
  result = publish_pacts(pact_files)
  $stdout.puts result.message
  exit(1) unless result.success
rescue PactBroker::Client::Error => e
  raise PactPublicationError, "#{e.class} - #{e.message}"
end

#record_deploymentObject



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/pact_broker/client/cli/broker.rb', line 186

def record_deployment
  require 'pact_broker/client/versions/record_deployment'
  params = {
    pacticipant_name: options.pacticipant,
    version_number: options.version,
    environment_name: options.environment,
    target: options.target,
    output: options.output
  }
  result = PactBroker::Client::Versions::RecordDeployment.call(
    params,
    options.broker_base_url,
    pact_broker_client_options
  )
  $stdout.puts result.message
  exit(1) unless result.success
end

#record_undeploymentObject



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/pact_broker/client/cli/broker.rb', line 212

def record_undeployment
  require 'pact_broker/client/versions/record_undeployment'
  params = {
    pacticipant_name: options.pacticipant,
    version_number: options.version,
    environment_name: options.environment,
    output: options.output
  }
  result = PactBroker::Client::Versions::RecordUndeployment.call(
    params,
    options.broker_base_url,
    pact_broker_client_options
  )
  $stdout.puts result.message
  exit(1) unless result.success
end

#test_webhookObject



137
138
139
140
141
# File 'lib/pact_broker/client/cli/broker.rb', line 137

def test_webhook
  require 'pact_broker/client/webhooks/test'
  result = PactBroker::Client::Webhooks::Test.call(options, pact_broker_client_options)
  $stdout.puts result.message
end

#versionObject



233
234
235
236
237
# File 'lib/pact_broker/client/cli/broker.rb', line 233

def version
  require 'pact_broker/client/version'

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