pact_broker-client 1.58.0 → 1.61.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release_gem.yml +1 -1
- data/CHANGELOG.md +25 -0
- data/README.md +262 -220
- data/lib/pact_broker/client/base_client.rb +1 -1
- data/lib/pact_broker/client/cli/broker.rb +15 -199
- data/lib/pact_broker/client/cli/custom_thor.rb +23 -0
- data/lib/pact_broker/client/cli/pact_commands.rb +128 -0
- data/lib/pact_broker/client/cli/version_commands.rb +102 -0
- data/lib/pact_broker/client/deployments/record_deployment.rb +3 -0
- data/lib/pact_broker/client/deployments/record_undeployment.rb +3 -0
- data/lib/pact_broker/client/environments/environment_command.rb +3 -0
- data/lib/pact_broker/client/git.rb +1 -1
- data/lib/pact_broker/client/hal/entity.rb +6 -2
- data/lib/pact_broker/client/hal/links.rb +3 -0
- data/lib/pact_broker/client/hash_refinements.rb +9 -0
- data/lib/pact_broker/client/merge_pacts.rb +21 -10
- data/lib/pact_broker/client/pacticipants/create.rb +1 -1
- data/lib/pact_broker/client/publish_pacts.rb +1 -0
- data/lib/pact_broker/client/version.rb +1 -1
- data/lib/pact_broker/client/versions/create.rb +111 -0
- data/lib/pact_broker/client/versions.rb +1 -0
- data/lib/pact_broker/client/webhooks/create.rb +4 -1
- data/pact-broker-client.gemspec +4 -4
- data/script/record-undeployment.sh +1 -1
- data/script/update-cli-usage-in-readme.rb +7 -3
- data/spec/lib/pact_broker/client/hal/entity_spec.rb +1 -1
- data/spec/lib/pact_broker/client/merge_pacts_spec.rb +146 -43
- data/spec/lib/pact_broker/client/versions/create_spec.rb +174 -0
- metadata +16 -17
@@ -125,7 +125,7 @@ module PactBroker
|
|
125
125
|
end
|
126
126
|
url
|
127
127
|
else
|
128
|
-
raise PactBroker::Client::RelationNotFound.new("Could not find relation #{relation_name} in index resource. Try upgrading your Pact Broker as the feature you require may not exist in your version.")
|
128
|
+
raise PactBroker::Client::RelationNotFound.new("Could not find relation #{relation_name} in index resource. Try upgrading your Pact Broker as the feature you require may not exist in your version. If you are using Pactflow, you may not have the permissions required for this action.")
|
129
129
|
end
|
130
130
|
end
|
131
131
|
end
|
@@ -1,228 +1,44 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
1
|
+
require "pact_broker/client/cli/custom_thor"
|
2
|
+
require "pact_broker/client/hash_refinements"
|
3
|
+
require "thor/error"
|
4
|
+
require "pact_broker/client/cli/pact_commands"
|
5
|
+
require "pact_broker/client/cli/environment_commands"
|
6
|
+
require "pact_broker/client/cli/deployment_commands"
|
7
|
+
require "pact_broker/client/cli/pacticipant_commands"
|
8
|
+
require "pact_broker/client/cli/version_commands"
|
9
|
+
require "pact_broker/client/cli/webhook_commands"
|
8
10
|
require "pact_broker/client/cli/matrix_commands"
|
9
11
|
|
10
12
|
module PactBroker
|
11
13
|
module Client
|
12
14
|
module CLI
|
13
|
-
# Thor::Error will have its backtrace hidden
|
14
|
-
class PactPublicationError < ::Thor::Error; end
|
15
|
-
class AuthError < ::Thor::Error; end
|
16
|
-
class VersionCreationError < ::Thor::Error; end
|
17
|
-
|
18
15
|
class Broker < CustomThor
|
19
|
-
|
20
|
-
|
16
|
+
include PactBroker::Client::CLI::PactCommands
|
21
17
|
include PactBroker::Client::CLI::EnvironmentCommands
|
22
18
|
include PactBroker::Client::CLI::DeploymentCommands
|
23
19
|
include PactBroker::Client::CLI::MatrixCommands
|
24
20
|
include PactBroker::Client::CLI::PacticipantCommands
|
21
|
+
include PactBroker::Client::CLI::VersionCommands
|
25
22
|
include PactBroker::Client::CLI::WebhookCommands
|
26
23
|
|
27
|
-
desc 'publish PACT_DIRS_OR_FILES ...', "Publish pacts to a Pact Broker."
|
28
|
-
method_option :consumer_app_version, required: true, aliases: "-a", desc: "The consumer application version"
|
29
|
-
method_option :branch, aliases: "-h", desc: "Repository branch of the consumer version"
|
30
|
-
method_option :auto_detect_version_properties, hidden: true, type: :boolean, default: false, desc: "Automatically detect the repository branch from known CI environment variables or git CLI."
|
31
|
-
method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for consumer version. Can be specified multiple times."
|
32
|
-
method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag consumer version with the name of the current git branch. Default: false"
|
33
|
-
method_option :build_url, desc: "The build URL that created the pact"
|
34
|
-
method_option :merge, type: :boolean, default: false, require: false, desc: "If a pact already exists for this consumer version and provider, merge the contents. Useful when running Pact tests concurrently on different build nodes."
|
35
|
-
output_option_json_or_text
|
36
|
-
shared_authentication_options
|
37
|
-
|
38
|
-
def publish(*pact_files)
|
39
|
-
require 'pact_broker/client/error'
|
40
|
-
validate_credentials
|
41
|
-
validate_pact_files(pact_files)
|
42
|
-
result = publish_pacts(pact_files)
|
43
|
-
$stdout.puts result.message
|
44
|
-
exit(1) unless result.success
|
45
|
-
rescue PactBroker::Client::Error => e
|
46
|
-
raise PactPublicationError, "#{e.class} - #{e.message}"
|
47
|
-
end
|
48
|
-
|
49
|
-
desc 'create-version-tag', 'Add a tag to a pacticipant version'
|
50
|
-
method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name"
|
51
|
-
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version"
|
52
|
-
method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for pacticipant version. Can be specified multiple times."
|
53
|
-
method_option :auto_create_version, type: :boolean, default: false, desc: "Automatically create the pacticipant version if it does not exist. Default: false"
|
54
|
-
method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag pacticipant version with the name of the current git branch. Default: false"
|
55
|
-
shared_authentication_options
|
56
|
-
|
57
|
-
def create_version_tag
|
58
|
-
require 'pact_broker/client/create_tag'
|
59
|
-
|
60
|
-
validate_credentials
|
61
|
-
PactBroker::Client::CreateTag.call(
|
62
|
-
options.broker_base_url,
|
63
|
-
options.pacticipant,
|
64
|
-
options.version,
|
65
|
-
tags,
|
66
|
-
options.auto_create_version,
|
67
|
-
pact_broker_client_options)
|
68
|
-
rescue PactBroker::Client::Error => e
|
69
|
-
raise VersionCreationError.new(e.message)
|
70
|
-
end
|
71
|
-
|
72
|
-
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that the version belongs to."
|
73
|
-
method_option :version, required: false, aliases: "-e", desc: "The pacticipant version number."
|
74
|
-
method_option :latest, required: false, aliases: "-l", banner: '[TAG]', desc: "Describe the latest pacticipant version. Optionally specify a TAG to describe the latest version with the specified tag."
|
75
|
-
method_option :output, aliases: "-o", desc: "json or table or id", default: 'table'
|
76
|
-
shared_authentication_options
|
77
|
-
|
78
|
-
desc 'describe-version', 'Describes a pacticipant version. If no version or tag is specified, the latest version is described.'
|
79
|
-
def describe_version
|
80
|
-
require 'pact_broker/client/versions/describe'
|
81
|
-
|
82
|
-
validate_credentials
|
83
|
-
latest = !options.latest.nil? || (options.latest.nil? && options.version.nil?)
|
84
|
-
params = {
|
85
|
-
pacticipant: options.pacticipant,
|
86
|
-
version: options.version,
|
87
|
-
latest: latest,
|
88
|
-
tag: options.latest != "latest" ? options.latest : nil
|
89
|
-
}
|
90
|
-
opts = {
|
91
|
-
output: options.output
|
92
|
-
}
|
93
|
-
result = PactBroker::Client::Versions::Describe.call(params, opts, options.broker_base_url, pact_broker_client_options)
|
94
|
-
$stdout.puts result.message
|
95
|
-
exit(1) unless result.success
|
96
|
-
end
|
97
|
-
|
98
|
-
|
99
|
-
|
100
24
|
ignored_and_hidden_potential_options_from_environment_variables
|
101
|
-
desc
|
25
|
+
desc "generate-uuid", "Generate a UUID for use when calling create-or-update-webhook"
|
102
26
|
def generate_uuid
|
103
|
-
require
|
104
|
-
|
27
|
+
require "securerandom"
|
105
28
|
puts SecureRandom.uuid
|
106
29
|
end
|
107
30
|
|
108
|
-
desc 'list-latest-pact-versions', 'List the latest pact for each integration'
|
109
|
-
shared_authentication_options
|
110
|
-
output_option_json_or_table
|
111
|
-
def list_latest_pact_versions(*required_but_ignored)
|
112
|
-
require 'pact_broker/client/pacts/list_latest_versions'
|
113
|
-
result = PactBroker::Client::Pacts::ListLatestVersions.call(options.broker_base_url, options.output, pact_broker_client_options)
|
114
|
-
$stdout.puts result.message
|
115
|
-
exit(1) unless result.success
|
116
|
-
end
|
117
|
-
|
118
31
|
ignored_and_hidden_potential_options_from_environment_variables
|
119
|
-
desc
|
32
|
+
desc "version", "Show the pact_broker-client gem version"
|
120
33
|
def version
|
121
|
-
require
|
122
|
-
|
34
|
+
require "pact_broker/client/version"
|
123
35
|
$stdout.puts PactBroker::Client::VERSION
|
124
36
|
end
|
125
37
|
|
126
38
|
no_commands do
|
127
|
-
|
128
39
|
def self.exit_on_failure?
|
129
40
|
true
|
130
41
|
end
|
131
|
-
|
132
|
-
def validate_credentials
|
133
|
-
if options.broker_username && options.broker_token
|
134
|
-
raise AuthError, "You cannot provide both a username/password and a bearer token. If your Pact Broker uses a bearer token, please remove the username and password configuration."
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
def validate_pact_files pact_files
|
139
|
-
unless pact_files && pact_files.any?
|
140
|
-
raise ::Thor::RequiredArgumentMissingError, "No value provided for required pact_files"
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
|
145
|
-
def publish_pacts pact_files
|
146
|
-
require 'pact_broker/client/publish_pacts'
|
147
|
-
|
148
|
-
write_options = options[:merge] ? { write: :merge } : {}
|
149
|
-
consumer_version_params = {
|
150
|
-
number: options.consumer_app_version,
|
151
|
-
branch: branch,
|
152
|
-
tags: tags,
|
153
|
-
build_url: options.build_url,
|
154
|
-
version_required: (!!options.branch || !!options.build_url || explict_auto_detect_version_properties)
|
155
|
-
}.compact
|
156
|
-
|
157
|
-
PactBroker::Client::PublishPacts.call(
|
158
|
-
options.broker_base_url,
|
159
|
-
file_list(pact_files),
|
160
|
-
consumer_version_params,
|
161
|
-
{ merge: options[:merge], output: options.output }.compact,
|
162
|
-
pact_broker_client_options.merge(write_options)
|
163
|
-
)
|
164
|
-
end
|
165
|
-
|
166
|
-
def file_list pact_files
|
167
|
-
require 'rake/file_list'
|
168
|
-
|
169
|
-
correctly_separated_pact_files = pact_files.collect{ |path| path.gsub(/\\+/, '/') }
|
170
|
-
paths = Rake::FileList[correctly_separated_pact_files].collect do | path |
|
171
|
-
if File.directory?(path)
|
172
|
-
Rake::FileList[File.join(path, "*.json")]
|
173
|
-
else
|
174
|
-
path
|
175
|
-
end
|
176
|
-
end.flatten
|
177
|
-
validate_pact_path_list(paths)
|
178
|
-
end
|
179
|
-
|
180
|
-
def validate_pact_path_list(paths)
|
181
|
-
paths.collect do | path |
|
182
|
-
if File.exist?(path)
|
183
|
-
path
|
184
|
-
elsif path.start_with?("-")
|
185
|
-
raise Thor::Error.new("ERROR: pact-broker publish was called with invalid arguments #{[path]}")
|
186
|
-
else
|
187
|
-
raise Thor::Error.new("Specified pact file '#{path}' does not exist. This sometimes indicates one of the arguments has been specified with the wrong name and has been incorrectly identified as a file path.")
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
def tags
|
193
|
-
require 'pact_broker/client/git'
|
194
|
-
|
195
|
-
t = [*options.tag]
|
196
|
-
t << PactBroker::Client::Git.branch(raise_error: true) if options.tag_with_git_branch
|
197
|
-
t.compact.uniq
|
198
|
-
end
|
199
|
-
|
200
|
-
def branch
|
201
|
-
require 'pact_broker/client/git'
|
202
|
-
|
203
|
-
if options.branch.nil? && options.auto_detect_version_properties
|
204
|
-
PactBroker::Client::Git.branch(raise_error: explict_auto_detect_version_properties)
|
205
|
-
else
|
206
|
-
options.branch
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
def explict_auto_detect_version_properties
|
211
|
-
@explict_auto_detect_version_properties ||= ARGV.include?("--auto-detect-version-properties")
|
212
|
-
end
|
213
|
-
|
214
|
-
def pact_broker_client_options
|
215
|
-
client_options = { verbose: options.verbose, pact_broker_base_url: options.broker_base_url }
|
216
|
-
client_options[:token] = options.broker_token || ENV['PACT_BROKER_TOKEN']
|
217
|
-
if options.broker_username || ENV['PACT_BROKER_USERNAME']
|
218
|
-
client_options[:basic_auth] = {
|
219
|
-
username: options.broker_username || ENV['PACT_BROKER_USERNAME'],
|
220
|
-
password: options.broker_password || ENV['PACT_BROKER_PASSWORD']
|
221
|
-
}.compact
|
222
|
-
end
|
223
|
-
|
224
|
-
client_options.compact
|
225
|
-
end
|
226
42
|
end
|
227
43
|
end
|
228
44
|
end
|
@@ -1,14 +1,18 @@
|
|
1
1
|
require 'thor'
|
2
|
+
require 'pact_broker/client/hash_refinements'
|
2
3
|
|
3
4
|
module PactBroker
|
4
5
|
module Client
|
5
6
|
module CLI
|
7
|
+
class AuthError < ::Thor::Error; end
|
8
|
+
|
6
9
|
##
|
7
10
|
# Custom Thor task allows the following:
|
8
11
|
#
|
9
12
|
# `--option 1 --option 2` to be interpreted as `--option 1 2` (the standard Thor format for multiple value options)
|
10
13
|
#
|
11
14
|
class CustomThor < ::Thor
|
15
|
+
using PactBroker::Client::HashRefinements
|
12
16
|
|
13
17
|
no_commands do
|
14
18
|
def self.start given_args = ARGV, config = {}
|
@@ -106,6 +110,25 @@ module PactBroker
|
|
106
110
|
def params_from_options(keys)
|
107
111
|
keys.each_with_object({}) { | key, p | p[key] = options[key] }
|
108
112
|
end
|
113
|
+
|
114
|
+
def pact_broker_client_options
|
115
|
+
client_options = { verbose: options.verbose, pact_broker_base_url: options.broker_base_url }
|
116
|
+
client_options[:token] = options.broker_token || ENV['PACT_BROKER_TOKEN']
|
117
|
+
if options.broker_username || ENV['PACT_BROKER_USERNAME']
|
118
|
+
client_options[:basic_auth] = {
|
119
|
+
username: options.broker_username || ENV['PACT_BROKER_USERNAME'],
|
120
|
+
password: options.broker_password || ENV['PACT_BROKER_PASSWORD']
|
121
|
+
}.compact
|
122
|
+
end
|
123
|
+
|
124
|
+
client_options.compact
|
125
|
+
end
|
126
|
+
|
127
|
+
def validate_credentials
|
128
|
+
if options.broker_username && options.broker_token
|
129
|
+
raise AuthError, "You cannot provide both a username/password and a bearer token. If your Pact Broker uses a bearer token, please remove the username and password configuration."
|
130
|
+
end
|
131
|
+
end
|
109
132
|
end
|
110
133
|
end
|
111
134
|
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require "pact_broker/client/hash_refinements"
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Client
|
5
|
+
module CLI
|
6
|
+
# Thor::Error will have its backtrace hidden
|
7
|
+
class PactPublicationError < ::Thor::Error; end
|
8
|
+
|
9
|
+
module PactCommands
|
10
|
+
using PactBroker::Client::HashRefinements
|
11
|
+
|
12
|
+
def self.included(thor)
|
13
|
+
thor.class_eval do
|
14
|
+
desc 'publish PACT_DIRS_OR_FILES ...', "Publish pacts to a Pact Broker."
|
15
|
+
method_option :consumer_app_version, required: true, aliases: "-a", desc: "The consumer application version"
|
16
|
+
method_option :branch, aliases: "-h", desc: "Repository branch of the consumer version"
|
17
|
+
method_option :auto_detect_version_properties, hidden: true, type: :boolean, default: false, desc: "Automatically detect the repository branch from known CI environment variables or git CLI."
|
18
|
+
method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for consumer version. Can be specified multiple times."
|
19
|
+
method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag consumer version with the name of the current git branch. Default: false"
|
20
|
+
method_option :build_url, desc: "The build URL that created the pact"
|
21
|
+
method_option :merge, type: :boolean, default: false, require: false, desc: "If a pact already exists for this consumer version and provider, merge the contents. Useful when running Pact tests concurrently on different build nodes."
|
22
|
+
output_option_json_or_text
|
23
|
+
shared_authentication_options
|
24
|
+
|
25
|
+
def publish(*pact_files)
|
26
|
+
require 'pact_broker/client/error'
|
27
|
+
validate_credentials
|
28
|
+
validate_pact_files(pact_files)
|
29
|
+
result = publish_pacts(pact_files)
|
30
|
+
$stdout.puts result.message
|
31
|
+
exit(1) unless result.success
|
32
|
+
rescue PactBroker::Client::Error => e
|
33
|
+
raise PactPublicationError, "#{e.class} - #{e.message}"
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'list-latest-pact-versions', 'List the latest pact for each integration'
|
37
|
+
shared_authentication_options
|
38
|
+
output_option_json_or_table
|
39
|
+
def list_latest_pact_versions(*required_but_ignored)
|
40
|
+
require 'pact_broker/client/pacts/list_latest_versions'
|
41
|
+
result = PactBroker::Client::Pacts::ListLatestVersions.call(options.broker_base_url, options.output, pact_broker_client_options)
|
42
|
+
$stdout.puts result.message
|
43
|
+
exit(1) unless result.success
|
44
|
+
end
|
45
|
+
|
46
|
+
no_commands do
|
47
|
+
def validate_pact_files pact_files
|
48
|
+
unless pact_files && pact_files.any?
|
49
|
+
raise ::Thor::RequiredArgumentMissingError, "No value provided for required pact_files"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def publish_pacts pact_files
|
55
|
+
require 'pact_broker/client/publish_pacts'
|
56
|
+
|
57
|
+
write_options = options[:merge] ? { write: :merge } : {}
|
58
|
+
consumer_version_params = {
|
59
|
+
number: options.consumer_app_version,
|
60
|
+
branch: branch,
|
61
|
+
tags: tags,
|
62
|
+
build_url: options.build_url,
|
63
|
+
version_required: (!!options.branch || !!options.build_url || explict_auto_detect_version_properties)
|
64
|
+
}.compact
|
65
|
+
|
66
|
+
PactBroker::Client::PublishPacts.call(
|
67
|
+
options.broker_base_url,
|
68
|
+
file_list(pact_files),
|
69
|
+
consumer_version_params,
|
70
|
+
{ merge: options[:merge], output: options.output }.compact,
|
71
|
+
pact_broker_client_options.merge(write_options)
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
def file_list pact_files
|
76
|
+
require 'rake/file_list'
|
77
|
+
|
78
|
+
correctly_separated_pact_files = pact_files.collect{ |path| path.gsub(/\\+/, '/') }
|
79
|
+
paths = Rake::FileList[correctly_separated_pact_files].collect do | path |
|
80
|
+
if File.directory?(path)
|
81
|
+
Rake::FileList[File.join(path, "*.json")]
|
82
|
+
else
|
83
|
+
path
|
84
|
+
end
|
85
|
+
end.flatten
|
86
|
+
validate_pact_path_list(paths)
|
87
|
+
end
|
88
|
+
|
89
|
+
def validate_pact_path_list(paths)
|
90
|
+
paths.collect do | path |
|
91
|
+
if File.exist?(path)
|
92
|
+
path
|
93
|
+
elsif path.start_with?("-")
|
94
|
+
raise Thor::Error.new("ERROR: pact-broker publish was called with invalid arguments #{[path]}")
|
95
|
+
else
|
96
|
+
raise Thor::Error.new("Specified pact file '#{path}' does not exist. This sometimes indicates one of the arguments has been specified with the wrong name and has been incorrectly identified as a file path.")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def tags
|
102
|
+
require 'pact_broker/client/git'
|
103
|
+
|
104
|
+
t = [*options.tag]
|
105
|
+
t << PactBroker::Client::Git.branch(raise_error: true) if options.tag_with_git_branch
|
106
|
+
t.compact.uniq
|
107
|
+
end
|
108
|
+
|
109
|
+
def branch
|
110
|
+
require 'pact_broker/client/git'
|
111
|
+
|
112
|
+
if options.branch.nil? && options.auto_detect_version_properties
|
113
|
+
PactBroker::Client::Git.branch(raise_error: explict_auto_detect_version_properties)
|
114
|
+
else
|
115
|
+
options.branch
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def explict_auto_detect_version_properties
|
120
|
+
@explict_auto_detect_version_properties ||= ARGV.include?("--auto-detect-version-properties")
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module PactBroker
|
2
|
+
module Client
|
3
|
+
module CLI
|
4
|
+
class VersionCreationError < ::Thor::Error; end
|
5
|
+
|
6
|
+
module VersionCommands
|
7
|
+
def self.included(thor)
|
8
|
+
thor.class_eval do
|
9
|
+
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that the version belongs to."
|
10
|
+
method_option :version, required: false, aliases: "-e", desc: "The pacticipant version number."
|
11
|
+
method_option :latest, required: false, aliases: "-l", banner: '[TAG]', desc: "Describe the latest pacticipant version. Optionally specify a TAG to describe the latest version with the specified tag."
|
12
|
+
method_option :output, aliases: "-o", desc: "json or table or id", default: 'table'
|
13
|
+
shared_authentication_options
|
14
|
+
|
15
|
+
desc 'describe-version', 'Describes a pacticipant version. If no version or tag is specified, the latest version is described.'
|
16
|
+
def describe_version
|
17
|
+
require 'pact_broker/client/versions/describe'
|
18
|
+
|
19
|
+
validate_credentials
|
20
|
+
latest = !options.latest.nil? || (options.latest.nil? && options.version.nil?)
|
21
|
+
params = {
|
22
|
+
pacticipant: options.pacticipant,
|
23
|
+
version: options.version,
|
24
|
+
latest: latest,
|
25
|
+
tag: options.latest != "latest" ? options.latest : nil
|
26
|
+
}
|
27
|
+
opts = {
|
28
|
+
output: options.output
|
29
|
+
}
|
30
|
+
result = PactBroker::Client::Versions::Describe.call(params, opts, options.broker_base_url, pact_broker_client_options)
|
31
|
+
$stdout.puts result.message
|
32
|
+
exit(1) unless result.success
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
desc "create-or-update-version", "Create or update pacticipant version by version number"
|
37
|
+
method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name"
|
38
|
+
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number"
|
39
|
+
method_option :branch, required: false, desc: "The repository branch name"
|
40
|
+
method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for pacticipant version. Can be specified multiple times."
|
41
|
+
shared_authentication_options
|
42
|
+
output_option_json_or_text
|
43
|
+
verbose_option
|
44
|
+
|
45
|
+
def create_or_update_version(*required_but_ignored)
|
46
|
+
validate_create_version_params
|
47
|
+
|
48
|
+
params = {
|
49
|
+
pacticipant_name: options.pacticipant.strip,
|
50
|
+
version_number: options.version.strip,
|
51
|
+
branch_name: options.branch&.strip,
|
52
|
+
tags: options.tag&.collect(&:strip)
|
53
|
+
}
|
54
|
+
|
55
|
+
execute_version_command(params, "Create")
|
56
|
+
end
|
57
|
+
|
58
|
+
desc 'create-version-tag', 'Add a tag to a pacticipant version'
|
59
|
+
method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name"
|
60
|
+
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version"
|
61
|
+
method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for pacticipant version. Can be specified multiple times."
|
62
|
+
method_option :auto_create_version, type: :boolean, default: false, desc: "Automatically create the pacticipant version if it does not exist. Default: false"
|
63
|
+
method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag pacticipant version with the name of the current git branch. Default: false"
|
64
|
+
shared_authentication_options
|
65
|
+
|
66
|
+
def create_version_tag
|
67
|
+
require 'pact_broker/client/create_tag'
|
68
|
+
|
69
|
+
validate_credentials
|
70
|
+
PactBroker::Client::CreateTag.call(
|
71
|
+
options.broker_base_url,
|
72
|
+
options.pacticipant,
|
73
|
+
options.version,
|
74
|
+
tags,
|
75
|
+
options.auto_create_version,
|
76
|
+
pact_broker_client_options)
|
77
|
+
rescue PactBroker::Client::Error => e
|
78
|
+
raise VersionCreationError.new(e.message)
|
79
|
+
end
|
80
|
+
|
81
|
+
no_commands do
|
82
|
+
def execute_version_command(params, command_class_name)
|
83
|
+
require "pact_broker/client/versions"
|
84
|
+
command_options = { verbose: options.verbose, output: options.output }
|
85
|
+
result = PactBroker::Client::Versions.const_get(command_class_name).call(params, command_options, pact_broker_client_options)
|
86
|
+
$stdout.puts result.message
|
87
|
+
exit(1) unless result.success
|
88
|
+
end
|
89
|
+
|
90
|
+
def validate_create_version_params
|
91
|
+
raise ::Thor::RequiredArgumentMissingError, "Pacticipant name cannot be blank" if options.pacticipant.strip.size == 0
|
92
|
+
raise ::Thor::RequiredArgumentMissingError, "Pacticipant version cannot be blank" if options.version.strip.size == 0
|
93
|
+
raise ::Thor::RequiredArgumentMissingError, "Version branch cannot be blank" if options.branch && options.branch.strip.size == 0
|
94
|
+
raise ::Thor::RequiredArgumentMissingError, "Version tag cannot be blank" if options.tag && options.tag.any?{ | tag | tag.strip.size == 0 }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'pact_broker/client/deployments/record_release'
|
2
|
+
require "pact_broker/client/hash_refinements"
|
2
3
|
|
3
4
|
module PactBroker
|
4
5
|
module Client
|
5
6
|
module Deployments
|
6
7
|
class RecordDeployment < PactBroker::Client::Deployments::RecordRelease
|
8
|
+
using PactBroker::Client::HashRefinements
|
9
|
+
|
7
10
|
def initialize(params, options, pact_broker_client_options)
|
8
11
|
super
|
9
12
|
@application_instance = params.fetch(:application_instance)
|
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'pact_broker/client/base_command'
|
2
|
+
require 'pact_broker/client/hash_refinements'
|
2
3
|
|
3
4
|
module PactBroker
|
4
5
|
module Client
|
5
6
|
module Deployments
|
6
7
|
class RecordUndeployment < PactBroker::Client::BaseCommand
|
8
|
+
using PactBroker::Client::HashRefinements
|
9
|
+
|
7
10
|
def initialize(params, options, pact_broker_client_options)
|
8
11
|
super
|
9
12
|
@pacticipant_name = params.fetch(:pacticipant_name)
|
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'pact_broker/client/base_command'
|
2
|
+
require 'pact_broker/client/hash_refinements'
|
2
3
|
|
3
4
|
module PactBroker
|
4
5
|
module Client
|
5
6
|
module Environments
|
6
7
|
class EnvironmentCommand < PactBroker::Client::BaseCommand
|
8
|
+
using PactBroker::Client::HashRefinements
|
9
|
+
|
7
10
|
NOT_SUPPORTED_MESSAGE = "This version of the Pact Broker does not support environments. Please upgrade to version 2.80.0 or later."
|
8
11
|
PACTFLOW_NOT_SUPPORTED_MESSAGE = "This version of Pactflow does not support environments or you do not have the required permission to read them. Please upgrade to the latest version if using Pactflow On-Premises and ensure the user has the environment read permission."
|
9
12
|
|
@@ -25,7 +25,7 @@ module PactBroker
|
|
25
25
|
using PactBroker::Client::HashRefinements
|
26
26
|
|
27
27
|
COMMAND = 'git rev-parse --abbrev-ref HEAD'.freeze
|
28
|
-
BRANCH_ENV_VAR_NAMES = %w{GITHUB_REF BUILDKITE_BRANCH CIRCLE_BRANCH TRAVIS_BRANCH GIT_BRANCH GIT_LOCAL_BRANCH APPVEYOR_REPO_BRANCH CI_COMMIT_REF_NAME BITBUCKET_BRANCH}.freeze
|
28
|
+
BRANCH_ENV_VAR_NAMES = %w{GITHUB_HEAD_REF GITHUB_REF BUILDKITE_BRANCH CIRCLE_BRANCH TRAVIS_BRANCH GIT_BRANCH GIT_LOCAL_BRANCH APPVEYOR_REPO_BRANCH CI_COMMIT_REF_NAME BITBUCKET_BRANCH}.freeze
|
29
29
|
COMMIT_ENV_VAR_NAMES = %w{GITHUB_SHA BUILDKITE_COMMIT CIRCLE_SHA1 TRAVIS_COMMIT GIT_COMMIT APPVEYOR_REPO_COMMIT CI_COMMIT_ID BITBUCKET_COMMIT}
|
30
30
|
BUILD_URL_ENV_VAR_NAMES = %w{BUILDKITE_BUILD_URL CIRCLE_BUILD_URL TRAVIS_BUILD_WEB_URL BUILD_URL }
|
31
31
|
|
@@ -91,11 +91,11 @@ module PactBroker
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def _link!(key)
|
94
|
-
_link(key) or raise RelationNotFoundError.new(
|
94
|
+
_link(key) or raise RelationNotFoundError.new(relation_not_found_error_message(key, @href))
|
95
95
|
end
|
96
96
|
|
97
97
|
def _links!(key)
|
98
|
-
_links(key) or raise RelationNotFoundError.new(
|
98
|
+
_links(key) or raise RelationNotFoundError.new(relation_not_found_error_message(key, @href))
|
99
99
|
end
|
100
100
|
|
101
101
|
def embedded_entity
|
@@ -161,6 +161,10 @@ module PactBroker
|
|
161
161
|
def self_href(entity_hash)
|
162
162
|
entity_hash["_links"] && entity_hash["_links"]["self"] && entity_hash["_links"]["self"]["href"]
|
163
163
|
end
|
164
|
+
|
165
|
+
def relation_not_found_error_message(key, href)
|
166
|
+
"Could not find relation '#{key}' in resource at #{href}. The most likely reason for this is that you are on an old version of the Pact Broker and you need to upgrade, or you are using Pactflow and you don't have the permissions required for this action."
|
167
|
+
end
|
164
168
|
end
|
165
169
|
|
166
170
|
class ErrorEntity < Entity
|
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'uri'
|
2
2
|
require 'delegate'
|
3
|
+
require 'pact_broker/client/hash_refinements'
|
3
4
|
|
4
5
|
module PactBroker
|
5
6
|
module Client
|
6
7
|
module Hal
|
7
8
|
class Links
|
9
|
+
using PactBroker::Client::HashRefinements
|
10
|
+
|
8
11
|
def initialize(href, key, links)
|
9
12
|
@href = href
|
10
13
|
@key = key
|
@@ -13,6 +13,15 @@ module PactBroker
|
|
13
13
|
def compact!
|
14
14
|
reject! {|_key, value| value == nil}
|
15
15
|
end unless Hash.method_defined? :compact!
|
16
|
+
|
17
|
+
def except(*keys)
|
18
|
+
if keys.size > 4 && size > 4 # index if O(m*n) is big
|
19
|
+
h = {}
|
20
|
+
keys.each { |key| h[key] = true }
|
21
|
+
keys = h
|
22
|
+
end
|
23
|
+
reject { |key, _value| keys.include? key}
|
24
|
+
end unless method_defined? :except
|
16
25
|
end
|
17
26
|
end
|
18
27
|
end
|