pact_broker-client 1.38.2 → 1.42.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +47 -0
  4. data/Gemfile +4 -0
  5. data/README.md +18 -0
  6. data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +61 -140
  7. data/example/scripts/publish-pact.sh +1 -1
  8. data/lib/pact_broker/client/backports.rb +9 -0
  9. data/lib/pact_broker/client/base_client.rb +1 -1
  10. data/lib/pact_broker/client/base_command.rb +95 -0
  11. data/lib/pact_broker/client/can_i_deploy.rb +20 -3
  12. data/lib/pact_broker/client/cli/broker.rb +44 -28
  13. data/lib/pact_broker/client/cli/custom_thor.rb +12 -0
  14. data/lib/pact_broker/client/cli/environment_commands.rb +70 -0
  15. data/lib/pact_broker/client/cli/pacticipant_commands.rb +44 -0
  16. data/lib/pact_broker/client/cli/record_deployment_long_desc.txt +0 -0
  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/environments.rb +3 -0
  20. data/lib/pact_broker/client/environments/create_environment.rb +31 -0
  21. data/lib/pact_broker/client/environments/delete_environment.rb +27 -0
  22. data/lib/pact_broker/client/environments/describe_environment.rb +36 -0
  23. data/lib/pact_broker/client/environments/environment_command.rb +66 -0
  24. data/lib/pact_broker/client/environments/list_environments.rb +30 -0
  25. data/lib/pact_broker/client/environments/text_formatter.rb +30 -0
  26. data/lib/pact_broker/client/environments/update_environment.rb +31 -0
  27. data/lib/pact_broker/client/generate_display_name.rb +27 -0
  28. data/lib/pact_broker/client/hal/entity.rb +26 -3
  29. data/lib/pact_broker/client/hal/http_client.rb +11 -2
  30. data/lib/pact_broker/client/hal/link.rb +20 -0
  31. data/lib/pact_broker/client/hal/links.rb +15 -0
  32. data/lib/pact_broker/client/hal_client_methods.rb +9 -3
  33. data/lib/pact_broker/client/matrix.rb +4 -0
  34. data/lib/pact_broker/client/matrix/abbreviate_version_number.rb +15 -0
  35. data/lib/pact_broker/client/matrix/resource.rb +26 -1
  36. data/lib/pact_broker/client/matrix/text_formatter.rb +28 -17
  37. data/lib/pact_broker/client/pacticipants.rb +6 -0
  38. data/lib/pact_broker/client/pacticipants/create.rb +24 -34
  39. data/lib/pact_broker/client/pacticipants/list.rb +34 -0
  40. data/lib/pact_broker/client/pacticipants/text_formatter.rb +41 -0
  41. data/lib/pact_broker/client/pacts.rb +0 -1
  42. data/lib/pact_broker/client/publish_pacts.rb +94 -128
  43. data/lib/pact_broker/client/publish_pacts_the_old_way.rb +194 -0
  44. data/lib/pact_broker/client/string_refinements.rb +56 -0
  45. data/lib/pact_broker/client/tasks/publication_task.rb +3 -3
  46. data/lib/pact_broker/client/version.rb +1 -1
  47. data/lib/pact_broker/client/versions/record_deployment.rb +6 -6
  48. data/lib/pact_broker/client/versions/record_undeployment.rb +45 -68
  49. data/pact-broker-client.gemspec +2 -0
  50. data/script/approve-all.sh +6 -0
  51. data/script/publish-pact.sh +36 -5
  52. data/script/record-deployment.sh +1 -3
  53. data/script/record-undeployment.sh +4 -0
  54. data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +13 -0
  55. data/spec/fixtures/approvals/describe_environment.approved.txt +7 -0
  56. data/spec/fixtures/approvals/list_environments.approved.txt +3 -0
  57. data/spec/fixtures/foo-bar.json +31 -0
  58. data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +47 -5
  59. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +5 -5
  60. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +36 -7
  61. data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +3 -3
  62. data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +21 -0
  63. data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +120 -0
  64. data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +89 -0
  65. data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +167 -0
  66. data/spec/lib/pact_broker/client/generate_display_name_spec.rb +39 -0
  67. data/spec/lib/pact_broker/client/hal/entity_spec.rb +2 -2
  68. data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +5 -2
  69. data/spec/lib/pact_broker/client/{publish_pacts_spec.rb → publish_pacts_the_old_way_spec.rb} +10 -9
  70. data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +18 -12
  71. data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +5 -5
  72. data/spec/pacts/pact_broker_client-pact_broker.json +50 -124
  73. data/spec/service_providers/create_environment_spec.rb +78 -0
  74. data/spec/service_providers/list_environments_spec.rb +77 -0
  75. data/spec/service_providers/pact_broker_client_create_version_spec.rb +4 -4
  76. data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +98 -0
  77. data/spec/service_providers/pacticipants_create_spec.rb +5 -4
  78. data/spec/service_providers/publish_pacts_spec.rb +116 -0
  79. data/spec/service_providers/record_deployment_spec.rb +6 -7
  80. data/spec/spec_helper.rb +3 -1
  81. data/spec/support/approvals.rb +26 -0
  82. data/spec/support/shared_context.rb +6 -2
  83. metadata +86 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 134d7fe9f87596c2b56d1edfb136bdff06c045cf1f6e2ef8a3f93b805d3e108d
