pact_broker-client 1.70.0 → 1.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c39e09b6dd262ec6baa6da53747ac6adfcac1b83e87050973d10624d6d0dbc85
4
- data.tar.gz: 817e36de371bb43762e42c8103735f291a1645a782541581cbff501a70b309da
3
+ metadata.gz: 95192c76cf2b56651bb52de5cd2c5f1bea45d966e5dfa4e8ef78d1e11a3a2a51
4
+ data.tar.gz: 1a095144bc411e428556f47da77160d5c7a182e4eb2201d75f30075adb1cb009
5
5
  SHA512:
6
- metadata.gz: 68d61e0fef6e96bd4acce08bc781aee2895b209cecbb0e3f453fe8e7e3843f417e5f3f62604dfda8ed5bee803c382c49eb552d17cc5fe06101fcab9848e1e34e
7
- data.tar.gz: bf36dbe78ff7fdd10af8983be7130928389175c8b6770ee1772f9a31ccac6920d6316890850d33d8c179a8e9ce3dd1467338810e2879dd71079c751bc2e117a4
6
+ metadata.gz: 3553d23ad0bdae6e6f460a6a85dd3ab46789bf3cfe6241881c1f126642b73cf6ee9714f60e830c7108f8e0a0a188a7a2a6b1a42dda55be7ae2339b9ccfd3552b
7
+ data.tar.gz: 3c039eb65e3f4f02c9f32ebf52936535ccb125e8105c4b1681aeafa90de007c7dc032824d20facf6e023c61e3b32147e188312b8a8244b506627fe69e8f414c0
@@ -12,8 +12,6 @@ jobs:
12
12
  steps:
13
13
  - uses: actions/checkout@v3
14
14
  - uses: ruby/setup-ruby@v1
15
- with:
16
- ruby-version: '3.2'
17
15
  - run: |
18
16
  gem install bundler -v 2.4
19
17
  bundle install
@@ -38,6 +36,23 @@ jobs:
38
36
  GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
39
37
  INCREMENT: '${{ github.event.client_payload.increment }}'
40
38
 
39
+ record-release:
40
+ needs: release
41
+ runs-on: ubuntu-latest
42
+ steps:
43
+ - uses: actions/checkout@v3
44
+ - uses: ruby/setup-ruby@v1
45
+ - name: Bundle install
46
+ run: |
47
+ gem install bundler -v 2.4
48
+ bundle config set --local without development test
49
+ bundle install
50
+ - name: Record release
51
+ run: script/ci/record-release.sh
52
+ env:
53
+ PACT_BROKER_BASE_URL: https://pact-foundation.pactflow.io
54
+ PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN_PACT_FOUNDATION }}
55
+
41
56
  notify-gem-released:
42
57
  needs: release
43
58
  strategy:
@@ -30,12 +30,15 @@ jobs:
30
30
  with:
31
31
  ruby-version: "3.2"
32
32
  - run: "bundle install"
33
+ # Publish to old and new account until we can disable the old account
33
34
  - run: |
