pact_broker-client 1.31.0 → 1.36.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 +23 -0
- data/CHANGELOG.md +49 -0
- data/README.md +15 -3
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +151 -8
- data/lib/pact_broker/client/base_client.rb +11 -9
- data/lib/pact_broker/client/cli/broker.rb +31 -5
- data/lib/pact_broker/client/cli/can_i_deploy_long_desc.txt +18 -9
- data/lib/pact_broker/client/git.rb +40 -22
- data/lib/pact_broker/client/matrix.rb +5 -2
- data/lib/pact_broker/client/matrix/text_formatter.rb +44 -11
- data/lib/pact_broker/client/pacts/list_latest_versions.rb +1 -1
- data/lib/pact_broker/client/publish_pacts.rb +92 -14
- data/lib/pact_broker/client/tasks/publication_task.rb +35 -6
- data/lib/pact_broker/client/version.rb +1 -1
- data/pact-broker-client.gemspec +2 -0
- data/script/publish-pact.sh +7 -1
- data/spec/lib/pact_broker/client/base_client_spec.rb +62 -4
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +13 -2
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +108 -12
- data/spec/lib/pact_broker/client/git_spec.rb +39 -2
- data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +29 -4
- data/spec/lib/pact_broker/client/publish_pacts_spec.rb +119 -7
- data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +88 -10
- data/spec/pacts/pact_broker_client-pact_broker.json +154 -8
- 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/support/matrix.json +6 -1
- data/spec/support/matrix.txt +3 -3
- data/spec/support/matrix_error.txt +3 -3
- data/spec/support/matrix_with_results.txt +10 -0
- data/tasks/pact.rake +2 -0
- metadata +36 -4
- data/.travis.yml +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d55a0e281744620059c94153234610bf5368b178eff81765250a1b31b00ef124
|
4
|
+
data.tar.gz: 42edd3c93f27dc59e498e52f36628158ac79bb8d7aa72a4b469ac69ec5734e00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af0ca16aa9d4f2732ac72b42a102d4567d5a0541510967bfa38a4b2d3302f6d40e17f81af6c444cf93c7710edc583da4715f39aebdb736e471d7cc26e67503d6
|
7
|
+
data.tar.gz: e276cb64d985c93dcb55185c6ed9b61fc8c392a90d28cf7fc4b49246f986503005d111c8f0802166364f316bf3bde100d2d71a36f533d899e32c00ff76681542
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on: push
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
runs-on: "ubuntu-latest"
|
8
|
+
continue-on-error: ${{ matrix.experimental }}
|
9
|
+
strategy:
|
10
|
+
fail-fast: false
|
11
|
+
matrix:
|
12
|
+
ruby_version: ["2.2", "2.7"]
|
13
|
+
experimental: [false]
|
14
|
+
include:
|
15
|
+
- ruby_version: "3.0"
|
16
|
+
experimental: true
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v2
|
19
|
+
- uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby_version }}
|
22
|
+
- run: "bundle install"
|
23
|
+
- run: "bundle exec rake"
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,52 @@
|
|
1
|
+
<a name="v1.36.0"></a>
|
2
|
+
### v1.36.0 (2021-02-21)
|
3
|
+
|
4
|
+
#### Features
|
5
|
+
|
6
|
+
* **can-i-deploy**
|
7
|
+
* add --to-environment option ([05ae44c](/../../commit/05ae44c))
|
8
|
+
|
9
|
+
* support version branch and build URL when publishing pacts ([a75f7df](/../../commit/a75f7df))
|
10
|
+
|
11
|
+
<a name="v1.35.0"></a>
|
12
|
+
### v1.35.0 (2021-01-21)
|
13
|
+
|
14
|
+
#### Features
|
15
|
+
|
16
|
+
* **can-i-deploy**
|
17
|
+
* display links to verification results in the output of can-i-deploy when using text format ([976950d](/../../commit/976950d))
|
18
|
+
|
19
|
+
<a name="v1.34.0"></a>
|
20
|
+
### v1.34.0 (2020-11-20)
|
21
|
+
|
22
|
+
#### Features
|
23
|
+
|
24
|
+
* **pact publish**
|
25
|
+
* strip new lines from version numbers and tags ([5842d24](/../../commit/5842d24))
|
26
|
+
|
27
|
+
* **publish**
|
28
|
+
* update output text when pact already exists and merging ([9b849d3](/../../commit/9b849d3))
|
29
|
+
|
30
|
+
<a name="v1.33.0"></a>
|
31
|
+
### v1.33.0 (2020-11-10)
|
32
|
+
|
33
|
+
#### Features
|
34
|
+
|
35
|
+
* **publish**
|
36
|
+
* allow pacts to be merged on the server side ([bd80f10](/../../commit/bd80f10))
|
37
|
+
|
38
|
+
<a name="v1.32.0"></a>
|
39
|
+
### v1.32.0 (2020-10-26)
|
40
|
+
|
41
|
+
#### Features
|
42
|
+
|
43
|
+
* Improve HTTP errors handling (#76) ([d8eaf16](/../../commit/d8eaf16))
|
44
|
+
|
45
|
+
#### Bug Fixes
|
46
|
+
|
47
|
+
* **list-latest-pact-versions**
|
48
|
+
* correct json output ([cf77666](/../../commit/cf77666))
|
49
|
+
|
1
50
|
<a name="v1.31.0"></a>
|
2
51
|
### v1.31.0 (2020-10-22)
|
3
52
|
|
data/README.md
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
A client for the Pact Broker. Publishes and retrieves pacts, verification results, pacticipants, pacticipant versions and tags. The functionality is available via a CLI, or via Ruby Rake tasks. You can also use the [Pact CLI Docker image](https://hub.docker.com/r/pactfoundation/pact-cli).
|
4
4
|
|
5
|
-
|
5
|
+
![Build status](https://github.com/pact-foundation/pact_broker-client/workflows/Test/badge.svg)
|
6
|
+
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/pact_broker-client.svg)](http://badge.fury.io/rb/pact_broker-client)
|
6
8
|
|
7
9
|
![Trigger update to docs.pact.io](https://github.com/pact-foundation/pact_broker-client/workflows/Trigger%20update%20to%20docs.pact.io/badge.svg)
|
8
10
|
|
@@ -16,9 +18,19 @@ Download the latest [pact-ruby-standalone][pact-ruby-standalone] package. You do
|
|
16
18
|
|
17
19
|
Add `gem 'pact_broker-client'` to your Gemfile and run `bundle install`, or install the gem directly by running `gem install pact_broker-client`.
|
18
20
|
|
21
|
+
## Connecting to a Pact Broker with a self signed certificate
|
22
|
+
|
23
|
+
To connect to a Pact Broker that uses custom SSL cerificates, set the environment variable `$SSL_CERT_FILE` or `$SSL_CERT_DIR` to a path that contains the appropriate certificate. Read more at https://docs.pact.io/pact_broker/advanced_topics/using-tls#for-non-jvm
|
24
|
+
|
19
25
|
## Usage - CLI
|
20
26
|
|
21
|
-
|
27
|
+
The Pact Broker base URL can be specified either using the environment variable `$PACT_BROKER_BASE_URL` or the `-b` or `--broker-base-url` parameters.
|
28
|
+
|
29
|
+
Pact Broker authentication can be performed either using basic auth or a bearer token.
|
30
|
+
|
31
|
+
Basic auth parameters can be specified using the `$PACT_BROKER_USERNAME` and `$PACT_BROKER_PASSWORD` environment variables, or the `-u` or `--broker-username` and `-p` or `--broker-password` parameters.
|
32
|
+
|
33
|
+
Authentication using a bearer token can be specified using the environment variable `$PACT_BROKER_TOKEN` or the `-k` or `--broker-token` parameters. This authentication system is used by [Pactflow](pactflow.io).
|
22
34
|
|
23
35
|
### publish
|
24
36
|
|
@@ -188,7 +200,7 @@ Can I deploy all the applications in my monorepo to prod?
|
|
188
200
|
--pacticipant B --version a7e28207 \
|
189
201
|
--pacticipant C --version a7e28207 \
|
190
202
|
--to prod \
|
191
|
-
--broker-base-url BROKER_BASE_URL
|
203
|
+
--broker-base-url BROKER_BASE_URL
|
192
204
|
|
193
205
|
Mobile provider use case - can I deploy version b80e7b1b of Bar, all versions of Foo with tag "prod", and the latest version tagged "prod" of any other automatically calculated dependencies together? (Eg. where Bar is a provider and Foo is a mobile consumer with multiple versions in production, and Bar also has its own providers it needs to be compatible with.)
|
194
206
|
|
@@ -28,6 +28,8 @@
|
|
28
28
|
|
29
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
|
30
30
|
|
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
|
32
|
+
|
31
33
|
* [A request for the index resource with the webhook relation](#a_request_for_the_index_resource_with_the_webhook_relation)
|
32
34
|
|
33
35
|
* [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'_given_a_latest_pact_between_Condor_and_the_Pricing_Service_exists) given a latest pact between Condor and the Pricing Service exists
|
@@ -42,6 +44,10 @@
|
|
42
44
|
|
43
45
|
* [A request to create a pacticipant](#a_request_to_create_a_pacticipant)
|
44
46
|
|
47
|
+
* [A request to create a pacticipant version](#a_request_to_create_a_pacticipant_version_given_version_26f353580936ad3b9baddb17b00e84f33c69e7cb_of_pacticipant_Foo_does_exist) given version 26f353580936ad3b9baddb17b00e84f33c69e7cb of pacticipant Foo does exist
|
48
|
+
|
49
|
+
* [A request to create a pacticipant version](#a_request_to_create_a_pacticipant_version_given_version_26f353580936ad3b9baddb17b00e84f33c69e7cb_of_pacticipant_Foo_does_not_exist) given version 26f353580936ad3b9baddb17b00e84f33c69e7cb of pacticipant Foo does not exist
|
50
|
+
|
45
51
|
* [A request to create a webhook for a consumer and provider](#a_request_to_create_a_webhook_for_a_consumer_and_provider_given_'Condor'_does_not_exist_in_the_pact-broker) given 'Condor' does not exist in the pact-broker
|
46
52
|
|
47
53
|
* [A request to create a webhook with a JSON body and a uuid](#a_request_to_create_a_webhook_with_a_JSON_body_and_a_uuid_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
|
@@ -164,7 +170,12 @@ Pact Broker will respond with:
|
|
164
170
|
},
|
165
171
|
"verificationResult": {
|
166
172
|
"verifiedAt": "2017-10-10T12:49:04+11:00",
|
167
|
-
"success": true
|
173
|
+
"success": true,
|
174
|
+
"_links": {
|
175
|
+
"self": {
|
176
|
+
"href": "http://result"
|
177
|
+
}
|
178
|
+
}
|
168
179
|
},
|
169
180
|
"pact": {
|
170
181
|
"createdAt": "2017-10-10T12:49:04+11:00"
|
@@ -185,7 +196,12 @@ Pact Broker will respond with:
|
|
185
196
|
},
|
186
197
|
"verificationResult": {
|
187
198
|
"verifiedAt": "2017-10-10T12:49:04+11:00",
|
188
|
-
"success": true
|
199
|
+
"success": true,
|
200
|
+
"_links": {
|
201
|
+
"self": {
|
202
|
+
"href": "http://result"
|
203
|
+
}
|
204
|
+
}
|
189
205
|
},
|
190
206
|
"pact": {
|
191
207
|
"createdAt": "2017-10-10T12:49:04+11:00"
|
@@ -233,7 +249,12 @@ Pact Broker will respond with:
|
|
233
249
|
},
|
234
250
|
"verificationResult": {
|
235
251
|
"verifiedAt": "2017-10-10T12:49:04+11:00",
|
236
|
-
"success": true
|
252
|
+
"success": true,
|
253
|
+
"_links": {
|
254
|
+
"self": {
|
255
|
+
"href": "http://result"
|
256
|
+
}
|
257
|
+
}
|
237
258
|
},
|
238
259
|
"pact": {
|
239
260
|
"createdAt": "2017-10-10T12:49:04+11:00"
|
@@ -281,7 +302,12 @@ Pact Broker will respond with:
|
|
281
302
|
},
|
282
303
|
"verificationResult": {
|
283
304
|
"verifiedAt": "2017-10-10T12:49:04+11:00",
|
284
|
-
"success": true
|
305
|
+
"success": true,
|
306
|
+
"_links": {
|
307
|
+
"self": {
|
308
|
+
"href": "http://result"
|
309
|
+
}
|
310
|
+
}
|
285
311
|
},
|
286
312
|
"pact": {
|
287
313
|
"createdAt": "2017-10-10T12:49:04+11:00"
|
@@ -329,7 +355,12 @@ Pact Broker will respond with:
|
|
329
355
|
},
|
330
356
|
"verificationResult": {
|
331
357
|
"verifiedAt": "2017-10-10T12:49:04+11:00",
|
332
|
-
"success": true
|
358
|
+
"success": true,
|
359
|
+
"_links": {
|
360
|
+
"self": {
|
361
|
+
"href": "http://result"
|
362
|
+
}
|
363
|
+
}
|
333
364
|
},
|
334
365
|
"pact": {
|
335
366
|
"createdAt": "2017-10-10T12:49:04+11:00"
|
@@ -413,7 +444,12 @@ Pact Broker will respond with:
|
|
413
444
|
},
|
414
445
|
"verificationResult": {
|
415
446
|
"verifiedAt": "2017-10-10T12:49:04+11:00",
|
416
|
-
"success": true
|
447
|
+
"success": true,
|
448
|
+
"_links": {
|
449
|
+
"self": {
|
450
|
+
"href": "http://result"
|
451
|
+
}
|
452
|
+
}
|
417
453
|
},
|
418
454
|
"pact": {
|
419
455
|
"createdAt": "2017-10-10T12:49:04+11:00"
|
@@ -484,7 +520,12 @@ Pact Broker will respond with:
|
|
484
520
|
},
|
485
521
|
"verificationResult": {
|
486
522
|
"verifiedAt": "2017-10-10T12:49:04+11:00",
|
487
|
-
"success": true
|
523
|
+
"success": true,
|
524
|
+
"_links": {
|
525
|
+
"self": {
|
526
|
+
"href": "http://result"
|
527
|
+
}
|
528
|
+
}
|
488
529
|
},
|
489
530
|
"pact": {
|
490
531
|
"createdAt": "2017-10-10T12:49:04+11:00"
|
@@ -611,6 +652,33 @@ Pact Broker will respond with:
|
|
611
652
|
}
|
612
653
|
}
|
613
654
|
```
|
655
|
+
<a name="a_request_for_the_index_resource_given_the_pb:pacticipant-version_relation_exists_in_the_index_resource"></a>
|
656
|
+
Given **the pb:pacticipant-version relation exists in the index resource**, upon receiving **a request for the index resource** from Pact Broker Client, with
|
657
|
+
```json
|
658
|
+
{
|
659
|
+
"method": "get",
|
660
|
+
"path": "/",
|
661
|
+
"headers": {
|
662
|
+
"Accept": "application/hal+json"
|
663
|
+
}
|
664
|
+
}
|
665
|
+
```
|
666
|
+
Pact Broker will respond with:
|
667
|
+
```json
|
668
|
+
{
|
669
|
+
"status": 200,
|
670
|
+
"headers": {
|
671
|
+
"Content-Type": "application/hal+json;charset=utf-8"
|
672
|
+
},
|
673
|
+
"body": {
|
674
|
+
"_links": {
|
675
|
+
"pb:pacticipant-version": {
|
676
|
+
"href": "http://localhost:1234/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-{pacticipant}-{version}"
|
677
|
+
}
|
678
|
+
}
|
679
|
+
}
|
680
|
+
}
|
681
|
+
```
|
614
682
|
<a name="a_request_for_the_index_resource_with_the_webhook_relation"></a>
|
615
683
|
Upon receiving **a request for the index resource with the webhook relation** from Pact Broker Client, with
|
616
684
|
```json
|
@@ -735,7 +803,12 @@ Pact Broker will respond with:
|
|
735
803
|
},
|
736
804
|
"verificationResult": {
|
737
805
|
"verifiedAt": "2017-10-10T12:49:04+11:00",
|
738
|
-
"success": true
|
806
|
+
"success": true,
|
807
|
+
"_links": {
|
808
|
+
"self": {
|
809
|
+
"href": "http://result"
|
810
|
+
}
|
811
|
+
}
|
739
812
|
},
|
740
813
|
"pact": {
|
741
814
|
"createdAt": "2017-10-10T12:49:04+11:00"
|
@@ -858,6 +931,76 @@ Pact Broker will respond with:
|
|
858
931
|
}
|
859
932
|
}
|
860
933
|
```
|
934
|
+
<a name="a_request_to_create_a_pacticipant_version_given_version_26f353580936ad3b9baddb17b00e84f33c69e7cb_of_pacticipant_Foo_does_exist"></a>
|
935
|
+
Given **version 26f353580936ad3b9baddb17b00e84f33c69e7cb of pacticipant Foo does exist**, upon receiving **a request to create a pacticipant version** from Pact Broker Client, with
|
936
|
+
```json
|
937
|
+
{
|
938
|
+
"method": "put",
|
939
|
+
"path": "/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-Foo-26f353580936ad3b9baddb17b00e84f33c69e7cb",
|
940
|
+
"headers": {
|
941
|
+
"Content-Type": "application/json",
|
942
|
+
"Accept": "application/hal+json"
|
943
|
+
},
|
944
|
+
"body": {
|
945
|
+
"branch": "main",
|
946
|
+
"buildUrl": "http://my-ci/builds/1"
|
947
|
+
}
|
948
|
+
}
|
949
|
+
```
|
950
|
+
Pact Broker will respond with:
|
951
|
+
```json
|
952
|
+
{
|
953
|
+
"status": 200,
|
954
|
+
"headers": {
|
955
|
+
"Content-Type": "application/hal+json;charset=utf-8"
|
956
|
+
},
|
957
|
+
"body": {
|
958
|
+
"number": "26f353580936ad3b9baddb17b00e84f33c69e7cb",
|
959
|
+
"branch": "main",
|
960
|
+
"buildUrl": "http://my-ci/builds/1",
|
961
|
+
"_links": {
|
962
|
+
"self": {
|
963
|
+
"href": "http://localhost:1234/some-url"
|
964
|
+
}
|
965
|
+
}
|
966
|
+
}
|
967
|
+
}
|
968
|
+
```
|
969
|
+
<a name="a_request_to_create_a_pacticipant_version_given_version_26f353580936ad3b9baddb17b00e84f33c69e7cb_of_pacticipant_Foo_does_not_exist"></a>
|
970
|
+
Given **version 26f353580936ad3b9baddb17b00e84f33c69e7cb of pacticipant Foo does not exist**, upon receiving **a request to create a pacticipant version** from Pact Broker Client, with
|
971
|
+
```json
|
972
|
+
{
|
973
|
+
"method": "put",
|
974
|
+
"path": "/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-Foo-26f353580936ad3b9baddb17b00e84f33c69e7cb",
|
975
|
+
"headers": {
|
976
|
+
"Content-Type": "application/json",
|
977
|
+
"Accept": "application/hal+json"
|
978
|
+
},
|
979
|
+
"body": {
|
980
|
+
"branch": "main",
|
981
|
+
"buildUrl": "http://my-ci/builds/1"
|
982
|
+
}
|
983
|
+
}
|
984
|
+
```
|
985
|
+
Pact Broker will respond with:
|
986
|
+
```json
|
987
|
+
{
|
988
|
+
"status": 201,
|
989
|
+
"headers": {
|
990
|
+
"Content-Type": "application/hal+json;charset=utf-8"
|
991
|
+
},
|
992
|
+
"body": {
|
993
|
+
"number": "26f353580936ad3b9baddb17b00e84f33c69e7cb",
|
994
|
+
"branch": "main",
|
995
|
+
"buildUrl": "http://my-ci/builds/1",
|
996
|
+
"_links": {
|
997
|
+
"self": {
|
998
|
+
"href": "http://localhost:1234/some-url"
|
999
|
+
}
|
1000
|
+
}
|
1001
|
+
}
|
1002
|
+
}
|
1003
|
+
```
|
861
1004
|
<a name="a_request_to_create_a_webhook_for_a_consumer_and_provider_given_'Condor'_does_not_exist_in_the_pact-broker"></a>
|
862
1005
|
Given **'Condor' does not exist in the pact-broker**, upon receiving **a request to create a webhook for a consumer and provider** from Pact Broker Client, with
|
863
1006
|
```json
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'erb'
|
2
4
|
require 'httparty'
|
3
5
|
require 'pact_broker/client/error'
|
@@ -30,6 +32,12 @@ module PactBroker
|
|
30
32
|
end
|
31
33
|
|
32
34
|
class BaseClient
|
35
|
+
ERROR_CODE_MAPPING = {
|
36
|
+
401 => "Authentication failed",
|
37
|
+
403 => "Authorization failed (insufficient permissions)",
|
38
|
+
409 => "Potential duplicate pacticipants"
|
39
|
+
}.freeze
|
40
|
+
|
33
41
|
include UrlHelpers
|
34
42
|
include HTTParty
|
35
43
|
include StringToSymbol
|
@@ -69,14 +77,8 @@ module PactBroker
|
|
69
77
|
yield response
|
70
78
|
elsif response.code == 404
|
71
79
|
nil
|
72
|
-
elsif response.code
|
73
|
-
message =
|
74
|
-
if response.body && response.body.size > 0
|
75
|
-
message = message + ": #{response.body}"
|
76
|
-
end
|
77
|
-
raise Error.new(message)
|
78
|
-
elsif response.code == 401
|
79
|
-
message = "Authentication failed"
|
80
|
+
elsif ERROR_CODE_MAPPING.key?(response.code)
|
81
|
+
message = ERROR_CODE_MAPPING.fetch(response.code)
|
80
82
|
if response.body && response.body.size > 0
|
81
83
|
message = message + ": #{response.body}"
|
82
84
|
end
|
@@ -93,7 +95,7 @@ module PactBroker
|
|
93
95
|
response.body
|
94
96
|
end
|
95
97
|
rescue
|
96
|
-
raise Error.new(response.body)
|
98
|
+
raise Error.new("status=#{response.code} #{response.body}")
|
97
99
|
end
|
98
100
|
raise Error.new(error_message)
|
99
101
|
end
|
@@ -18,6 +18,7 @@ module PactBroker
|
|
18
18
|
method_option :version, required: false, aliases: "-e", desc: "The pacticipant version. Must be entered after the --pacticipant that it relates to."
|
19
19
|
method_option :latest, required: false, aliases: "-l", banner: '[TAG]', desc: "Use the latest pacticipant version. Optionally specify a TAG to use the latest version with the specified tag."
|
20
20
|
method_option :to, required: false, banner: 'TAG', desc: "This is too hard to explain in a short sentence. Look at the examples.", default: nil
|
21
|
+
method_option :to_environment, required: false, banner: 'ENVIRONMENT', desc: "The environment into which the pacticipant(s) are to be deployed", default: nil, hide: true
|
21
22
|
method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
|
22
23
|
method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
|
23
24
|
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
|
@@ -37,7 +38,7 @@ module PactBroker
|
|
37
38
|
selectors = VersionSelectorOptionsParser.call(ARGV)
|
38
39
|
validate_can_i_deploy_selectors(selectors)
|
39
40
|
can_i_deploy_options = { output: options.output, retry_while_unknown: options.retry_while_unknown, retry_interval: options.retry_interval }
|
40
|
-
result = CanIDeploy.call(options.broker_base_url, selectors, {to_tag: options.to, limit: options.limit}, can_i_deploy_options, pact_broker_client_options)
|
41
|
+
result = CanIDeploy.call(options.broker_base_url, selectors, { to_tag: options.to, to_environment: options.to_environment, limit: options.limit }, can_i_deploy_options, pact_broker_client_options)
|
41
42
|
$stdout.puts result.message
|
42
43
|
exit(1) unless result.success
|
43
44
|
end
|
@@ -48,8 +49,12 @@ module PactBroker
|
|
48
49
|
method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
|
49
50
|
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
|
50
51
|
method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token"
|
52
|
+
method_option :branch, aliases: "-h", desc: "Repository branch of the consumer version"
|
53
|
+
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."
|
51
54
|
method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for consumer version. Can be specified multiple times."
|
52
55
|
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"
|
56
|
+
method_option :build_url, desc: "The build URL that created the pact"
|
57
|
+
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."
|
53
58
|
method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
|
54
59
|
|
55
60
|
def publish(*pact_files)
|
@@ -209,13 +214,20 @@ module PactBroker
|
|
209
214
|
|
210
215
|
def publish_pacts pact_files
|
211
216
|
require 'pact_broker/client/publish_pacts'
|
217
|
+
write_options = options[:merge] ? { write: :merge } : {}
|
218
|
+
consumer_version_params = {
|
219
|
+
number: options.consumer_app_version,
|
220
|
+
branch: branch,
|
221
|
+
tags: tags,
|
222
|
+
build_url: options.build_url,
|
223
|
+
version_required: (!!options.branch || !!options.build_url || explict_auto_detect_version_properties)
|
224
|
+
}.compact
|
212
225
|
|
213
226
|
PactBroker::Client::PublishPacts.call(
|
214
227
|
options.broker_base_url,
|
215
228
|
file_list(pact_files),
|
216
|
-
|
217
|
-
|
218
|
-
pact_broker_client_options
|
229
|
+
consumer_version_params,
|
230
|
+
pact_broker_client_options.merge(write_options)
|
219
231
|
)
|
220
232
|
end
|
221
233
|
|
@@ -236,10 +248,24 @@ module PactBroker
|
|
236
248
|
require 'pact_broker/client/git'
|
237
249
|
|
238
250
|
t = [*options.tag]
|
239
|
-
t << PactBroker::Client::Git.branch if options.tag_with_git_branch
|
251
|
+
t << PactBroker::Client::Git.branch(raise_error: true) if options.tag_with_git_branch
|
240
252
|
t.compact.uniq
|
241
253
|
end
|
242
254
|
|
255
|
+
def branch
|
256
|
+
require 'pact_broker/client/git'
|
257
|
+
|
258
|
+
if options.branch.nil? && options.auto_detect_version_properties
|
259
|
+
PactBroker::Client::Git.branch(raise_error: explict_auto_detect_version_properties)
|
260
|
+
else
|
261
|
+
options.branch
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def explict_auto_detect_version_properties
|
266
|
+
@explict_auto_detect_version_properties ||= ARGV.include?("--auto-detect-version-properties")
|
267
|
+
end
|
268
|
+
|
243
269
|
def pact_broker_client_options
|
244
270
|
client_options = { verbose: options.verbose }
|
245
271
|
client_options[:token] = options.broker_token if options.broker_token
|