4
- data.tar.gz: 57acfb55120c41e97ec1397dceebdd6f9784b9a3ff50c47c6464735c11c6e5a1
3
+ metadata.gz: 1da6a5e8cef3f91ae1cd441eb92dd2d788ad67ccac947c476090787b27b134ea
4
+ data.tar.gz: 0df7d512c7c45a8b7ea4d049560be927d1d7c3273c0ec157c22cb81651caa16e
5
5
  SHA512:
6
- metadata.gz: 235afd0d61e101c549795f7dec7ea22f7d282456d59e72d8f49d7b383e358742e75f6eb866154f99af21b73a34671af6bfc6337fd72fc08b44049d47daeef2f9
7
- data.tar.gz: 23e3aa5306ce014268b287d7de00b200476cea6f7711821ee5dac95586a3d8ccd1f9152959409209349b0a9a3cc77febcba26d6c90be7b7aa165ef2a3ceb3b22
6
+ metadata.gz: 27dc97ff230f86c530b8aed93cf5e86334dd51982017627a7c99de57a2cf8f65af6706c5a73c5d1999df0b145b60b88a649b716fc7f859cbc289193f9dbca437
7
+ data.tar.gz: 1f970d5b863efc1bc27c55515b95afe8c4a3e166e3da62819ac92e1d4f6205fccb7f8979925266dc37342c1be496310c59a150408398e000b5e8e8b2079ab609
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
5
+ .approvals
5
6
  coverage
6
7
  InstalledFiles
7
8
  lib/bundler/man
