pact_broker-client 1.40.0 → 1.45.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/test.yml +21 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +57 -0
- data/Gemfile +4 -0
- data/README.md +39 -22
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +79 -280
- data/lib/pact_broker/client/backports.rb +9 -0
- data/lib/pact_broker/client/base_command.rb +98 -0
- data/lib/pact_broker/client/can_i_deploy.rb +57 -5
- data/lib/pact_broker/client/cli/broker.rb +23 -76
- data/lib/pact_broker/client/cli/custom_thor.rb +12 -0
- data/lib/pact_broker/client/cli/deployment_commands.rb +94 -0
- data/lib/pact_broker/client/cli/environment_commands.rb +70 -0
- data/lib/pact_broker/client/cli/pacticipant_commands.rb +53 -0
- data/lib/pact_broker/client/cli/record_deployment_long_desc.txt +0 -55
- data/lib/pact_broker/client/cli/version_selector_options_parser.rb +4 -0
- data/lib/pact_broker/client/colorize_notices.rb +31 -0
- data/lib/pact_broker/client/deployments.rb +4 -0
- data/lib/pact_broker/client/deployments/record_deployment.rb +38 -0
- data/lib/pact_broker/client/deployments/record_release.rb +99 -0
- data/lib/pact_broker/client/deployments/record_support_ended.rb +103 -0
- data/lib/pact_broker/client/deployments/record_undeployment.rb +127 -0
- data/lib/pact_broker/client/describe_text_formatter.rb +23 -0
- data/lib/pact_broker/client/environments.rb +6 -0
- data/lib/pact_broker/client/environments/create_environment.rb +31 -0
- data/lib/pact_broker/client/environments/delete_environment.rb +27 -0
- data/lib/pact_broker/client/environments/describe_environment.rb +26 -0
- data/lib/pact_broker/client/environments/environment_command.rb +66 -0
- data/lib/pact_broker/client/environments/list_environments.rb +30 -0
- data/lib/pact_broker/client/environments/text_formatter.rb +30 -0
- data/lib/pact_broker/client/environments/update_environment.rb +31 -0
- data/lib/pact_broker/client/generate_display_name.rb +27 -0
- data/lib/pact_broker/client/hal/entity.rb +31 -6
- data/lib/pact_broker/client/hal/http_client.rb +8 -2
- data/lib/pact_broker/client/hal/link.rb +8 -0
- data/lib/pact_broker/client/hal_client_methods.rb +1 -3
- data/lib/pact_broker/client/matrix.rb +4 -0
- data/lib/pact_broker/client/matrix/abbreviate_version_number.rb +15 -0
- data/lib/pact_broker/client/matrix/resource.rb +26 -1
- data/lib/pact_broker/client/matrix/text_formatter.rb +28 -17
- data/lib/pact_broker/client/pacticipants.rb +6 -0
- data/lib/pact_broker/client/pacticipants/create.rb +24 -34
- data/lib/pact_broker/client/pacticipants/describe.rb +33 -0
- data/lib/pact_broker/client/pacticipants/list.rb +34 -0
- data/lib/pact_broker/client/pacticipants/text_formatter.rb +41 -0
- data/lib/pact_broker/client/publish_pacts.rb +6 -2
- data/lib/pact_broker/client/string_refinements.rb +56 -0
- data/lib/pact_broker/client/version.rb +1 -1
- data/lib/pact_broker/client/versions.rb +4 -1
- data/lib/pact_broker/client/versions/describe.rb +3 -1
- data/lib/pact_broker/client/versions/formatter.rb +3 -1
- data/lib/pact_broker/client/versions/json_formatter.rb +5 -3
- data/lib/pact_broker/client/versions/text_formatter.rb +3 -1
- data/pact-broker-client.gemspec +2 -0
- data/script/approve-all.sh +6 -0
- data/script/publish-pact.sh +12 -9
- data/script/record-deployments-and-releases.sh +18 -0
- data/spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt +7 -0
- data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +13 -0
- data/spec/fixtures/approvals/can_i_deploy_success_dry_run.approved.txt +7 -0
- data/spec/fixtures/approvals/describe_environment.approved.txt +7 -0
- data/spec/fixtures/approvals/describe_pacticipant.approved.txt +2 -0
- data/spec/fixtures/approvals/list_environments.approved.txt +3 -0
- data/spec/integration/describe_environment_spec.rb +31 -0
- data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +109 -7
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +19 -6
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +1 -1
- data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +3 -3
- data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +21 -0
- data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +204 -0
- data/spec/lib/pact_broker/client/deployments/record_support_ended_spec.rb +208 -0
- data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +219 -0
- data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +120 -0
- data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +89 -0
- data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +167 -0
- data/spec/lib/pact_broker/client/generate_display_name_spec.rb +39 -0
- data/spec/lib/pact_broker/client/hal/entity_spec.rb +2 -2
- data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +2 -2
- data/spec/pacts/pact_broker_client-pact_broker.json +88 -287
- data/spec/service_providers/create_environment_spec.rb +78 -0
- data/spec/service_providers/list_environments_spec.rb +77 -0
- data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +98 -0
- data/spec/service_providers/pact_broker_client_register_repository_spec.rb +2 -2
- data/spec/service_providers/pacticipants_create_spec.rb +5 -4
- data/spec/service_providers/publish_pacts_spec.rb +5 -2
- data/spec/service_providers/record_deployment_spec.rb +17 -36
- data/spec/service_providers/record_release_spec.rb +132 -0
- data/spec/service_providers/record_undeployment_spec.rb +166 -0
- data/spec/spec_helper.rb +15 -2
- data/spec/support/approvals.rb +26 -0
- data/spec/support/shared_context.rb +8 -3
- data/tasks/pact.rake +21 -1
- metadata +104 -7
- data/lib/pact_broker/client/versions/record_deployment.rb +0 -109
- data/lib/pact_broker/client/versions/record_undeployment.rb +0 -102
- data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +0 -82
@@ -1,109 +0,0 @@
|
|
1
|
-
require 'pact_broker/client/hal_client_methods'
|
2
|
-
require 'pact_broker/client/error'
|
3
|
-
require 'pact_broker/client/command_result'
|
4
|
-
|
5
|
-
module PactBroker
|
6
|
-
module Client
|
7
|
-
class Versions
|
8
|
-
class RecordDeployment
|
9
|
-
include PactBroker::Client::HalClientMethods
|
10
|
-
|
11
|
-
NOT_SUPPORTED_MESSAGE = "This version of the Pact Broker does not support recording deployments. Please upgrade to version 2.80.0 or later."
|
12
|
-
|
13
|
-
def self.call(params, pact_broker_base_url, pact_broker_client_options)
|
14
|
-
new(params, pact_broker_base_url, pact_broker_client_options).call
|
15
|
-
end
|
16
|
-
|
17
|
-
def initialize(params, pact_broker_base_url, pact_broker_client_options)
|
18
|
-
@pact_broker_base_url = pact_broker_base_url
|
19
|
-
@pacticipant_name = params.fetch(:pacticipant_name)
|
20
|
-
@version_number = params.fetch(:version_number)
|
21
|
-
@environment_name = params.fetch(:environment_name)
|
22
|
-
@target = params.fetch(:target)
|
23
|
-
@output = params.fetch(:output)
|
24
|
-
@pact_broker_client_options = pact_broker_client_options
|
25
|
-
end
|
26
|
-
|
27
|
-
def call
|
28
|
-
check_if_command_supported
|
29
|
-
record_deployment
|
30
|
-
|
31
|
-
PactBroker::Client::CommandResult.new(true, result_message)
|
32
|
-
rescue PactBroker::Client::Error => e
|
33
|
-
PactBroker::Client::CommandResult.new(false, e.message)
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
attr_reader :pact_broker_base_url, :pact_broker_client_options
|
39
|
-
attr_reader :pacticipant_name, :version_number, :environment_name, :target, :output
|
40
|
-
attr_reader :deployed_version_resource
|
41
|
-
|
42
|
-
def check_environment_exists
|
43
|
-
index_resource
|
44
|
-
._link!("pb:environments")
|
45
|
-
.get!
|
46
|
-
._links("pb:environments")
|
47
|
-
.find!(environment_name, "No environment found with name '#{environment_name}'")
|
48
|
-
end
|
49
|
-
|
50
|
-
def record_deployment
|
51
|
-
@deployed_version_resource =
|
52
|
-
get_record_deployment_relation
|
53
|
-
.post(record_deployment_request_body)
|
54
|
-
.assert_success!
|
55
|
-
end
|
56
|
-
|
57
|
-
def get_record_deployment_relation
|
58
|
-
record_deployment_links = get_pacticipant_version._links!("pb:record-deployment")
|
59
|
-
link_for_environment = record_deployment_links.find(environment_name)
|
60
|
-
if link_for_environment
|
61
|
-
link_for_environment
|
62
|
-
else
|
63
|
-
check_environment_exists
|
64
|
-
# Force the exception to be raised
|
65
|
-
record_deployment_links.find!(environment_name, "Environment '#{environment_name}' is not an available option for recording a deployment of #{pacticipant_name}.")
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def get_pacticipant_version
|
70
|
-
index_resource
|
71
|
-
._link!("pb:pacticipant-version")
|
72
|
-
.expand(pacticipant: pacticipant_name, version: version_number)
|
73
|
-
.get
|
74
|
-
.assert_success!(404 => "#{pacticipant_name} version #{version_number} not found")
|
75
|
-
end
|
76
|
-
|
77
|
-
def record_deployment_request_body
|
78
|
-
{ replacedPreviousDeployedVersion: target }
|
79
|
-
end
|
80
|
-
|
81
|
-
def result_message
|
82
|
-
if output == "text"
|
83
|
-
message = "Recorded deployment of #{pacticipant_name} version #{version_number} to #{environment_name} in #{pact_broker_name}."
|
84
|
-
suffix = target ? " Marked previous deployed version as undeployed." : ""
|
85
|
-
message + suffix
|
86
|
-
elsif output == "json"
|
87
|
-
deployed_version_resource.response.raw_body
|
88
|
-
else
|
89
|
-
""
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def pact_broker_name
|
94
|
-
is_pactflow? ? "Pactflow" : "the Pact Broker"
|
95
|
-
end
|
96
|
-
|
97
|
-
def is_pactflow?
|
98
|
-
deployed_version_resource.response.headers.keys.any?{ | header_name | header_name.downcase.include?("pactflow") }
|
99
|
-
end
|
100
|
-
|
101
|
-
def check_if_command_supported
|
102
|
-
unless index_resource.can?("pb:environments")
|
103
|
-
raise PactBroker::Client::Error.new(NOT_SUPPORTED_MESSAGE)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'pact_broker/client/hal_client_methods'
|
2
|
-
require 'pact_broker/client/error'
|
3
|
-
require 'pact_broker/client/command_result'
|
4
|
-
|
5
|
-
# TODO
|
6
|
-
# --limit 1
|
7
|
-
# order by date so that the oldest one gets undeployed first
|
8
|
-
|
9
|
-
module PactBroker
|
10
|
-
module Client
|
11
|
-
class Versions
|
12
|
-
class RecordUndeployment
|
13
|
-
include PactBroker::Client::HalClientMethods
|
14
|
-
|
15
|
-
NOT_SUPPORTED_MESSAGE = "This version of the Pact Broker does not support recording undeployments. Please upgrade to version 2.80.0 or later."
|
16
|
-
|
17
|
-
def self.call(params, pact_broker_base_url, pact_broker_client_options)
|
18
|
-
new(params, pact_broker_base_url, pact_broker_client_options).call
|
19
|
-
end
|
20
|
-
|
21
|
-
def initialize(params, pact_broker_base_url, pact_broker_client_options)
|
22
|
-
@pact_broker_base_url = pact_broker_base_url
|
23
|
-
@pacticipant_name = params.fetch(:pacticipant_name)
|
24
|
-
@version_number = params.fetch(:version_number)
|
25
|
-
@environment_name = params.fetch(:environment_name)
|
26
|
-
@output = params.fetch(:output)
|
27
|
-
@pact_broker_client_options = pact_broker_client_options
|
28
|
-
end
|
29
|
-
|
30
|
-
def call
|
31
|
-
check_if_command_supported
|
32
|
-
if deployed_version_links_for_environment.any?
|
33
|
-
@undeployment_entities = deployed_version_links_for_environment.collect do | deployed_version_link |
|
34
|
-
deployed_version_link.get!._link!("pb:record-undeployment").post!
|
35
|
-
end
|
36
|
-
else
|
37
|
-
check_environment_exists
|
38
|
-
raise_not_found_error
|
39
|
-
end
|
40
|
-
|
41
|
-
PactBroker::Client::CommandResult.new(true, "foo")
|
42
|
-
rescue PactBroker::Client::Error => e
|
43
|
-
PactBroker::Client::CommandResult.new(false, e.message)
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
attr_reader :pact_broker_base_url, :pact_broker_client_options
|
49
|
-
attr_reader :pacticipant_name, :version_number, :environment_name, :target, :output
|
50
|
-
attr_reader :deployed_version_resource, :undeployment_entities
|
51
|
-
|
52
|
-
def version_resource
|
53
|
-
index_resource._link!("pb:pacticipant-version").expand(pacticipant: pacticipant_name, version: version_number).get!
|
54
|
-
end
|
55
|
-
|
56
|
-
def deployed_version_links
|
57
|
-
@deployed_version_links ||= version_resource._links!("pb:currently-deployed-versions")
|
58
|
-
end
|
59
|
-
|
60
|
-
def deployed_version_links_for_environment
|
61
|
-
@deployed_version_links_for_environment ||= deployed_version_links.select(environment_name)
|
62
|
-
end
|
63
|
-
|
64
|
-
def check_environment_exists
|
65
|
-
index_resource
|
66
|
-
._link!("pb:environments")
|
67
|
-
.get!
|
68
|
-
._links("pb:environments")
|
69
|
-
.find!(environment_name, "No environment found with name '#{environment_name}'")
|
70
|
-
end
|
71
|
-
|
72
|
-
def raise_not_found_error
|
73
|
-
raise PactBroker::Client::Error.new(deployed_version_not_found_message)
|
74
|
-
end
|
75
|
-
|
76
|
-
def deployed_version_not_found_message
|
77
|
-
if (env_names = deployed_version_links.names).any?
|
78
|
-
"#{pacticipant_name} version #{version_number} is not currently deployed to #{environment_name}. It is currently deployed to: #{env_names.join(", ")}"
|
79
|
-
else
|
80
|
-
"#{pacticipant_name} version #{version_number} is not currently deployed to any environment."
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def result_message
|
85
|
-
if output == "text"
|
86
|
-
message = "Recorded undeployment of #{pacticipant_name} version #{version_number} from #{environment_name} in #{pact_broker_name}."
|
87
|
-
elsif output == "json"
|
88
|
-
undeployment_entities.last.response.raw_body
|
89
|
-
else
|
90
|
-
""
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def check_if_command_supported
|
95
|
-
unless index_resource.can?("pb:environments")
|
96
|
-
raise PactBroker::Client::Error.new(NOT_SUPPORTED_MESSAGE)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'pact_broker/client/versions/record_deployment'
|
2
|
-
|
3
|
-
module PactBroker
|
4
|
-
module Client
|
5
|
-
class Versions
|
6
|
-
describe RecordDeployment do
|
7
|
-
describe ".call" do
|
8
|
-
let(:broker_base_url) { "http://broker" }
|
9
|
-
let(:index_body_hash) do
|
10
|
-
{
|
11
|
-
_links: {}
|
12
|
-
}
|
13
|
-
end
|
14
|
-
let!(:index_request) do
|
15
|
-
stub_request(:get, broker_base_url).to_return(status: 200, body: index_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
|
16
|
-
end
|
17
|
-
|
18
|
-
let(:target) { true }
|
19
|
-
|
20
|
-
let(:params) do
|
21
|
-
{
|
22
|
-
pacticipant_name: "Foo",
|
23
|
-
version_number: "1",
|
24
|
-
environment_name: "test",
|
25
|
-
target: target,
|
26
|
-
output: "text"
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
let(:pact_broker_client_options) { {} }
|
31
|
-
|
32
|
-
subject { RecordDeployment.call(params, broker_base_url, pact_broker_client_options) }
|
33
|
-
|
34
|
-
context "when the pb:environments relation does not exist" do
|
35
|
-
it "returns an error response" do
|
36
|
-
expect(subject.success).to be false
|
37
|
-
expect(subject.message).to include "does not support"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "when the response headers contain Pactflow" do
|
42
|
-
before do
|
43
|
-
allow_any_instance_of(RecordDeployment).to receive(:check_if_command_supported)
|
44
|
-
allow_any_instance_of(RecordDeployment).to receive(:check_environment_exists)
|
45
|
-
allow_any_instance_of(RecordDeployment).to receive(:record_deployment)
|
46
|
-
allow_any_instance_of(RecordDeployment).to receive(:deployed_version_resource).and_return(deployed_version_resource)
|
47
|
-
end
|
48
|
-
|
49
|
-
let(:response_headers) { { "X-Pactflow-Sha" => "abc" } }
|
50
|
-
|
51
|
-
let(:deployed_version_resource) do
|
52
|
-
double('PactBroker::Client::Hal::Entity', response: double('response', headers: response_headers) )
|
53
|
-
end
|
54
|
-
|
55
|
-
it "indicates the API was Pactflow" do
|
56
|
-
expect(subject.message).to include "Recorded deployment of Foo version 1 to test in Pactflow"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "when target is false" do
|
61
|
-
before do
|
62
|
-
allow_any_instance_of(RecordDeployment).to receive(:check_if_command_supported)
|
63
|
-
allow_any_instance_of(RecordDeployment).to receive(:check_environment_exists)
|
64
|
-
allow_any_instance_of(RecordDeployment).to receive(:record_deployment)
|
65
|
-
allow_any_instance_of(RecordDeployment).to receive(:pact_broker_name).and_return("")
|
66
|
-
end
|
67
|
-
|
68
|
-
let(:target) { false }
|
69
|
-
|
70
|
-
let(:deployed_version_resource) do
|
71
|
-
double('PactBroker::Client::Hal::Entity', response: double('response', headers: response_headers) )
|
72
|
-
end
|
73
|
-
|
74
|
-
it "does not include the message about marking the previous version as undeployed" do
|
75
|
-
expect(subject.message).to_not include "undeployed"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|