34
35
  rm -rf spec/pacts/*
35
36
  bundle exec rspec spec/service_providers/
36
- VERBOSE=true bundle exec rake pact:publish:pactflow
37
+ VERBOSE=true bundle exec rake pact:publish:pactflow_oss
38
+ VERBOSE=true bundle exec rake pact:publish:pactflow_pact_foundation
37
39
  env:
38
40
  PACT_BROKER_TOKEN: ${{ secrets.PACTFLOW_PACT_OSS_TOKEN }}
41
+ PACT_BROKER_TOKEN_PACT_FOUNDATION: ${{ secrets.PACT_BROKER_TOKEN_PACT_FOUNDATION }}
39
42
  PACT_BROKER_FEATURES: ${{ matrix.feature }}
40
43
  TEST_FEATURE: ${{ matrix.feature }}
41
44
  can-i-deploy:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ <a name="v1.72.0"></a>
2
+ ### v1.72.0 (2023-09-11)
3
+
4
+ #### Features
5
+
6
+ * enable publishing provider contracts using the 'all in one' endpoint ([398d58c](/../../commit/398d58c))
7
+
8
+ <a name="v1.71.0"></a>
9
+ ### v1.71.0 (2023-09-07)
10
+
11
+ #### Features
12
+
13
+ * publish provider contracts using all in one endpoint (#141) ([a9f87a8](/../../commit/a9f87a8))
14
+
1
15
  <a name="v1.70.0"></a>
2
16
  ### v1.70.0 (2023-08-29)
3
17
 
data/Gemfile CHANGED
@@ -12,5 +12,12 @@ if ENV['X_PACT_DEVELOPMENT'] == 'true'
12
12
  end
13
13
 
14
14
  group :development do
15
+ gem 'fakefs', '~> 2.4'
16
+ gem 'webmock', '~> 3.0'
17
+ gem 'conventional-changelog', '~>1.3'
18
+ gem 'pact', '~> 1.16'
19
+ gem 'pact-support', '~> 1.16'
20
+ gem 'approvals', '0.0.26'
21
+ gem 'rspec-its', '~> 1.3'
15
22
  gem 'pry-byebug'
16
- end
23
+ end
data/README.md CHANGED
@@ -434,7 +434,7 @@ Options:
434
434
  -e, [--version=VERSION]
435
435
  # The pacticipant version. Must be entered after the
436
436
  --pacticipant that it relates to.
437
- [--ignore=IGNORE]
437
+ [--ignore=PACTICIPANT]
438
438
  # The pacticipant name to ignore. Use once for each pacticipant
439
439
  being ignored. A specific version can be ignored by also
440
440
  specifying a --version after the pacticipant name option. The
@@ -458,10 +458,6 @@ Options:
458
458
  # The tag that represents the branch or environment of the
459
459
  integrated applications for which you want to check the
460
460
  verification result status.
461
- [--ignore=IGNORE]
462
- # The pacticipant name to ignore. Use once for each pacticipant
463
- being ignored. A specific version can be ignored by also
464
- specifying a --version after the pacticipant name option.
465
461
  -o, [--output=OUTPUT]
466
462
  # json or table
467
463
  # Default: table
@@ -505,8 +501,8 @@ Description:
505
501
  support for environments, deployments and releases. For documentation on how to use can-i-deploy with tags, please see
506
502
  https://docs.pact.io/pact_broker/client_cli/can_i_deploy_usage_with_tags/
507
503
 
508
- Before `can-i-deploy` can be used, the relevant environment resources must first be created in the Pact Broker using the `create-environment` command. The "test"
509
- and "production" environments will have been seeded for you. You can check the existing environments by running `pact-broker list-environments`. See
504
+ Before `can-i-deploy` can be used, the relevant environment resources must first be created in the Pact Broker using the `create-environment` command. The
505
+ "test" and "production" environments will have been seeded for you. You can check the existing environments by running `pact-broker list-environments`. See
510
506
  https://docs.pact.io/pact_broker/client_cli/readme#environments for more information.
511
507
 
512
508
  $ pact-broker create-environment --name "uat" --display-name "UAT" --no-production
@@ -516,8 +512,8 @@ Description:
516
512
 
517
513
  $ pact-broker record-deployment --pacticipant Foo --version 173153ae0 --environment uat
518
514
 
519
- Before an application is deployed or released to an environment, the can-i-deploy command must be run to check that the application version is safe to deploy with
520
- the versions of each integrated application that are already in that environment.
515
+ Before an application is deployed or released to an environment, the can-i-deploy command must be run to check that the application version is safe to deploy
516
+ with the versions of each integrated application that are already in that environment.
521
517
 
522
518
  $ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION --to-environment ENVIRONMENT
523
519
 
@@ -525,8 +521,8 @@ Description:
525
521
 
526
522
  $ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 --to-environment test
527
523
 
528
- Can-i-deploy can also be used to check if arbitrary versions have a successful verification. When asking "Can I deploy this application version with the latest version
529
- from the main branch of another application" it functions as a "can I merge" check.
524
+ Can-i-deploy can also be used to check if arbitrary versions have a successful verification. When asking "Can I deploy this application version with the
525
+ latest version from the main branch of another application" it functions as a "can I merge" check.
530
526
 
531
527
  $ pact-broker can-i-deploy --pacticipant Foo 173153ae0 \ --pacticipant Bar --latest main
532
528
 
@@ -536,6 +532,56 @@ If the verification process takes a long time and there are results missing when
536
532
  command to poll and wait for the missing results to arrive. The arguments to specify are `--retry-while-unknown TIMES` and `--retry-interval SECONDS`, set to
537
533
  appropriate values for your pipeline.
538
534
 
535
+ #### can-i-merge
536
+
537
+ ```
538
+ Usage:
539
+ pact-broker can-i-merge -a, --pacticipant=PACTICIPANT -b, --broker-base-url=BROKER_BASE_URL
540
+
541
+ Options:
542
+ -a, --pacticipant=PACTICIPANT
543
+ # The pacticipant name. Use once for each pacticipant being
544
+ checked.
545
+ -e, [--version=VERSION]
546
+ # The pacticipant version. Must be entered after the
547
+ --pacticipant that it relates to.
548
+ -o, [--output=OUTPUT]
549
+ # json or table
550
+ # Default: table
551
+ [--retry-while-unknown=TIMES]
552
+ # The number of times to retry while there is an unknown
553
+ verification result (ie. the provider verification is likely
554
+ still running)
555
+ # Default: 0
556
+ [--retry-interval=SECONDS]
557
+ # The time between retries in seconds. Use in conjuction with
558
+ --retry-while-unknown
559
+ # Default: 10
560
+ [--dry-run], [--no-dry-run]
561
+ # When dry-run is enabled, always exit process with a success
562
+ code. Can also be enabled by setting the environment variable
563
+ PACT_BROKER_CAN_I_MERGE_DRY_RUN=true. This mode is useful when
564
+ setting up your CI/CD pipeline for the first time, or in a
565
+ 'break glass' situation where you need to knowingly deploy what
566
+ Pact considers a breaking change. For the second scenario, it
567
+ is recommended to use the environment variable and just set it
568
+ for the build required to deploy that particular version, so
569
+ you don't accidentally leave the dry run mode enabled.
570
+ -b, --broker-base-url=BROKER_BASE_URL
571
+ # The base URL of the Pact Broker
572
+ -u, [--broker-username=BROKER_USERNAME]
573
+ # Pact Broker basic auth username
574
+ -p, [--broker-password=BROKER_PASSWORD]
575
+ # Pact Broker basic auth password
576
+ -k, [--broker-token=BROKER_TOKEN]
577
+ # Pact Broker bearer token
578
+ -v, [--verbose], [--no-verbose]
579
+ # Verbose output. Default: false
580
+ ```
581
+
582
+ Description:
583
+ Checks if the specified pacticipant version is compatible with the configured main branch of each of the pacticipants with which it is integrated.
584
+
539
585
  ### Pacticipants
540
586
 
541
587
  #### create-or-update-pacticipant
@@ -679,8 +725,8 @@ Options:
679
725
  ```
680
726
 
681
727
  Description:
682
- 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,
683
- provider, event types and broker details. Note that the URL must be the first parameter when executing create-webhook.
728
+ 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
729
+ consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-webhook.
684
730
 
685
731
  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
686
732
  option. Please use the --broker-username or environment variable for the Pact Broker username.
@@ -744,9 +790,9 @@ Options:
744
790
  ```
745
791
 
746
792
  Description:
747
- 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
748
- 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
749
- also be provided. You can generate a valid UUID by using the `generate-uuid` command.
793
+ 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
794
+ 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
795
+ must also be provided. You can generate a valid UUID by using the `generate-uuid` command.
750
796
 
751
797
  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
752
798
  option. Please use the --broker-username or environment variable for the Pact Broker username.
@@ -930,6 +976,8 @@ Options:
930
976
  # The tool used to verify the provider contract
931
977
  [--verifier-version=VERIFIER_VERSION]
932
978
  # The version of the tool used to verify the provider contract
979
+ [--build-url=BUILD_URL]
980
+ # The build URL that created the provider contract
933
981
  -o, [--output=OUTPUT]
934
982
  # json or text
935
983
  # Default: text
@@ -4,12 +4,16 @@
4
4
 
5
5
  * [A request for the index resource](#a_request_for_the_index_resource)
6
6
 
7
+ * [A request for the index resource](#a_request_for_the_index_resource_given_the_pb:publish-provider-contract_relation_exists_in_the_index_resource) given the pb:publish-provider-contract relation exists in the index resource
8
+
7
9
  * [A request to create a provider contract](#a_request_to_create_a_provider_contract)
8
10
 
9
11
  * [A request to create a provider contract](#a_request_to_create_a_provider_contract_given_there_is_a_pf:ui_href_in_the_response) given there is a pf:ui href in the response
10
12
 
11
13
  * [A request to create a webhook for a team](#a_request_to_create_a_webhook_for_a_team_given_a_team_with_UUID_2abbc12a-427d-432a-a521-c870af1739d9_exists) given a team with UUID 2abbc12a-427d-432a-a521-c870af1739d9 exists
12
14
 
15
+ * [A request to publish a provider contract](#a_request_to_publish_a_provider_contract)
16
+
13
17
  #### Interactions
14
18
 
15
19
  <a name="a_request_for_the_index_resource"></a>
@@ -45,6 +49,33 @@ PactFlow will respond with:
45
49
  }
46
50
  }
47
51
  ```
52
+ <a name="a_request_for_the_index_resource_given_the_pb:publish-provider-contract_relation_exists_in_the_index_resource"></a>
53
+ Given **the pb:publish-provider-contract relation exists in the index resource**, upon receiving **a request for the index resource** from Pact Broker Client, with
54
+ ```json
55
+ {
56
+ "method": "GET",
57
+ "path": "/",
58
+ "headers": {
59
+ "Accept": "application/hal+json"
60
+ }
61
+ }
62
+ ```
63
+ PactFlow will respond with:
64
+ ```json
65
+ {
66
+ "status": 200,
67
+ "headers": {
68
+ "Content-Type": "application/hal+json;charset=utf-8"
69
+ },
70
+ "body": {
71
+ "_links": {
72
+ "pf:publish-provider-contract": {
73
+ "href": "http://localhost:1235/HAL-REL-PLACEHOLDER-PF-PUBLISH-PROVIDER-CONTRACT-{provider}"
74
+ }
75
+ }
76
+ }
77
+ }
78
+ ```
48
79
  <a name="a_request_to_create_a_provider_contract"></a>
49
80
  Upon receiving **a request to create a provider contract** from Pact Broker Client, with
50
81
  ```json
@@ -56,7 +87,7 @@ Upon receiving **a request to create a provider contract** from Pact Broker Clie
56
87
  "Accept": "application/hal+json"
57
88
  },
58
89
  "body": {
59
- "content": "LS0tCjpzb21lOiBjb250cmFjdAo=",
90
+ "content": "LS0tCnNvbWU6IGNvbnRyYWN0Cg==",
60
91
  "contractType": "oas",
61
92
  "contentType": "application/yaml",
62
93
  "verificationResults": {
@@ -90,7 +121,7 @@ Given **there is a pf:ui href in the response**, upon receiving **a request to c
90
121
  "Accept": "application/hal+json"
91
122
  },
92
123
  "body": {
93
- "content": "LS0tCjpzb21lOiBjb250cmFjdAo=",
124
+ "content": "LS0tCnNvbWU6IGNvbnRyYWN0Cg==",
94
125
  "contractType": "oas",
95
126
  "contentType": "application/yaml",
96
127
  "verificationResults": {
@@ -104,7 +135,7 @@ Given **there is a pf:ui href in the response**, upon receiving **a request to c
104
135
  }
105
136
  }
106
137
  ```
107
- Pactflow will respond with:
138
+ PactFlow will respond with:
108
139
  ```json
109
140
  {
110
141
  "status": 201,
@@ -114,7 +145,7 @@ Pactflow will respond with:
114
145
  "body": {
115
146
  "_links": {
116
147
  "pf:ui": {
117
- "href": "http://localhost:1235/contracts/bi-directional/provider/Bar/version/1/provider-contract"
148
+ "href": "some-url"
118
149
  }
119
150
  }
120
151
  }
@@ -171,3 +202,66 @@ PactFlow will respond with:
171
202
  }
172
203
  }
173
204
  ```
205
+ <a name="a_request_to_publish_a_provider_contract"></a>
206
+ Upon receiving **a request to publish a provider contract** from Pact Broker Client, with
207
+ ```json
208
+ {
209
+ "method": "post",
210
+ "path": "/HAL-REL-PLACEHOLDER-PF-PUBLISH-PROVIDER-CONTRACT-Bar",
211
+ "headers": {
212
+ "Content-Type": "application/json",
213
+ "Accept": "application/hal+json"
214
+ },
215
+ "body": {
216
+ "pacticipantVersionNumber": "1",
217
+ "tags": [
218
+ "dev"
219
+ ],
220
+ "branch": "main",
221
+ "buildUrl": "http://build",
222
+ "contract": {
223
+ "content": "LS0tCnNvbWU6IGNvbnRyYWN0Cg==",
224
+ "contentType": "application/yaml",
225
+ "specification": "oas",
226
+ "selfVerificationResults": {
227
+ "success": true,
228
+ "content": "c29tZSByZXN1bHRz",
229
+ "contentType": "text/plain",
230
+ "format": "text",
231
+ "verifier": "my custom tool",
232
+ "verifierVersion": "1.0"
233
+ }
234
+ }
235
+ }
236
+ }
237
+ ```
238
+ PactFlow will respond with:
239
+ ```json
240
+ {
241
+ "status": 200,
242
+ "headers": {
243
+ "Content-Type": "application/hal+json;charset=utf-8"
244
+ },
245
+ "body": {
246
+ "notices": [
247
+ {
248
+ "text": "some notice",
249
+ "type": "info"
250
+ }
251
+ ],
252
+ "_embedded": {
253
+ "version": {
254
+ "number": "1"
255
+ }
256
+ },
257
+ "_links": {
258
+ "pb:pacticipant-version-tags": [
259
+ {
260
+ }
261
+ ],
262
+ "pb:branch-version": {
263
+ }
264
+ }
265
+ }
266
+ }
267
+ ```
@@ -1,4 +1,4 @@
1
1
  ### Pacts for Pact Broker Client
2
2
 
3
3
  * [Pact Broker](Pact%20Broker%20Client%20-%20Pact%20Broker.md)
4
- * [PactFlow](Pact%20Broker%20Client%20-%20Pactflow.md)
4
+ * [PactFlow](Pact%20Broker%20Client%20-%20PactFlow.md)
@@ -13,13 +13,12 @@ module PactBroker
13
13
 
14
14
  method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name. Use once for each pacticipant being checked."
15
15
  method_option :version, required: false, aliases: "-e", desc: "The pacticipant version. Must be entered after the --pacticipant that it relates to."
16
- method_option :ignore, required: false, desc: "The pacticipant name to ignore. Use once for each pacticipant being ignored. A specific version can be ignored by also specifying a --version after the pacticipant name option. The environment variable PACT_BROKER_CAN_I_DEPLOY_IGNORE may also be used to specify a pacticipant name to ignore, with commas to separate multiple pacticipant names if necessary."
16
+ method_option :ignore, required: false, banner: "PACTICIPANT", desc: "The pacticipant name to ignore. Use once for each pacticipant being ignored. A specific version can be ignored by also specifying a --version after the pacticipant name option. The environment variable PACT_BROKER_CAN_I_DEPLOY_IGNORE may also be used to specify a pacticipant name to ignore, with commas to separate multiple pacticipant names if necessary."
17
17
  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."
18
18
  method_option :branch, required: false, desc: "The branch of the version for which you want to check the verification results.", default: nil
19
19
  method_option :main_branch, required: false, type: :boolean, desc: "Use the latest version of the configured main branch of the pacticipant as the version for which you want to check the verification results", default: false
20
20
  method_option :to_environment, required: false, banner: "ENVIRONMENT", desc: "The environment into which the pacticipant(s) are to be deployed", default: nil
21
21
  method_option :to, required: false, banner: "TAG", desc: "The tag that represents the branch or environment of the integrated applications for which you want to check the verification result status.", default: nil
22
- method_option :ignore, required: false, desc: "The pacticipant name to ignore. Use once for each pacticipant being ignored. A specific version can be ignored by also specifying a --version after the pacticipant name option."
23
22
  method_option :output, aliases: "-o", desc: "json or table", default: "table"
24
23
  method_option :retry_while_unknown, banner: "TIMES", type: :numeric, default: 0, required: false, desc: "The number of times to retry while there is an unknown verification result (ie. the provider verification is likely still running)"
25
24
  method_option :retry_interval, banner: "SECONDS", type: :numeric, default: 10, required: false, desc: "The time between retries in seconds. Use in conjuction with --retry-while-unknown"
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '1.70.0'
3
+ VERSION = '1.72.0'
4
4
  end
5
5
  end
@@ -26,7 +26,7 @@ module Pactflow
26
26
  method_option :verification_results_format, desc: "The format of the verification output eg. junit, text"
27
27
  method_option :verifier, desc: "The tool used to verify the provider contract"
28
28
  method_option :verifier_version, desc: "The version of the tool used to verify the provider contract"
29
- #method_option :build_url, desc: "The build URL that created the pact"
29
+ method_option :build_url, desc: "The build URL that created the provider contract"
30
30
 
31
31
  output_option_json_or_text
32
32
  shared_authentication_options
@@ -70,6 +70,7 @@ module Pactflow
70
70
  provider_version_number: options.provider_app_version.strip,
71
71
  branch_name: options.branch && options.branch.strip,
72
72
  tags: (options.tag && options.tag.collect(&:strip)) || [],
73
+ build_url: options.build_url,
73
74
  contract: {
74
75
  content: File.read(provider_contract_path),
75
76
  content_type: options.content_type,
@@ -1,13 +1,14 @@
1
- require "pact_broker/client/base_command"
2
- require "pact_broker/client/versions/create"
3
- require 'pact_broker/client/colorize_notices'
4
1
  require "base64"
2
+ require "pact_broker/client/base_command"
3
+ require "pact_broker/client/colorize_notices"
4
+ require "pactflow/client/provider_contracts/publish_the_old_way"
5
5
 
6
6
  module Pactflow
7
7
  module Client
8
8
  module ProviderContracts
9
9
  class Publish < PactBroker::Client::BaseCommand
10
- attr_reader :branch_name, :tags, :provider_name, :provider_version_number, :contract, :verification_results
10
+ PUBLISH_RELATION = "pf:publish-provider-contract"
11
+
11
12
 
12
13
  def initialize(params, options, pact_broker_client_options)
13
14
  super
@@ -15,62 +16,30 @@ module Pactflow
15
16
  @provider_version_number = params[:provider_version_number]
16
17
  @branch_name = params[:branch_name]
17
18
  @tags = params[:tags] || []
19
+ @build_url = params[:build_url]
18
20
  @contract = params[:contract]
19
21
  @verification_results = params[:verification_results]
20
22
  end
21
23
 
22
24
  private
23
25
 
24
- def do_call
25
- create_branch_version_and_tags
26
- render_response(create_contract)
27
- end
26
+ attr_reader :provider_name, :provider_version_number, :branch_name, :tags, :build_url, :contract, :verification_results
28
27
 
29
- def render_response(res)
30
- notices = [
31
- { type: 'success', text: "Successfully published provider contract for #{provider_name} version #{provider_version_number} to PactFlow"},
32
- ]
33
- if res.body && res.body['_links'] && res.body['_links']['pf:ui']['href']
34
- notices.concat([{ text: "View the uploaded contract at #{res.body['_links']['pf:ui']['href']}" }])
28
+ def do_call
29
+ if !disabled? && index_resource.assert_success!.can?(PUBLISH_RELATION)
30
+ publish_provider_contracts
31
+ PactBroker::Client::CommandResult.new(success?, message)
32
+ else
33
+ PublishTheOldWay.call(params, options, pact_broker_client_options)
35
34
  end
36
- notices.concat(next_steps)
37
- PactBroker::Client::CommandResult.new(true, PactBroker::Client::ColorizeNotices.call(notices.collect do |n|
38
- OpenStruct.new(n)
39
- end).join("\n"))
40
- end
41
-
42
- def next_steps
43
- [
44
- { type: 'prompt', text: 'Next steps:' },
45
- { type: 'prompt',
46
- text: ' * Check your application is safe to deploy - https://docs.pact.io/can_i_deploy' },
47
- { text: " pact-broker can-i-deploy --pacticipant #{provider_name} --version #{provider_version_number} --to-environment <your environment name>" },
48
- { type: 'prompt',
49
- text: ' * Record deployment or release to specified environment (choose one) - https://docs.pact.io/go/record-deployment' },
50
- { text: " pact-broker record-deployment --pacticipant #{provider_name} --version #{provider_version_number} --environment <your environment name>" },
51
- { text: " pact-broker record-release --pacticipant #{provider_name} --version #{provider_version_number} --environment <your environment name>" }
52
- ]
53
35
  end
54
36
 
55
- def create_branch_version_and_tags
56
- if branch_name || tags.any?
57
- pacticipant_version_params = {
58
- pacticipant_name: provider_name,
59
- version_number: provider_version_number,
60
- branch_name: branch_name,
61
- tags: tags
62
- }
63
- result = PactBroker::Client::Versions::Create.call(pacticipant_version_params, options, pact_broker_client_options)
64
- if !result.success
65
- raise PactBroker::Client::Error.new(result.message)
66
- end
67
- end
37
+ def disabled?
38
+ ENV.fetch("PACTFLOW_FEATURES", "").include?("publish_provider_contracts_using_old_api")
68
39
  end
69
40
 
70
- def create_contract
71
- contract_path = "#{pact_broker_base_url}/contracts/provider/{provider}/version/{version}"
72
- entrypoint = create_entry_point(contract_path, pact_broker_client_options)
73
- entrypoint.expand(provider: provider_name, version: provider_version_number).put!(contract_params).response
41
+ def publish_provider_contracts
42
+ @response_entity = index_resource._link(PUBLISH_RELATION).expand(provider: provider_name).post!(contract_params, headers: { "Accept" => "application/hal+json,application/problem+json" })
74
43
  end
75
44
 
76
45
  def contract_params
@@ -82,22 +51,45 @@ module Pactflow
82
51
  verifier: verification_results[:verifier],
83
52
  verifierVersion: verification_results[:verifier_version]
84
53
  }.compact
85
-
86
- body_params = {
87
- content: encode_content(contract[:content]),
88
- contractType: contract[:specification],
89
- contentType: contract[:content_type],
90
- }.compact
54
+
55
+ contract_params = {
56
+ content: encode_content(contract[:content]),
57
+ specification: contract[:specification],
58
+ contentType: contract[:content_type]
59
+ }.compact
91
60
 
92
61
  if verification_results_params.any?
93
- body_params[:verificationResults] = verification_results_params
62
+ contract_params[:selfVerificationResults] = verification_results_params
94
63
  end
95
- body_params
64
+
65
+ {
66
+ pacticipantVersionNumber: provider_version_number,
67
+ tags: tags,
68
+ branch: branch_name,
69
+ buildUrl: build_url,
70
+ contract: contract_params
71
+ }
96
72
  end
97
73
 
98
74
  def encode_content oas
99
75
  Base64.strict_encode64(oas)
100
76
  end
77
+
78
+ def message
79
+ if options[:output] == "json"
80
+ @response_entity.response.raw_body
81
+ else
82
+ text_message
83
+ end
84
+ end
85
+
86
+ def success?
87
+ @response_entity.success?
88
+ end
89
+
90
+ def text_message
91
+ PactBroker::Client::ColorizeNotices.call(@response_entity.notices.collect{ |n| OpenStruct.new(n) } )
92
+ end
101
93
  end
102
94
  end
103
95
  end