data/CHANGELOG.md CHANGED
@@ -1,3 +1,50 @@
1
+ <a name="v1.42.0"></a>
2
+ ### v1.42.0 (2021-05-31)
3
+
4
+ #### Features
5
+
6
+ * add list-pacticipants ([fc8ce3b](/../../commit/fc8ce3b))
7
+ * add --display-name to create-or-update-pacticipant ([76f323b](/../../commit/76f323b))
8
+ * add backtrace to error output when verbose is true ([abf1ef0](/../../commit/abf1ef0))
9
+ * add list-environments and describe-environment ([4472d48](/../../commit/4472d48))
10
+ * add delete-environment ([361eed1](/../../commit/361eed1))
11
+ * add update-environment command ([95276cd](/../../commit/95276cd))
12
+ * add create-environment command ([a9fab50](/../../commit/a9fab50))
13
+
14
+ #### Bug Fixes
15
+
16
+ * stop long values in columns from being truncated ([18063fd](/../../commit/18063fd))
17
+
18
+ <a name="v1.41.0"></a>
19
+ ### v1.41.0 (2021-05-25)
20
+
21
+ #### Features
22
+
23
+ * update colours of pact publish output ([2a51e37](/../../commit/2a51e37))
24
+
25
+ <a name="v1.40.0"></a>
26
+ ### v1.40.0 (2021-04-26)
27
+
28
+ #### Features
29
+
30
+ * use the pb:publish-contracts relation and endpoint to publish pacts ([19f1b0b](/../../commit/19f1b0b))
31
+ * update publish pacts command to use new 'all in one' contract publishing endpoint ([50dfb11](/../../commit/50dfb11))
32
+
33
+ <a name="v1.39.0"></a>
34
+ ### v1.39.0 (2021-04-27)
35
+
36
+ #### Features
37
+
38
+ * publish pacts using the "all in one" endpoint (#86) ([3a1ea22](/../../commit/3a1ea22))
39
+ * provide a more helpful error message when the specified pact file does not exist ([29a7962](/../../commit/29a7962))
40
+
41
+ <a name="v1.38.3"></a>
42
+ ### v1.38.3 (2021-04-08)
43
+
44
+ #### Bug Fixes
45
+
46
+ * URL encode parameters for HAL templated URLs ([764a0fa](/../../commit/764a0fa))
47
+
1
48
  <a name="v1.38.2"></a>
2
49
  ### v1.38.2 (2021-04-01)
3
50
 
data/Gemfile CHANGED
@@ -10,3 +10,7 @@ if ENV['X_PACT_DEVELOPMENT'] == 'true'
10
10
  gem 'pact-mock_service', path: '../pact-mock_service'
11
11
  gem 'pact-support', path: '../pact-support'
12
12
  end
13
+
14
+ group :development do
15
+ gem 'pry-byebug'
16
+ end
data/README.md CHANGED
@@ -309,6 +309,24 @@ Description:
309
309
  the `generate-uuid` command.
310
310
  ```
311
311
 
312
+ ### create-or-update-pacticipant
313
+
314
+ ```
315
+ Usage:
316
+ pact-broker create-or-update-pacticipant --name=NAME -b, --broker-base-url=BROKER_BASE_URL
317
+
318
+ Options:
319
+ --name=NAME # Pacticipant name
320
+ [--repository-url=REPOSITORY_URL] # The repository URL of the pacticipant
321
+ -b, --broker-base-url=BROKER_BASE_URL # The base URL of the Pact Broker
322
+ -u, [--broker-username=BROKER_USERNAME] # Pact Broker basic auth username
323
+ -p, [--broker-password=BROKER_PASSWORD] # Pact Broker basic auth password
324
+ -k, [--broker-token=BROKER_TOKEN] # Pact Broker bearer token
325
+ -v, [--verbose], [--no-verbose] # Verbose output. Default: false
326
+
327
+ Create or update pacticipant by name
328
+ ```
329
+
312
330
  ### describe-version
313
331
 
314
332
  ```
@@ -2,12 +2,6 @@
2
2
 
3
3
  #### Requests from Pact Broker Client to Pact Broker
4
4
 
5
- * [A request for a pacticipant version](#a_request_for_a_pacticipant_version_given_version_5556b8149bf8bac76bc30f50a8a2dd4c22c85f30_of_pacticipant_Foo_exists_with_2_environments_that_aren&#39;t_test_available_for_deployment) given version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with 2 environments that aren't test available for deployment
6
-
7
- * [A request for a pacticipant version](#a_request_for_a_pacticipant_version_given_version_5556b8149bf8bac76bc30f50a8a2dd4c22c85f30_of_pacticipant_Foo_exists_with_a_test_environment_available_for_deployment) given version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment
8
-
9
- * [A request for a pacticipant version](#a_request_for_a_pacticipant_version_given_version_5556b8149bf8bac76bc30f50a8a2dd4c22c85f30_of_pacticipant_Foo_does_not_exist) given version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo does not exist
10
-
11
5
  * [A request for the compatibility matrix for a pacticipant that does not exist](#a_request_for_the_compatibility_matrix_for_a_pacticipant_that_does_not_exist)
12
6
 
13
7
  * [A request for the compatibility matrix for all versions of Foo and Bar](#a_request_for_the_compatibility_matrix_for_all_versions_of_Foo_and_Bar_given_the_pact_for_Foo_version_1.2.3_and_1.2.4_has_been_verified_by_Bar_version_4.5.6) given the pact for Foo version 1.2.3 and 1.2.4 has been verified by Bar version 4.5.6
@@ -26,8 +20,6 @@
26
20
 
27
21
  * [A request for the compatibility matrix where only the version of Foo is specified](#a_request_for_the_compatibility_matrix_where_only_the_version_of_Foo_is_specified_given_the_pact_for_Foo_version_1.2.3_has_been_verified_by_Bar_version_4.5.6_and_version_5.6.7) given the pact for Foo version 1.2.3 has been verified by Bar version 4.5.6 and version 5.6.7
28
22
 
29
- * [A request for the environments](#a_request_for_the_environments_given_an_environment_with_name_test_exists) given an environment with name test exists
30
-
31
23
  * [A request for the index resource](#a_request_for_the_index_resource)
32
24
 
33
25
  * [A request for the index resource](#a_request_for_the_index_resource_given_the_pacticipant_relations_are_present) given the pacticipant relations are present
@@ -36,10 +28,10 @@
36
28
 
37
29
  * [A request for the index resource](#a_request_for_the_index_resource_given_the_pb:latest-version_relation_exists_in_the_index_resource) given the pb:latest-version relation exists in the index resource
38
30
 
39
- * [A request for the index resource](#a_request_for_the_index_resource_given_the_pb:pacticipant-version_and_pb:environments_relations_exist_in_the_index_resource) given the pb:pacticipant-version and pb:environments relations exist in the index resource
40
-
41
31
  * [A request for the index resource](#a_request_for_the_index_resource_given_the_pb:pacticipant-version_relation_exists_in_the_index_resource) given the pb:pacticipant-version relation exists in the index resource
42
32
 
33
+ * [A request for the index resource](#a_request_for_the_index_resource_given_the_pb:publish-contracts_relations_exists_in_the_index_resource) given the pb:publish-contracts relations exists in the index resource
34
+
43
35
  * [A request for the index resource with the webhook relation](#a_request_for_the_index_resource_with_the_webhook_relation)
44
36
 
45
37
  * [A request for the list of the latest pacts from all consumers for the Pricing Service'](#a_request_for_the_list_of_the_latest_pacts_from_all_consumers_for_the_Pricing_Service&#39;_given_a_latest_pact_between_Condor_and_the_Pricing_Service_exists) given a latest pact between Condor and the Pricing Service exists
@@ -92,7 +84,7 @@
92
84
 
93
85
  * [A request to publish a pact with method put](#a_request_to_publish_a_pact_with_method_put_given_the_&#39;Pricing_Service&#39;_and_&#39;Condor&#39;_already_exist_in_the_pact-broker,_and_Condor_already_has_a_pact_published_for_version_1.3.0) given the 'Pricing Service' and 'Condor' already exist in the pact-broker, and Condor already has a pact published for version 1.3.0
94
86
 
95
- * [A request to record a deployment](#a_request_to_record_a_deployment_given_version_5556b8149bf8bac76bc30f50a8a2dd4c22c85f30_of_pacticipant_Foo_exists_with_a_test_environment_available_for_deployment) given version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment
87
+ * [A request to publish contracts](#a_request_to_publish_contracts)
96
88
 
97
89
  * [A request to register the repository URL of a pacticipant](#a_request_to_register_the_repository_URL_of_a_pacticipant_given_the_&#39;Pricing_Service&#39;_already_exists_in_the_pact-broker) given the 'Pricing Service' already exists in the pact-broker
98
90
 
@@ -126,87 +118,6 @@
126
118
 
127
119
  #### Interactions
128
120
 
129
- <a name="a_request_for_a_pacticipant_version_given_version_5556b8149bf8bac76bc30f50a8a2dd4c22c85f30_of_pacticipant_Foo_exists_with_2_environments_that_aren&#39;t_test_available_for_deployment"></a>
130
- Given **version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with 2 environments that aren't test available for deployment**, upon receiving **a request for a pacticipant version** from Pact Broker Client, with
131
- ```json
132
- {
133
- "method": "GET",
134
- "path": "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
135
- "headers": {
136
- "Accept": "application/hal+json"
137
- }
138
- }
139
- ```
140
- Pact Broker will respond with:
141
- ```json
142
- {
143
- "status": 200,
144
- "headers": {
145
- "Content-Type": "application/hal+json;charset=utf-8"
146
- },
147
- "body": {
148
- "_links": {
149
- "pb:record-deployment": [
150
- {
151
- "name": "prod",
152
- "href": "href"
153
- },
154
- {
155
- "name": "dev",
156
- "href": "href"
157
- }
158
- ]
159
- }
160
- }
161
- }
162
- ```
163
- <a name="a_request_for_a_pacticipant_version_given_version_5556b8149bf8bac76bc30f50a8a2dd4c22c85f30_of_pacticipant_Foo_exists_with_a_test_environment_available_for_deployment"></a>
164
- Given **version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment**, upon receiving **a request for a pacticipant version** from Pact Broker Client, with
165
- ```json
166
- {
167
- "method": "GET",
168
- "path": "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
169
- "headers": {
170
- "Accept": "application/hal+json"
171
- }
172
- }
173
- ```
174
- Pact Broker will respond with:
175
- ```json
176
- {
177
- "status": 200,
178
- "headers": {
179
- "Content-Type": "application/hal+json;charset=utf-8"
180
- },
181
- "body": {
182
- "_links": {
183
- "pb:record-deployment": [
184
- {
185
- "name": "test",
186
- "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-RECORD-DEPLOYMENT-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST"
187
- }
188
- ]
189
- }
190
- }
191
- }
192
- ```
193
- <a name="a_request_for_a_pacticipant_version_given_version_5556b8149bf8bac76bc30f50a8a2dd4c22c85f30_of_pacticipant_Foo_does_not_exist"></a>
194
- Given **version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo does not exist**, upon receiving **a request for a pacticipant version** from Pact Broker Client, with
195
- ```json
196
- {
197
- "method": "GET",
198
- "path": "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
199
- "headers": {
200
- "Accept": "application/hal+json"
201
- }
202
- }
203
- ```
204
- Pact Broker will respond with:
205
- ```json
206
- {
207
- "status": 404
208
- }
209
- ```
210
121
  <a name="a_request_for_the_compatibility_matrix_for_a_pacticipant_that_does_not_exist"></a>
211
122
  Upon receiving **a request for the compatibility matrix for a pacticipant that does not exist** from Pact Broker Client, with
212
123
  ```json
@@ -628,36 +539,6 @@ Pact Broker will respond with:
628
539
  }
629
540
  }
630
541
  ```
631
- <a name="a_request_for_the_environments_given_an_environment_with_name_test_exists"></a>
632
- Given **an environment with name test exists**, upon receiving **a request for the environments** from Pact Broker Client, with
633
- ```json
634
- {
635
- "method": "GET",
636
- "path": "/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS",
637
- "headers": {
638
- "Accept": "application/hal+json"
639
- }
640
- }
641
- ```
642
- Pact Broker will respond with:
643
- ```json
644
- {
645
- "status": 200,
646
- "headers": {
647
- "Content-Type": "application/hal+json;charset=utf-8"
648
- },
649
- "body": {
650
- "_links": {
651
- "pb:environments": [
652
- {
653
- "name": "test",
654
- "href": "href"
655
- }
656
- ]
657
- }
658
- }
659
- }
660
- ```
661
542
  <a name="a_request_for_the_index_resource"></a>
662
543
  Upon receiving **a request for the index resource** from Pact Broker Client, with
663
544
  ```json
@@ -775,11 +656,11 @@ Pact Broker will respond with:
775
656
  }
776
657
  }
777
658
  ```
778
- <a name="a_request_for_the_index_resource_given_the_pb:pacticipant-version_and_pb:environments_relations_exist_in_the_index_resource"></a>
779
- Given **the pb:pacticipant-version and pb:environments relations exist in the index resource**, upon receiving **a request for the index resource** from Pact Broker Client, with
659
+ <a name="a_request_for_the_index_resource_given_the_pb:pacticipant-version_relation_exists_in_the_index_resource"></a>
660
+ Given **the pb:pacticipant-version relation exists in the index resource**, upon receiving **a request for the index resource** from Pact Broker Client, with
780
661
  ```json
781
662
  {
782
- "method": "GET",
663
+ "method": "get",
783
664
  "path": "/",
784
665
  "headers": {
785
666
  "Accept": "application/hal+json"
@@ -796,20 +677,17 @@ Pact Broker will respond with:
796
677
  "body": {
797
678
  "_links": {
798
679
  "pb:pacticipant-version": {
799
- "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-{pacticipant}-{version}"
800
- },
801
- "pb:environments": {
802
- "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS"
680
+ "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-{pacticipant}-{version}"
803
681
  }
804
682
  }
805
683
  }
806
684
  }
807
685
  ```
808
- <a name="a_request_for_the_index_resource_given_the_pb:pacticipant-version_relation_exists_in_the_index_resource"></a>
809
- Given **the pb:pacticipant-version relation exists in the index resource**, upon receiving **a request for the index resource** from Pact Broker Client, with
686
+ <a name="a_request_for_the_index_resource_given_the_pb:publish-contracts_relations_exists_in_the_index_resource"></a>
687
+ Given **the pb:publish-contracts relations exists in the index resource**, upon receiving **a request for the index resource** from Pact Broker Client, with
810
688
  ```json
811
689
  {
812
- "method": "get",
690
+ "method": "GET",
813
691
  "path": "/",
814
692
  "headers": {
815
693
  "Accept": "application/hal+json"
@@ -825,8 +703,8 @@ Pact Broker will respond with:
825
703
  },
826
704
  "body": {
827
705
  "_links": {
828
- "pb:pacticipant-version": {
829
- "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-{pacticipant}-{version}"
706
+ "pb:publish-contracts": {
707
+ "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-PUBLISH-CONTRACTS"
830
708
  }
831
709
  }
832
710
  }
@@ -1928,30 +1806,73 @@ Pact Broker will respond with:
1928
1806
  }
1929
1807
  }
1930
1808
  ```
1931
- <a name="a_request_to_record_a_deployment_given_version_5556b8149bf8bac76bc30f50a8a2dd4c22c85f30_of_pacticipant_Foo_exists_with_a_test_environment_available_for_deployment"></a>
1932
- Given **version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment**, upon receiving **a request to record a deployment** from Pact Broker Client, with
1809
+ <a name="a_request_to_publish_contracts"></a>
1810
+ Upon receiving **a request to publish contracts** from Pact Broker Client, with
1933
1811
  ```json
1934
1812
  {
1935
1813
  "method": "POST",
1936
- "path": "/HAL-REL-PLACEHOLDER-PB-RECORD-DEPLOYMENT-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST",
1814
+ "path": "/HAL-REL-PLACEHOLDER-PB-PUBLISH-CONTRACTS",
1937
1815
  "headers": {
1938
1816
  "Content-Type": "application/json",
1939
1817
  "Accept": "application/hal+json"
1940
1818
  },
1941
1819
  "body": {
1942
- "replacedPreviousDeployedVersion": true
1820
+ "pacticipantName": "Foo",
1821
+ "pacticipantVersionNumber": "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
1822
+ "branch": "main",
1823
+ "tags": [
1824
+ "dev"
1825
+ ],
1826
+ "buildUrl": "http://build",
1827
+ "contracts": [
1828
+ {
1829
+ "consumerName": "Foo",
1830
+ "providerName": "Bar",
1831
+ "specification": "pact",
1832
+ "contentType": "application/json",
1833
+ "content": "eyJjb25zdW1lciI6eyJuYW1lIjoiRm9vIn0sInByb3ZpZGVyIjp7Im5hbWUiOiJCYXIifSwiaW50ZXJhY3Rpb25zIjpbeyJkZXNjcmlwdGlvbiI6ImFuIGV4YW1wbGUgcmVxdWVzdCIsInByb3ZpZGVyU3RhdGUiOiJhIHByb3ZpZGVyIHN0YXRlIiwicmVxdWVzdCI6eyJtZXRob2QiOiJHRVQiLCJwYXRoIjoiLyIsImhlYWRlcnMiOnt9fSwicmVzcG9uc2UiOnsic3RhdHVzIjoyMDAsImhlYWRlcnMiOnsiQ29udGVudC1UeXBlIjoiYXBwbGljYXRpb24vaGFsK2pzb24ifX19XSwibWV0YWRhdGEiOnsicGFjdFNwZWNpZmljYXRpb24iOnsidmVyc2lvbiI6IjIuMC4wIn19fQ==",
1834
+ "writeMode": "overwrite",
1835
+ "onConflict": "overwrite"
1836
+ }
1837
+ ]
1943
1838
  }
1944
1839
  }
1945
1840
  ```
1946
1841
  Pact Broker will respond with:
1947
1842
  ```json
1948
1843
  {
1949
- "status": 201,
1844
+ "status": 200,
1950
1845
  "headers": {
1951
1846
  "Content-Type": "application/hal+json;charset=utf-8"
1952
1847
  },
1953
1848
  "body": {
1954
- "replacedPreviousDeployedVersion": true
1849
+ "_embedded": {
1850
+ "pacticipant": {
1851
+ "name": "Foo"
1852
+ },
1853
+ "version": {
1854
+ "number": "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
1855
+ "buildUrl": "http://build"
1856
+ }
1857
+ },
1858
+ "logs": [
1859
+ {
1860
+ "level": "info",
1861
+ "message": "some message"
1862
+ }
1863
+ ],
1864
+ "_links": {
1865
+ "pb:pacticipant-version-tags": [
1866
+ {
1867
+ "name": "dev"
1868
+ }
1869
+ ],
1870
+ "pb:contracts": [
1871
+ {
1872
+ "href": "http://some-pact"
1873
+ }
1874
+ ]
1875
+ }
1955
1876
  }
1956
1877
  }
1957
1878
  ```
@@ -1,3 +1,3 @@
1
1
  # assumes you've set PACT_BROKER_BASE_URL, PACT_BROKER_USERNAME and PACT_BROKER_PASSWORD already
2
2
 
3
- bundle exec bin/pact-broker publish $(dirname "$0")/pact.json --consumer-app-version=1.0.0 --tag master
3
+ bundle exec bin/pact-broker publish $(dirname "$0")/pact.json --consumer-app-version=1.0.0 --tag master --verbose
@@ -10,4 +10,13 @@ class Hash
10
10
  def compact!
11
11
  reject! {|_key, value| value == nil}
12
12
  end unless method_defined? :compact!
13
+
14
+ def except(*keys)
15
+ if keys.size > 4 && size > 4 # index if O(m*n) is big
16
+ h = {}
17
+ keys.each { |key| h[key] = true }
18
+ keys = h
19
+ end
20
+ reject { |key, _value| keys.include? key}
21
+ end unless method_defined? :except
13
22
  end
@@ -119,7 +119,7 @@ module PactBroker
119
119
  if relation
120
120
  url = relation['href']
121
121
  params.each do | (key, value) |
122
- url = url.gsub("{#{key}}", value)
122
+ url = url.gsub("{#{key}}", encode_param(value))
123
123
  end
124
124
  url
125
125
  else
@@ -0,0 +1,95 @@
1
+ require 'pact_broker/client/hal_client_methods'
2
+ require 'pact_broker/client/error'
3
+ require 'pact_broker/client/command_result'
4
+ require 'term/ansicolor'
5
+ require 'pact_broker/client/backports'
6
+
7
+ module PactBroker
8
+ module Client
9
+ class BaseCommand
10
+ include PactBroker::Client::HalClientMethods
11
+
12
+ def self.call(params, options, pact_broker_client_options)
13
+ new(params, options, pact_broker_client_options).call
14
+ end
15
+
16
+ def initialize(params, options, pact_broker_client_options)
17
+ @params = params
18
+ @options = options
19
+ @pact_broker_base_url = pact_broker_client_options.fetch(:pact_broker_base_url)
20
+ @pact_broker_client_options = pact_broker_client_options
21
+ end
22
+
23
+ def call
24
+ check_if_command_supported
25
+ do_call
26
+ rescue PactBroker::Client::Hal::ErrorResponseReturned => e
27
+ handle_http_error(e)
28
+ rescue PactBroker::Client::Error => e
29
+ handle_ruby_error(e)
30
+ rescue StandardError => e
31
+ handle_ruby_error(e, verbose?)
32
+ end
33
+
34
+ private
35
+
36
+ attr_reader :params, :options
37
+ attr_reader :pact_broker_base_url, :pact_broker_client_options
38
+
39
+ def handle_http_error(e)
40
+ message = if json_output?
41
+ body = e.entity.response.raw_body
42
+ (body.nil? || body == "") ? "{}" : body
43
+ else
44
+ red(e.message)
45
+ end
46
+ PactBroker::Client::CommandResult.new(false, message)
47
+ end
48
+
49
+ def handle_ruby_error(e, include_backtrace = false)
50
+ PactBroker::Client::CommandResult.new(false, error_message(e, include_backtrace))
51
+ end
52
+
53
+ def error_message(e, include_backtrace)
54
+ if json_output?
55
+ json_error_message(e, include_backtrace)
56
+ else
57
+ text_error_message(e, include_backtrace)
58
+ end
59
+ end
60
+
61
+ def json_error_message(e, include_backtrace)
62
+ error_hash = { message: e.message }
63
+ error_hash[:class] = e.class.name unless e.is_a?(PactBroker::Client::Error)
64
+ error_hash[:backtrace] = e.backtrace if include_backtrace
65
+ { error: error_hash }.to_json
66
+ end
67
+
68
+
69
+ def text_error_message(e, include_backtrace)
70
+ maybe_backtrace = (include_backtrace ? "\n" + e.backtrace.join("\n") : "")
71
+ exception_message = e.is_a?(PactBroker::Client::Error) ? e.message : "#{e.class} - #{e.message}"
72
+ red(exception_message) + maybe_backtrace
73
+ end
74
+
75
+ def check_if_command_supported
76
+ end
77
+
78
+ def json_output?
79
+ options[:output] == "json"
80
+ end
81
+
82
+ def verbose?
83
+ options[:verbose]
84
+ end
85
+
86
+ def green(text)
87
+ ::Term::ANSIColor.green(text)
88
+ end
89
+
90
+ def red(text)
91
+ ::Term::ANSIColor.red(text)
92
+ end
93
+ end
94
+ end
95
+ end