pact_broker-client 1.35.0 → 1.38.1
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 -0
- data/CHANGELOG.md +34 -0
- data/Rakefile +2 -0
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +283 -0
- data/lib/pact_broker/client.rb +1 -1
- data/lib/pact_broker/client/backports.rb +13 -0
- data/lib/pact_broker/client/cli/broker.rb +112 -34
- data/lib/pact_broker/client/cli/can_i_deploy_long_desc.txt +18 -9
- data/lib/pact_broker/client/cli/create_or_update_webhook_long_desc.txt +3 -1
- data/lib/pact_broker/client/cli/create_webhook_long_desc.txt +2 -0
- data/lib/pact_broker/client/cli/custom_thor.rb +11 -17
- data/lib/pact_broker/client/git.rb +43 -22
- data/lib/pact_broker/client/hal/entity.rb +44 -3
- data/lib/pact_broker/client/hal/http_client.rb +5 -1
- data/lib/pact_broker/client/hal/links.rb +39 -0
- data/lib/pact_broker/client/hal_client_methods.rb +11 -0
- data/lib/pact_broker/client/hash_refinements.rb +19 -0
- data/lib/pact_broker/client/matrix.rb +2 -1
- data/lib/pact_broker/client/matrix/text_formatter.rb +2 -0
- data/lib/pact_broker/client/publish_pacts.rb +85 -14
- data/lib/pact_broker/client/tasks/publication_task.rb +37 -6
- data/lib/pact_broker/client/version.rb +1 -1
- data/lib/pact_broker/client/versions/record_deployment.rb +109 -0
- data/lib/pact_broker/client/versions/record_undeployment.rb +125 -0
- data/pact-broker-client.gemspec +1 -1
- data/script/publish-pact.sh +7 -1
- data/script/record-deployment.sh +4 -0
- data/script/trigger-release.sh +1 -1
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +51 -6
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +108 -12
- data/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +1 -7
- data/spec/lib/pact_broker/client/git_spec.rb +39 -2
- data/spec/lib/pact_broker/client/hal/entity_spec.rb +4 -3
- data/spec/lib/pact_broker/client/publish_pacts_spec.rb +99 -6
- data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +88 -10
- data/spec/lib/pact_broker/client/versions/describe_spec.rb +0 -1
- data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +82 -0
- data/spec/pacts/pact_broker_client-pact_broker.json +287 -0
- data/spec/service_providers/pact_broker_client_create_version_spec.rb +89 -0
- data/spec/service_providers/pact_broker_client_matrix_spec.rb +4 -0
- data/spec/service_providers/pact_broker_client_versions_spec.rb +1 -2
- data/spec/service_providers/record_deployment_spec.rb +219 -0
- data/spec/spec_helper.rb +2 -0
- data/tasks/pact.rake +2 -0
- metadata +19 -7
@@ -19,17 +19,27 @@ Using a specific version is the easiest way to ensure you get an accurate respon
|
|
19
19
|
|
20
20
|
#### Recommended usage - allowing the Pact Broker to automatically determine the dependencies
|
21
21
|
|
22
|
-
Prerequisite: if you would like the Pact Broker to calculate the dependencies for you when you want to deploy an application into a given environment, you will need to let the Broker know which version of each application is in that environment.
|
22
|
+
Prerequisite: if you would like the Pact Broker to calculate the dependencies for you when you want to deploy an application into a given environment, you will need to let the Broker know which version of each application is in that environment.
|
23
|
+
|
24
|
+
How you do this depends on the version of the Pact Broker you are running.
|
25
|
+
|
26
|
+
If you are using a Broker version where deployment versions are supported, then you would notify the Broker of the deployment of this application version like so:
|
27
|
+
|
28
|
+
$ pact-broker record-deployment --pacticipant Foo --version 173153ae0 --environment test
|
29
|
+
|
30
|
+
This assumes that you have already set up an environment named "test" in the Broker.
|
31
|
+
|
32
|
+
If you are using a Broker version that does not support deployment environments, then you will need to use tags to notify the broker of the deployment of this application version, like so:
|
23
33
|
|
24
34
|
$ pact-broker create-version-tag --pacticipant Foo --version 173153ae0 --tag test
|
25
35
|
|
26
|
-
|
36
|
+
Once you have configured your build to notify the Pact Broker of the successful deployment using either method describe above, you can use the following simple command to find out if you are safe to deploy (use either `--to` or `--to-environment` as supported):
|
27
37
|
|
28
|
-
$ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION
|
29
|
-
--to ENVIRONMENT
|
38
|
+
$ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION
|
39
|
+
[--to-environment ENVIRONMENT | --to ENVIRONMENT_TAG ]
|
30
40
|
--broker-base-url BROKER_BASE_URL
|
31
41
|
|
32
|
-
If the `--to`
|
42
|
+
If the `--to` or `--to-environment` options are omitted, then the query will return the compatiblity with the overall latest version of each of the other applications.
|
33
43
|
|
34
44
|
Examples:
|
35
45
|
|
@@ -38,7 +48,7 @@ Can I deploy version 173153ae0 of application Foo to the test environment?
|
|
38
48
|
|
39
49
|
|
40
50
|
$ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 \
|
41
|
-
--to test \
|
51
|
+
--to-environment test \
|
42
52
|
--broker-base-url https://my-pact-broker
|
43
53
|
|
44
54
|
|
@@ -56,21 +66,20 @@ Can I deploy the latest version of the application Foo that has the tag "test" t
|
|
56
66
|
--broker-base-url https://my-pact-broker
|
57
67
|
|
58
68
|
|
59
|
-
|
60
69
|
#### Alternate usage - specifying dependencies explicitly
|
61
70
|
|
62
71
|
If you are unable to use tags, or there is some other limitation that stops you from using the recommended approach, you can specify one or more of the dependencies explictly. You must also do this if you want to use the `--all TAG` option for any of the pacticipants.
|
63
72
|
|
64
73
|
You can specify as many application versions as you like, and you can even specify multiple versions of the same application (repeat the `--pacticipant` name and supply a different version.)
|
65
74
|
|
66
|
-
You can use explictly declared dependencies with or without the `--to
|
75
|
+
You can use explictly declared dependencies with or without the `--to ENVIRONMENT_TAG`. For example, if you declare two (or more) application versions with no `--to ENVIRONMENT_TAG`, then only the applications you specify will be taken into account when determining if it is safe to deploy. If you declare two (or more) application versions _as well as_ a `--to ENVIRONMENT`, then the Pact Broker will work out what integrations your declared applications will have in that environment when determining if it safe to deploy. When using this script for a production release, and you are using tags, it is always the most future-proof option to use the `--to` if possible, as it will catch any newly added consumers or providers.
|
67
76
|
|
68
77
|
If you are finding that your dependencies are not being automatically included when you supply multiple pacticipant versions, please upgrade to the latest version of the Pact Broker, as this is a more recently added feature.
|
69
78
|
|
70
79
|
|
71
80
|
$ pact-broker can-i-deploy --pacticipant PACTICIPANT_1 [--version VERSION_1 | --latest [TAG_1] | --all TAG_1] \
|
72
81
|
--pacticipant PACTICIPANT_2 [--version VERSION_2 | --latest [TAG_2] | --all TAG_2] \
|
73
|
-
[--to ENVIRONMENT] \
|
82
|
+
[--to-environment ENVIRONMENT | --to ENVIRONMENT_TAG] \
|
74
83
|
--broker-base-url BROKER_BASE_URL
|
75
84
|
|
76
85
|
Examples:
|
@@ -1 +1,3 @@
|
|
1
|
-
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-or-update-webhook" and add the consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-or-update-webhook and a uuid must also be provided. You can generate a valid UUID by using the `generate-uuid` command.
|
1
|
+
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-or-update-webhook" and add the consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-or-update-webhook and a uuid must also be provided. You can generate a valid UUID by using the `generate-uuid` command.
|
2
|
+
|
3
|
+
Note that the -u option from the curl command clashes with the -u option from the pact-broker CLI. When used in this command, the -u will be used as a curl option. Please use the --broker-username or environment variable for the Pact Broker username.
|
@@ -1 +1,3 @@
|
|
1
1
|
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-webhook" and add the consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-webhook.
|
2
|
+
|
3
|
+
Note that the -u option from the curl command clashes with the -u option from the pact-broker CLI. When used in this command, the -u will be used as a curl option. Please use the --broker-username or environment variable for the Pact Broker username.
|
@@ -22,10 +22,7 @@ module PactBroker
|
|
22
22
|
def self.add_broker_config_from_environment_variables argv
|
23
23
|
return argv if argv[0] == 'help' || argv.empty?
|
24
24
|
|
25
|
-
|
26
|
-
new_argv = add_option_from_environment_variable(new_argv, 'broker-username', 'u', 'PACT_BROKER_USERNAME')
|
27
|
-
new_argv = add_option_from_environment_variable(new_argv, 'broker-token', 'k', 'PACT_BROKER_TOKEN')
|
28
|
-
add_option_from_environment_variable(new_argv, 'broker-password', 'p', 'PACT_BROKER_PASSWORD')
|
25
|
+
add_option_from_environment_variable(argv, 'broker-base-url', 'b', 'PACT_BROKER_BASE_URL')
|
29
26
|
end
|
30
27
|
|
31
28
|
def self.add_option_from_environment_variable argv, long_name, short_name, environment_variable_name
|
@@ -86,6 +83,14 @@ module PactBroker
|
|
86
83
|
method_option :broker_token, hide: true
|
87
84
|
end
|
88
85
|
|
86
|
+
def self.shared_authentication_options
|
87
|
+
method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
|
88
|
+
method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
|
89
|
+
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
|
90
|
+
method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token"
|
91
|
+
method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
|
92
|
+
end
|
93
|
+
|
89
94
|
def self.shared_options_for_webhook_commands
|
90
95
|
method_option :request, banner: "METHOD", aliases: "-X", desc: "Webhook HTTP method", required: true
|
91
96
|
method_option :header, aliases: "-H", type: :array, desc: "Webhook Header"
|
@@ -93,24 +98,13 @@ module PactBroker
|
|
93
98
|
method_option :user, aliases: "-u", desc: "Webhook basic auth username and password eg. username:password"
|
94
99
|
method_option :consumer, desc: "Consumer name"
|
95
100
|
method_option :provider, desc: "Provider name"
|
96
|
-
method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
|
97
|
-
method_option :broker_username, desc: "Pact Broker basic auth username"
|
98
|
-
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
|
99
|
-
method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token"
|
100
101
|
method_option :description, desc: "Wwebhook description"
|
101
102
|
method_option :contract_content_changed, type: :boolean, desc: "Trigger this webhook when the pact content changes"
|
102
103
|
method_option :contract_published, type: :boolean, desc: "Trigger this webhook when a pact is published"
|
103
104
|
method_option :provider_verification_published, type: :boolean, desc: "Trigger this webhook when a provider verification result is published"
|
104
105
|
method_option :provider_verification_failed, type: :boolean, desc: "Trigger this webhook when a failed provider verification result is published"
|
105
106
|
method_option :provider_verification_succeeded, type: :boolean, desc: "Trigger this webhook when a successful provider verification result is published"
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.shared_authentication_options_for_pact_broker
|
110
|
-
method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
|
111
|
-
method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
|
112
|
-
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
|
113
|
-
method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token"
|
107
|
+
shared_authentication_options
|
114
108
|
end
|
115
109
|
|
116
110
|
def self.verbose_option
|
@@ -120,4 +114,4 @@ module PactBroker
|
|
120
114
|
end
|
121
115
|
end
|
122
116
|
end
|
123
|
-
end
|
117
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'pact_broker/client/error'
|
2
|
+
require 'pact_broker/client/hash_refinements'
|
2
3
|
|
3
4
|
=begin
|
4
5
|
|
@@ -16,19 +17,25 @@ BITBUCKET_BRANCH BITBUCKET_COMMIT https://confluence.atlassian.com/bitbucket/var
|
|
16
17
|
=end
|
17
18
|
|
18
19
|
# Keep in sync with pact-provider-verifier/lib/pact/provider_verifier/git.rb
|
20
|
+
|
21
|
+
# `git name-rev --name-only HEAD` provides "tags/v1.35.0^0"
|
19
22
|
module PactBroker
|
20
23
|
module Client
|
21
24
|
module Git
|
22
|
-
|
25
|
+
using PactBroker::Client::HashRefinements
|
26
|
+
|
27
|
+
COMMAND = 'git rev-parse --abbrev-ref HEAD'.freeze
|
23
28
|
BRANCH_ENV_VAR_NAMES = %w{BUILDKITE_BRANCH CIRCLE_BRANCH TRAVIS_BRANCH GIT_BRANCH GIT_LOCAL_BRANCH APPVEYOR_REPO_BRANCH CI_COMMIT_REF_NAME BITBUCKET_BRANCH}.freeze
|
24
29
|
COMMIT_ENV_VAR_NAMES = %w{BUILDKITE_COMMIT CIRCLE_SHA1 TRAVIS_COMMIT GIT_COMMIT APPVEYOR_REPO_COMMIT CI_COMMIT_ID BITBUCKET_COMMIT}
|
25
30
|
|
31
|
+
BUILD_URL_ENV_VAR_NAMES = %w{BUILDKITE_BUILD_URL CIRCLE_BUILD_URL TRAVIS_BUILD_WEB_URL BUILD_URL }
|
32
|
+
|
26
33
|
def self.commit
|
27
34
|
find_commit_from_env_vars
|
28
35
|
end
|
29
36
|
|
30
|
-
def self.branch
|
31
|
-
|
37
|
+
def self.branch(options)
|
38
|
+
find_branch_from_known_env_vars || find_branch_from_env_var_ending_with_branch || branch_from_git_command(options[:raise_error])
|
32
39
|
end
|
33
40
|
|
34
41
|
# private
|
@@ -37,10 +44,21 @@ module PactBroker
|
|
37
44
|
COMMIT_ENV_VAR_NAMES.collect { |env_var_name| value_from_env_var(env_var_name) }.compact.first
|
38
45
|
end
|
39
46
|
|
40
|
-
def self.
|
47
|
+
def self.find_branch_from_known_env_vars
|
41
48
|
BRANCH_ENV_VAR_NAMES.collect { |env_var_name| value_from_env_var(env_var_name) }.compact.first
|
42
49
|
end
|
43
50
|
|
51
|
+
def self.find_branch_from_env_var_ending_with_branch
|
52
|
+
values = ENV.keys
|
53
|
+
.select{ |env_var_name| env_var_name.end_with?("_BRANCH") }
|
54
|
+
.collect{ |env_var_name| value_from_env_var(env_var_name) }.compact
|
55
|
+
if values.size == 1
|
56
|
+
values.first
|
57
|
+
else
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
44
62
|
def self.value_from_env_var(env_var_name)
|
45
63
|
val = ENV[env_var_name]
|
46
64
|
if val && val.strip.size > 0
|
@@ -50,24 +68,10 @@ module PactBroker
|
|
50
68
|
end
|
51
69
|
end
|
52
70
|
|
53
|
-
def self.branch_from_git_command
|
54
|
-
branch_names =
|
55
|
-
|
56
|
-
|
57
|
-
.split("\n")
|
58
|
-
.collect(&:strip)
|
59
|
-
.reject(&:empty?)
|
60
|
-
.collect(&:split)
|
61
|
-
.collect(&:first)
|
62
|
-
.collect{ |line| line.gsub(/^origin\//, '') }
|
63
|
-
.reject{ |line| line == "HEAD" }
|
64
|
-
|
65
|
-
rescue StandardError => e
|
66
|
-
raise PactBroker::Client::Error, "Could not determine current git branch using command `#{COMMAND}`. #{e.class} #{e.message}"
|
67
|
-
end
|
68
|
-
|
69
|
-
validate_branch_names(branch_names)
|
70
|
-
branch_names[0]
|
71
|
+
def self.branch_from_git_command(raise_error)
|
72
|
+
branch_names = execute_and_parse_command(raise_error)
|
73
|
+
validate_branch_names(branch_names) if raise_error
|
74
|
+
branch_names.size == 1 ? branch_names[0] : nil
|
71
75
|
end
|
72
76
|
|
73
77
|
def self.validate_branch_names(branch_names)
|
@@ -83,6 +87,23 @@ module PactBroker
|
|
83
87
|
def self.execute_git_command
|
84
88
|
`#{COMMAND}`
|
85
89
|
end
|
90
|
+
|
91
|
+
def self.execute_and_parse_command(raise_error)
|
92
|
+
execute_git_command
|
93
|
+
.split("\n")
|
94
|
+
.collect(&:strip)
|
95
|
+
.reject(&:empty?)
|
96
|
+
.collect(&:split)
|
97
|
+
.collect(&:first)
|
98
|
+
.collect{ |line| line.gsub(/^origin\//, '') }
|
99
|
+
.reject{ |line| line == "HEAD" }
|
100
|
+
rescue StandardError => e
|
101
|
+
if raise_error
|
102
|
+
raise PactBroker::Client::Error, "Could not determine current git branch using command `#{COMMAND}`. #{e.class} #{e.message}"
|
103
|
+
else
|
104
|
+
return []
|
105
|
+
end
|
106
|
+
end
|
86
107
|
end
|
87
108
|
end
|
88
109
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'erb'
|
2
2
|
require 'delegate'
|
3
|
+
require 'pact_broker/client/error'
|
3
4
|
require 'pact_broker/client/hal/link'
|
5
|
+
require 'pact_broker/client/hal/links'
|
4
6
|
|
5
7
|
module PactBroker
|
6
8
|
module Client
|
@@ -51,10 +53,43 @@ module PactBroker
|
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
56
|
+
def _links(key)
|
57
|
+
if @links[key] && @links[key].is_a?(Array)
|
58
|
+
link_collection = @links[key].collect do | hash |
|
59
|
+
Link.new(hash, @client)
|
60
|
+
end
|
61
|
+
Links.new(@href, key, link_collection)
|
62
|
+
elsif @links[key].is_a?(Hash)
|
63
|
+
Links.new(@href, key, [Link.new(@links[key], @client)])
|
64
|
+
else
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
54
69
|
def _link!(key)
|
55
70
|
_link(key) or raise RelationNotFoundError.new("Could not find relation '#{key}' in resource at #{@href}")
|
56
71
|
end
|
57
72
|
|
73
|
+
def _links!(key)
|
74
|
+
_links(key) or raise RelationNotFoundError.new("Could not find relation '#{key}' in resource at #{@href}")
|
75
|
+
end
|
76
|
+
|
77
|
+
def embedded_entity
|
78
|
+
embedded_ent = yield @data["_embedded"]
|
79
|
+
Entity.new(embedded_ent["_links"]["self"]["href"], embedded_ent, @client, response)
|
80
|
+
end
|
81
|
+
|
82
|
+
def embedded_entities(key = nil)
|
83
|
+
embedded_ents = if key
|
84
|
+
@data["_embedded"][key]
|
85
|
+
else
|
86
|
+
yield @data["_embedded"]
|
87
|
+
end
|
88
|
+
embedded_ents.collect do | embedded_ent |
|
89
|
+
Entity.new(embedded_ent["_links"]["self"]["href"], embedded_ent, @client, response)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
58
93
|
def success?
|
59
94
|
true
|
60
95
|
end
|
@@ -85,7 +120,7 @@ module PactBroker
|
|
85
120
|
@data.key?(method_name) || @links.key?(method_name)
|
86
121
|
end
|
87
122
|
|
88
|
-
def assert_success!
|
123
|
+
def assert_success!(_ignored = nil)
|
89
124
|
self
|
90
125
|
end
|
91
126
|
end
|
@@ -107,8 +142,14 @@ module PactBroker
|
|
107
142
|
false
|
108
143
|
end
|
109
144
|
|
110
|
-
def assert_success!
|
111
|
-
|
145
|
+
def assert_success!(messages = {})
|
146
|
+
default_message = "Error retrieving #{@href} status=#{response ? response.status: nil} #{response ? response.raw_body : ''}".strip
|
147
|
+
message = if response && messages[response.status]
|
148
|
+
(messages[response.status] || "") + " (#{default_message})"
|
149
|
+
else
|
150
|
+
default_message
|
151
|
+
end
|
152
|
+
raise ErrorResponseReturned.new(message)
|
112
153
|
end
|
113
154
|
end
|
114
155
|
end
|
@@ -17,7 +17,7 @@ module PactBroker
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def get href, params = {}, headers = {}
|
20
|
-
query = params.collect{ |(key, value)| "#{CGI::escape(key)}=#{CGI::escape(value)}" }.join("&")
|
20
|
+
query = params.collect{ |(key, value)| "#{CGI::escape(key.to_s)}=#{CGI::escape(value)}" }.join("&")
|
21
21
|
uri = URI(href)
|
22
22
|
uri.query = query
|
23
23
|
perform_request(create_request(uri, 'Get', nil, headers), uri)
|
@@ -83,6 +83,10 @@ module PactBroker
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
+
def headers
|
87
|
+
__getobj__().to_hash
|
88
|
+
end
|
89
|
+
|
86
90
|
def raw_body
|
87
91
|
__getobj__().body
|
88
92
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'delegate'
|
3
|
+
|
4
|
+
module PactBroker
|
5
|
+
module Client
|
6
|
+
module Hal
|
7
|
+
class Links
|
8
|
+
def initialize(href, key, links)
|
9
|
+
@href = href
|
10
|
+
@key = key
|
11
|
+
@links = links
|
12
|
+
end
|
13
|
+
|
14
|
+
def names
|
15
|
+
@names ||= links.collect(&:name).compact.uniq
|
16
|
+
end
|
17
|
+
|
18
|
+
def find!(name, not_found_message = nil)
|
19
|
+
link = find(name)
|
20
|
+
if link
|
21
|
+
link
|
22
|
+
else
|
23
|
+
message = not_found_message || "Could not find relation '#{key}' with name '#{name}' in resource at #{href}."
|
24
|
+
available_options = names.any? ? names.join(", ") : "<none found>"
|
25
|
+
raise RelationNotFoundError.new(message.chomp(".") + ". Available options: #{available_options}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def find(name)
|
30
|
+
links.find{ | link | link.name == name }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
attr_reader :links, :key, :href
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'pact_broker/client/hal'
|
2
|
+
require 'pact_broker/client/retry'
|
2
3
|
|
3
4
|
module PactBroker
|
4
5
|
module Client
|
@@ -10,6 +11,16 @@ module PactBroker
|
|
10
11
|
def create_http_client(pact_broker_client_options)
|
11
12
|
PactBroker::Client::Hal::HttpClient.new(pact_broker_client_options.merge(pact_broker_client_options[:basic_auth] || {}))
|
12
13
|
end
|
14
|
+
|
15
|
+
def index_entry_point
|
16
|
+
@index_entry_point ||= create_index_entry_point(pact_broker_base_url, pact_broker_client_options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def index_resource
|
20
|
+
@index_resource ||= Retry.while_error do
|
21
|
+
index_entry_point.get!
|
22
|
+
end
|
23
|
+
end
|
13
24
|
end
|
14
25
|
end
|
15
26
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module PactBroker
|
2
|
+
module Client
|
3
|
+
module HashRefinements
|
4
|
+
refine Hash do
|
5
|
+
def compact
|
6
|
+
h = {}
|
7
|
+
each do |key, value|
|
8
|
+
h[key] = value unless value == nil
|
9
|
+
end
|
10
|
+
h
|
11
|
+
end unless Hash.method_defined? :compact
|
12
|
+
|
13
|
+
def compact!
|
14
|
+
reject! {|_key, value| value == nil}
|
15
|
+
end unless Hash.method_defined? :compact!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -53,10 +53,11 @@ module PactBroker
|
|
53
53
|
opts[:success] = [*options[:success]]
|
54
54
|
end
|
55
55
|
opts[:limit] = options[:limit] if options[:limit]
|
56
|
+
opts[:environment] = options[:to_environment] if options[:to_environment]
|
56
57
|
if options[:to_tag]
|
57
58
|
opts[:latest] = 'true'
|
58
59
|
opts[:tag] = options[:to_tag]
|
59
|
-
elsif selectors.size == 1
|
60
|
+
elsif selectors.size == 1 && !options[:to_environment]
|
60
61
|
opts[:latest] = 'true'
|
61
62
|
end
|
62
63
|
opts
|
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'table_print'
|
2
2
|
require 'dig_rb'
|
3
|
+
require 'pact_broker/client/hash_refinements'
|
3
4
|
|
4
5
|
module PactBroker
|
5
6
|
module Client
|
6
7
|
class Matrix
|
7
8
|
class TextFormatter
|
9
|
+
using PactBroker::Client::HashRefinements
|
8
10
|
|
9
11
|
Line = Struct.new(:consumer, :consumer_version, :provider, :provider_version, :success, :ref)
|
10
12
|
|