pact_broker-client 1.39.0 → 1.44.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +21 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +52 -0
  5. data/Gemfile +4 -0
  6. data/README.md +39 -18
  7. data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +79 -280
  8. data/lib/pact_broker/client/backports.rb +9 -0
  9. data/lib/pact_broker/client/base_command.rb +95 -0
  10. data/lib/pact_broker/client/can_i_deploy.rb +20 -3
  11. data/lib/pact_broker/client/cli/broker.rb +20 -75
  12. data/lib/pact_broker/client/cli/custom_thor.rb +12 -0
  13. data/lib/pact_broker/client/cli/deployment_commands.rb +74 -0
  14. data/lib/pact_broker/client/cli/environment_commands.rb +70 -0
  15. data/lib/pact_broker/client/cli/pacticipant_commands.rb +53 -0
  16. data/lib/pact_broker/client/cli/record_deployment_long_desc.txt +0 -55
  17. data/lib/pact_broker/client/cli/version_selector_options_parser.rb +4 -0
  18. data/lib/pact_broker/client/colorize_notices.rb +31 -0
  19. data/lib/pact_broker/client/deployments.rb +4 -0
  20. data/lib/pact_broker/client/deployments/record_deployment.rb +38 -0
  21. data/lib/pact_broker/client/deployments/record_release.rb +99 -0
  22. data/lib/pact_broker/client/deployments/record_undeployment.rb +120 -0
  23. data/lib/pact_broker/client/describe_text_formatter.rb +23 -0
  24. data/lib/pact_broker/client/environments.rb +6 -0
  25. data/lib/pact_broker/client/environments/create_environment.rb +31 -0
  26. data/lib/pact_broker/client/environments/delete_environment.rb +27 -0
  27. data/lib/pact_broker/client/environments/describe_environment.rb +26 -0
  28. data/lib/pact_broker/client/environments/environment_command.rb +66 -0
  29. data/lib/pact_broker/client/environments/list_environments.rb +30 -0
  30. data/lib/pact_broker/client/environments/text_formatter.rb +30 -0
  31. data/lib/pact_broker/client/environments/update_environment.rb +31 -0
  32. data/lib/pact_broker/client/generate_display_name.rb +27 -0
  33. data/lib/pact_broker/client/hal/entity.rb +14 -4
  34. data/lib/pact_broker/client/hal/http_client.rb +8 -2
  35. data/lib/pact_broker/client/hal/link.rb +8 -0
  36. data/lib/pact_broker/client/hal_client_methods.rb +1 -3
  37. data/lib/pact_broker/client/matrix.rb +4 -0
  38. data/lib/pact_broker/client/matrix/abbreviate_version_number.rb +15 -0
  39. data/lib/pact_broker/client/matrix/resource.rb +26 -1
  40. data/lib/pact_broker/client/matrix/text_formatter.rb +28 -17
  41. data/lib/pact_broker/client/pacticipants.rb +6 -0
  42. data/lib/pact_broker/client/pacticipants/create.rb +24 -34
  43. data/lib/pact_broker/client/pacticipants/describe.rb +33 -0
  44. data/lib/pact_broker/client/pacticipants/list.rb +34 -0
  45. data/lib/pact_broker/client/pacticipants/text_formatter.rb +41 -0
  46. data/lib/pact_broker/client/publish_pacts.rb +7 -3
  47. data/lib/pact_broker/client/string_refinements.rb +56 -0
  48. data/lib/pact_broker/client/version.rb +1 -1
  49. data/lib/pact_broker/client/versions.rb +4 -1
  50. data/lib/pact_broker/client/versions/describe.rb +3 -1
  51. data/lib/pact_broker/client/versions/formatter.rb +3 -1
  52. data/lib/pact_broker/client/versions/json_formatter.rb +5 -3
  53. data/lib/pact_broker/client/versions/text_formatter.rb +3 -1
  54. data/pact-broker-client.gemspec +2 -0
  55. data/script/approve-all.sh +6 -0
  56. data/script/publish-pact.sh +24 -6
  57. data/script/record-deployments-and-releases.sh +10 -0
  58. data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +13 -0
  59. data/spec/fixtures/approvals/describe_environment.approved.txt +7 -0
  60. data/spec/fixtures/approvals/describe_pacticipant.approved.txt +2 -0
  61. data/spec/fixtures/approvals/list_environments.approved.txt +3 -0
  62. data/spec/integration/describe_environment_spec.rb +31 -0
  63. data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +47 -5
  64. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +5 -5
  65. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +1 -1
  66. data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +3 -3
  67. data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +21 -0
  68. data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +204 -0
  69. data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +120 -0
  70. data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +89 -0
  71. data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +167 -0
  72. data/spec/lib/pact_broker/client/generate_display_name_spec.rb +39 -0
  73. data/spec/lib/pact_broker/client/hal/entity_spec.rb +2 -2
  74. data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +2 -2
  75. data/spec/pacts/pact_broker_client-pact_broker.json +88 -287
  76. data/spec/service_providers/create_environment_spec.rb +78 -0
  77. data/spec/service_providers/list_environments_spec.rb +77 -0
  78. data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +98 -0
  79. data/spec/service_providers/pacticipants_create_spec.rb +5 -4
  80. data/spec/service_providers/publish_pacts_spec.rb +5 -2
  81. data/spec/service_providers/record_deployment_spec.rb +17 -36
  82. data/spec/service_providers/record_release_spec.rb +135 -0
  83. data/spec/spec_helper.rb +15 -2
  84. data/spec/support/approvals.rb +26 -0
  85. data/spec/support/shared_context.rb +6 -2
  86. data/tasks/pact.rake +19 -1
  87. metadata +93 -7
  88. data/lib/pact_broker/client/versions/record_deployment.rb +0 -109
  89. data/lib/pact_broker/client/versions/record_undeployment.rb +0 -102
  90. data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +0 -82
@@ -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