pact_broker-client 1.53.0 → 1.57.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +1 -1
  3. data/CHANGELOG.md +31 -0
  4. data/README.md +14 -2
  5. data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +222 -0
  6. data/lib/pact_broker/client/base_client.rb +7 -5
  7. data/lib/pact_broker/client/cli/matrix_commands.rb +3 -2
  8. data/lib/pact_broker/client/cli/pacticipant_commands.rb +2 -1
  9. data/lib/pact_broker/client/cli/version_selector_options_parser.rb +4 -0
  10. data/lib/pact_broker/client/cli/webhook_commands.rb +16 -1
  11. data/lib/pact_broker/client/deployments/record_release.rb +5 -1
  12. data/lib/pact_broker/client/deployments/record_undeployment.rb +1 -1
  13. data/lib/pact_broker/client/environments/environment_command.rb +7 -2
  14. data/lib/pact_broker/client/git.rb +15 -4
  15. data/lib/pact_broker/client/hal/entity.rb +2 -2
  16. data/lib/pact_broker/client/hal/http_client.rb +20 -1
  17. data/lib/pact_broker/client/hal/link.rb +7 -2
  18. data/lib/pact_broker/client/pacticipants/create.rb +2 -1
  19. data/lib/pact_broker/client/publish_pacts.rb +5 -1
  20. data/lib/pact_broker/client/version.rb +1 -1
  21. data/lib/pact_broker/client/webhooks/create.rb +4 -0
  22. data/script/can-i-deploy.sh +5 -0
  23. data/script/record-deployments-and-releases.sh +3 -3
  24. data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +55 -0
  25. data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +6 -0
  26. data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +12 -1
  27. data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +1 -1
  28. data/spec/lib/pact_broker/client/git_spec.rb +46 -0
  29. data/spec/lib/pact_broker/client/hal/link_spec.rb +15 -0
  30. data/spec/pacts/pact_broker_client-pact_broker.json +234 -0
  31. data/spec/service_providers/webhooks_create_spec.rb +58 -0
  32. data/tasks/pact.rake +3 -1
  33. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6662ad835f144252e2a6fd78f98e52b381794629dcbfb8085fa1acb0b28ece0
4
- data.tar.gz: b0ec70c258bb01ae05801070596dbb02fe23a8f674d2bab53117c40b75a6d59f
3
+ metadata.gz: 2d919435a18e3fdcfa55f3c4e75194c950e027924b2fb274a88bb78ce04035be
4
+ data.tar.gz: b80790889dde8ee96a98d48b8558608ca0f240da15ece8d57cdc15d646317d42
5
5
  SHA512:
6
- metadata.gz: 0f20176d5773873c3cd9a41711a7d4405721f95017132702e6be84430a63baef7101aefcb2b43e05546536d974306c7677b529bd8c2d6e32701432de67e0fe44
7
- data.tar.gz: b4fc4fa3bd5096b5281d98478cc59d8732a31c29ec7f959922c064193135fd613740220230449e2c5ea3b98611f555b372545549fd22fb52050cc7710a582023
6
+ metadata.gz: 9c36cfba633f104712099c648e8ef1ccf58dfd1e3025fc44719cdaf6b3e4b47af0ba27af0da7d01074ffc8f6c01cbc4e3e0195b5d95f18e5e960bbac038c6370
7
+ data.tar.gz: 33526cff8acc17cd129b2521127f4abc3f73eac56b4f1c3e832fe0fb3583bdbe3a1917ae2ac9ec8796414584ad97777e89f163c5732ac5f5f4a879a6c4955be3
@@ -37,7 +37,7 @@ jobs:
37
37
  - run: |
38
38
  rm -rf spec/pacts/*
39
39
  bundle exec rspec spec/service_providers/
40
- bundle exec rake pact:publish:pactflow
40
+ VERBOSE=true bundle exec rake pact:publish:pactflow
41
41
  env:
42
42
  PACT_BROKER_TOKEN: ${{ secrets.PACTFLOW_PACT_OSS_TOKEN }}
43
43
  PACT_BROKER_FEATURES: ${{ matrix.feature }}
data/CHANGELOG.md CHANGED
@@ -1,3 +1,34 @@
1
+ <a name="v1.57.0"></a>
2
+ ### v1.57.0 (2021-11-05)
3
+
4
+ #### Features
5
+
6
+ * support the --branch option in the version selectors for can-i-deploy ([dba8ec4](/../../commit/dba8ec4))
7
+ * show more helpful error message if pb:environments not available for pactflow ([1bf38e3](/../../commit/1bf38e3))
8
+ * print out notices if returned from publish pacts request ([86caf7e](/../../commit/86caf7e))
9
+
10
+ <a name="v1.56.0"></a>
11
+ ### v1.56.0 (2021-10-06)
12
+
13
+ #### Features
14
+
15
+ * add pacticipant label options to webhook create/update commands (#96) ([710293f](/../../commit/710293f))
16
+
17
+ <a name="v1.55.0"></a>
18
+ ### v1.55.0 (2021-10-03)
19
+
20
+ #### Features
21
+
22
+ * support Github Actions environment variables for --tag-with-git-branch ([2b8dac5](/../../commit/2b8dac5))
23
+
24
+ <a name="v1.54.0"></a>
25
+ ### v1.54.0 (2021-10-01)
26
+
27
+ #### Features
28
+
29
+ * disable SSL verification for HAL client and HTTParty client when environment variable PACT_DISABLE_SSL_VERIFICATION=true ([470aafa](/../../commit/470aafa))
30
+ * support setting the --main-branch for a pacticipant ([1f18e70](/../../commit/1f18e70))
31
+
1
32
  <a name="v1.53.0"></a>
2
33
  ### v1.53.0 (2021-09-29)
3
34
 
data/README.md CHANGED
@@ -517,6 +517,8 @@ Options:
517
517
  # Pacticipant name
518
518
  [--display-name=DISPLAY_NAME]
519
519
  # Display name
520
+ [--main-branch=MAIN_BRANCH]
521
+ # The main development branch of the pacticipant repository
520
522
  [--repository-url=REPOSITORY_URL]
521
523
  # The repository URL of the pacticipant
522
524
  -o, [--output=OUTPUT]
@@ -605,8 +607,12 @@ Options:
605
607
  # Webhook basic auth username and password eg. username:password
606
608
  [--consumer=CONSUMER]
607
609
  # Consumer name
610
+ [--consumer-label=CONSUMER_LABEL]
611
+ # Consumer label
608
612
  [--provider=PROVIDER]
609
613
  # Provider name
614
+ [--provider-label=PROVIDER_LABEL]
615
+ # Provider label
610
616
  [--description=DESCRIPTION]
611
617
  # Webhook description
612
618
  [--contract-content-changed], [--no-contract-content-changed]
@@ -661,8 +667,12 @@ Options:
661
667
  # Webhook basic auth username and password eg. username:password
662
668
  [--consumer=CONSUMER]
663
669
  # Consumer name
670
+ [--consumer-label=CONSUMER_LABEL]
671
+ # Consumer label
664
672
  [--provider=PROVIDER]
665
673
  # Provider name
674
+ [--provider-label=PROVIDER_LABEL]
675
+ # Provider label
666
676
  [--description=DESCRIPTION]
667
677
  # Webhook description
668
678
  [--contract-content-changed], [--no-contract-content-changed]
@@ -827,11 +837,13 @@ require 'pact_broker/client/tasks'
827
837
 
828
838
  PactBroker::Client::PublicationTask.new do | task |
829
839
  require 'my_consumer/version'
830
- task.consumer_version = MyConsumer::VERSION
840
+ task.consumer_version = ENV["GIT_COMMIT"]
831
841
  task.pattern = 'custom/path/to/pacts/*.json' # optional, default value is 'spec/pacts/*.json'
832
842
  task.pact_broker_base_url = "http://pact-broker"
833
- task.tag_with_git_branch = true|false # Optional but STRONGLY RECOMMENDED as it will greatly assist with your pact workflow. Result will be merged with other specified task.tags
843
+ task.branch = ENV["GIT_BRANCH"] # Optional but STRONGLY RECOMMENDED.
844
+ task.tag_with_git_branch = true|false # Superseeded by the `branch` property
834
845
  task.tags = ["dev"] # optional
846
+ task.build_url = ENV["CI_BUILD_URL"]
835
847
  task.pact_broker_basic_auth = { username: 'basic_auth_user', password: 'basic_auth_pass'} # optional
836
848
  task.pact_broker_token = "1234abcd" # Bearer token
837
849
  task.write_method = :merge # optional, this will merge the published pact into an existing pact rather than overwriting it if one exists. Not recommended, as it makes a mulch of the workflow on the broker.
@@ -64,10 +64,14 @@
64
64
 
65
65
  * [A request to create a webhook with a JSON body for a consumer and provider](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_consumer_and_provider_given_the_&#39;Pricing_Service&#39;_and_&#39;Condor&#39;_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
66
66
 
67
+ * [A request to create a webhook with a JSON body for a consumer specified by a label](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_consumer_specified_by_a_label)
68
+
67
69
  * [A request to create a webhook with a JSON body for a consumer that does not exist](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_consumer_that_does_not_exist)
68
70
 
69
71
  * [A request to create a webhook with a JSON body for a provider](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_provider_given_the_&#39;Pricing_Service&#39;_and_&#39;Condor&#39;_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
70
72
 
73
+ * [A request to create a webhook with a JSON body for a provider specified by a label](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_provider_specified_by_a_label)
74
+
71
75
  * [A request to create a webhook with a non-JSON body for a consumer and provider](#a_request_to_create_a_webhook_with_a_non-JSON_body_for_a_consumer_and_provider_given_the_&#39;Pricing_Service&#39;_and_&#39;Condor&#39;_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
72
76
 
73
77
  * [A request to create a webhook with every possible event type](#a_request_to_create_a_webhook_with_every_possible_event_type_given_the_&#39;Pricing_Service&#39;_and_&#39;Condor&#39;_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
@@ -1089,6 +1093,16 @@ Pact Broker will respond with:
1089
1093
  },
1090
1094
  "body": {
1091
1095
  "description": "a webhook",
1096
+ "request": {
1097
+ "body": {
1098
+ "some": "body"
1099
+ }
1100
+ },
1101
+ "events": [
1102
+ {
1103
+ "name": "contract_content_changed"
1104
+ }
1105
+ ],
1092
1106
  "_links": {
1093
1107
  "self": {
1094
1108
  "href": "http://localhost:1234/some-url",
@@ -1222,6 +1236,16 @@ Pact Broker will respond with:
1222
1236
  },
1223
1237
  "body": {
1224
1238
  "description": "a webhook",
1239
+ "request": {
1240
+ "body": {
1241
+ "some": "body"
1242
+ }
1243
+ },
1244
+ "events": [
1245
+ {
1246
+ "name": "contract_content_changed"
1247
+ }
1248
+ ],
1225
1249
  "_links": {
1226
1250
  "self": {
1227
1251
  "href": "http://localhost:1234/some-url",
@@ -1276,6 +1300,16 @@ Pact Broker will respond with:
1276
1300
  },
1277
1301
  "body": {
1278
1302
  "description": "a webhook",
1303
+ "request": {
1304
+ "body": {
1305
+ "some": "body"
1306
+ }
1307
+ },
1308
+ "events": [
1309
+ {
1310
+ "name": "contract_content_changed"
1311
+ }
1312
+ ],
1279
1313
  "_links": {
1280
1314
  "self": {
1281
1315
  "href": "http://localhost:1234/some-url",
@@ -1327,6 +1361,80 @@ Pact Broker will respond with:
1327
1361
  },
1328
1362
  "body": {
1329
1363
  "description": "a webhook",
1364
+ "request": {
1365
+ "body": {
1366
+ "some": "body"
1367
+ }
1368
+ },
1369
+ "events": [
1370
+ {
1371
+ "name": "contract_content_changed"
1372
+ }
1373
+ ],
1374
+ "_links": {
1375
+ "self": {
1376
+ "href": "http://localhost:1234/some-url",
1377
+ "title": "A title"
1378
+ }
1379
+ }
1380
+ }
1381
+ }
1382
+ ```
1383
+ <a name="a_request_to_create_a_webhook_with_a_JSON_body_for_a_consumer_specified_by_a_label"></a>
1384
+ Upon receiving **a request to create a webhook with a JSON body for a consumer specified by a label** from Pact Broker Client, with
1385
+ ```json
1386
+ {
1387
+ "method": "post",
1388
+ "path": "/HAL-REL-PLACEHOLDER-PB-WEBHOOKS",
1389
+ "headers": {
1390
+ "Content-Type": "application/json",
1391
+ "Accept": "application/hal+json"
1392
+ },
1393
+ "body": {
1394
+ "description": "a webhook",
1395
+ "events": [
1396
+ {
1397
+ "name": "contract_content_changed"
1398
+ }
1399
+ ],
1400
+ "request": {
1401
+ "url": "https://webhook",
1402
+ "method": "POST",
1403
+ "headers": {
1404
+ "Foo": "bar",
1405
+ "Bar": "foo"
1406
+ },
1407
+ "body": {
1408
+ "some": "body"
1409
+ },
1410
+ "username": "username",
1411
+ "password": "password"
1412
+ },
1413
+ "consumer": {
1414
+ "label": "consumer_label"
1415
+ }
1416
+ }
1417
+ }
1418
+ ```
1419
+ Pact Broker will respond with:
1420
+ ```json
1421
+ {
1422
+ "status": 201,
1423
+ "headers": {
1424
+ "Content-Type": "application/hal+json;charset=utf-8"
1425
+ },
1426
+ "body": {
1427
+ "description": "a webhook",
1428
+ "request": {
1429
+ "body": {
1430
+ "some": "body"
1431
+ }
1432
+ },
1433
+ "events": [
1434
+ {
1435
+ "name": "contract_content_changed"
1436
+ }
1437
+ ],
1330
1438
  "_links": {
1331
1439
  "self": {
1332
1440
  "href": "http://localhost:1234/some-url",
@@ -1433,6 +1541,80 @@ Pact Broker will respond with:
1433
1541
  },
1434
1542
  "body": {
1435
1543
  "description": "a webhook",
1544
+ "request": {
1545
+ "body": {
1546
+ "some": "body"
1547
+ }
1548
+ },
1549
+ "events": [
1550
+ {
1551
+ "name": "contract_content_changed"
1552
+ }
1553
+ ],
1554
+ "_links": {
1555
+ "self": {
1556
+ "href": "http://localhost:1234/some-url",
1557
+ "title": "A title"
1558
+ }
1559
+ }
1560
+ }
1561
+ }
1562
+ ```
1563
+ <a name="a_request_to_create_a_webhook_with_a_JSON_body_for_a_provider_specified_by_a_label"></a>
1564
+ Upon receiving **a request to create a webhook with a JSON body for a provider specified by a label** from Pact Broker Client, with
1565
+ ```json
1566
+ {
1567
+ "method": "post",
1568
+ "path": "/HAL-REL-PLACEHOLDER-PB-WEBHOOKS",
1569
+ "headers": {
1570
+ "Content-Type": "application/json",
1571
+ "Accept": "application/hal+json"
1572
+ },
1573
+ "body": {
1574
+ "description": "a webhook",
1575
+ "events": [
1576
+ {
1577
+ "name": "contract_content_changed"
1578
+ }
1579
+ ],
1580
+ "request": {
1581
+ "url": "https://webhook",
1582
+ "method": "POST",
1583
+ "headers": {
1584
+ "Foo": "bar",
1585
+ "Bar": "foo"
1586
+ },
1587
+ "body": {
1588
+ "some": "body"
1589
+ },
1590
+ "username": "username",
1591
+ "password": "password"
1592
+ },
1593
+ "provider": {
1594
+ "label": "provider_label"
1595
+ }
1596
+ }
1597
+ }
1598
+ ```
1599
+ Pact Broker will respond with:
1600
+ ```json
1601
+ {
1602
+ "status": 201,
1603
+ "headers": {
1604
+ "Content-Type": "application/hal+json;charset=utf-8"
1605
+ },
1606
+ "body": {
1607
+ "description": "a webhook",
1608
+ "request": {
1609
+ "body": {
1610
+ "some": "body"
1611
+ }
1612
+ },
1613
+ "events": [
1614
+ {
1615
+ "name": "contract_content_changed"
1616
+ }
1617
+ ],
1436
1618
  "_links": {
1437
1619
  "self": {
1438
1620
  "href": "http://localhost:1234/some-url",
@@ -1482,6 +1664,14 @@ Pact Broker will respond with:
1482
1664
  },
1483
1665
  "body": {
1484
1666
  "description": "a webhook",
1667
+ "request": {
1668
+ "body": "<xml></xml>"
1669
+ },
1670
+ "events": [
1671
+ {
1672
+ "name": "contract_content_changed"
1673
+ }
1674
+ ],
1485
1675
  "_links": {
1486
1676
  "self": {
1487
1677
  "href": "http://localhost:1234/some-url",
@@ -1545,6 +1735,28 @@ Pact Broker will respond with:
1545
1735
  },
1546
1736
  "body": {
1547
1737
  "description": "a webhook",
1738
+ "request": {
1739
+ "body": {
1740
+ "some": "body"
1741
+ }
1742
+ },
1743
+ "events": [
1744
+ {
1745
+ "name": "contract_content_changed"
1746
+ },
1747
+ {
1748
+ "name": "contract_published"
1749
+ },
1750
+ {
1751
+ "name": "provider_verification_published"
1752
+ },
1753
+ {
1754
+ "name": "provider_verification_succeeded"
1755
+ },
1756
+ {
1757
+ "name": "provider_verification_failed"
1758
+ }
1759
+ ],
1548
1760
  "_links": {
1549
1761
  "self": {
1550
1762
  "href": "http://localhost:1234/some-url",
@@ -2550,6 +2762,16 @@ Pact Broker will respond with:
2550
2762
  },
2551
2763
  "body": {
2552
2764
  "description": "a webhook",
2765
+ "request": {
2766
+ "body": {
2767
+ "some": "body"
2768
+ }
2769
+ },
2770
+ "events": [
2771
+ {
2772
+ "name": "contract_content_changed"
2773
+ }
2774
+ ],
2553
2775
  "_links": {
2554
2776
  "self": {
2555
2777
  "href": "http://localhost:1234/some-url",
@@ -54,6 +54,8 @@ module PactBroker
54
54
  self.class.headers('Authorization' => "Bearer #{client_options[:token]}") if client_options[:token]
55
55
  self.class.ssl_ca_file(ENV['SSL_CERT_FILE']) if ENV['SSL_CERT_FILE'] && ENV['SSL_CERT_FILE'] != ''
56
56
  self.class.ssl_ca_path(ENV['SSL_CERT_DIR']) if ENV['SSL_CERT_DIR'] && ENV['SSL_CERT_DIR'] != ''
57
+ @default_options = {}
58
+ @default_options[:verify] = false if (ENV['PACT_DISABLE_SSL_VERIFICATION'] == 'true' || ENV['PACT_BROKER_DISABLE_SSL_VERIFICATION'] == 'true')
57
59
  end
58
60
 
59
61
  def default_request_headers
@@ -102,15 +104,15 @@ module PactBroker
102
104
  end
103
105
 
104
106
  def patch url, options
105
- self.class.patch(url, options.merge(body: options[:body].to_json))
107
+ self.class.patch(url, @default_options.merge(options.merge(body: options[:body].to_json)))
106
108
  end
107
109
 
108
- def put url, *args
109
- self.class.put(url, *args)
110
+ def put url, options = {}, &block
111
+ self.class.put(url, @default_options.merge(options), &block)
110
112
  end
111
113
 
112
- def get url, *args
113
- self.class.get(url, *args)
114
+ def get url, options = {}, &block
115
+ self.class.get(url, @default_options.merge(options), &block)
114
116
  end
115
117
 
116
118
  def url_for_relation relation_name, params
@@ -13,6 +13,7 @@ module PactBroker
13
13
  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."
14
14
  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."
15
15
  method_option :to_environment, required: false, banner: "ENVIRONMENT", desc: "The environment into which the pacticipant(s) are to be deployed", default: nil
16
+ method_option :branch, required: false, desc: "The branch of the version for which you want to check the verification results", default: nil
16
17
  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
17
18
  method_option :output, aliases: "-o", desc: "json or table", default: "table"
18
19
  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)"
@@ -77,8 +78,8 @@ module PactBroker
77
78
  end
78
79
 
79
80
  def validate_can_i_deploy_selectors selectors
80
- pacticipants_without_versions = selectors.select{ |s| s[:version].nil? && s[:latest].nil? && s[:tag].nil? }.collect{ |s| s[:pacticipant] }
81
- raise ::Thor::RequiredArgumentMissingError, "The version must be specified using `--version VERSION`, `--latest`, `--latest TAG`, or `--all TAG` for pacticipant #{pacticipants_without_versions.join(", ")}" if pacticipants_without_versions.any?
81
+ pacticipants_without_versions = selectors.select{ |s| s[:version].nil? && s[:latest].nil? && s[:tag].nil? && s[:branch].nil? }.collect{ |s| s[:pacticipant] }
82
+ raise ::Thor::RequiredArgumentMissingError, "The version must be specified using `--version VERSION`, `--branch BRANCH` `--latest`, `--latest TAG`, or `--all TAG` for pacticipant #{pacticipants_without_versions.join(", ")}" if pacticipants_without_versions.any?
82
83
  end
83
84
  end
84
85
  end
@@ -2,13 +2,14 @@ module PactBroker
2
2
  module Client
3
3
  module CLI
4
4
  module PacticipantCommands
5
- PACTICIPANT_PARAM_NAMES = [:name, :display_name, :repository_url]
5
+ PACTICIPANT_PARAM_NAMES = [:name, :display_name, :main_branch, :repository_url]
6
6
 
7
7
  def self.included(thor)
8
8
  thor.class_eval do
9
9
  desc 'create-or-update-pacticipant', 'Create or update pacticipant by name'
10
10
  method_option :name, type: :string, required: true, desc: "Pacticipant name"
11
11
  method_option :display_name, type: :string, desc: "Display name"
12
+ method_option :main_branch, type: :string, required: false, desc: "The main development branch of the pacticipant repository"
12
13
  method_option :repository_url, type: :string, required: false, desc: "The repository URL of the pacticipant"
13
14
  output_option_json_or_text
14
15
  shared_authentication_options
@@ -31,6 +31,10 @@ module PactBroker
31
31
  when "--latest", "-l"
32
32
  selectors << { pacticipant: nil } if selectors.empty?
33
33
  selectors.last[:tag] = word
34
+ when "--branch"
35
+ selectors << { pacticipant: nil } if selectors.empty?
36
+ selectors.last[:branch] = word
37
+ selectors.last[:latest] = true
34
38
  when "--all"
35
39
  selectors << { pacticipant: nil } if selectors.empty?
36
40
  selectors.last[:tag] = word
@@ -15,7 +15,9 @@ module PactBroker
15
15
  method_option :data, aliases: "-d", desc: "Webhook payload (file or string)"
16
16
  method_option :user, aliases: "-u", desc: "Webhook basic auth username and password eg. username:password"
17
17
  method_option :consumer, desc: "Consumer name"
18
+ method_option :consumer_label, desc: "Consumer label, mutually exclusive with consumer name"
18
19
  method_option :provider, desc: "Provider name"
20
+ method_option :provider_label, desc: "Provider label, mutually exclusive with provider name"
19
21
  method_option :description, desc: "Webhook description"
20
22
  method_option :contract_content_changed, type: :boolean, desc: "Trigger this webhook when the pact content changes"
21
23
  method_option :contract_published, type: :boolean, desc: "Trigger this webhook when a pact is published"
@@ -70,6 +72,7 @@ module PactBroker
70
72
  end
71
73
 
72
74
  def parse_webhook_options(webhook_url)
75
+ validate_mutual_exclusiveness_of_participant_name_and_label_options
73
76
  events = parse_webhook_events
74
77
 
75
78
  # TODO update for contract_requiring_verification_published when released
@@ -102,7 +105,9 @@ module PactBroker
102
105
  password: password,
103
106
  body: body,
104
107
  consumer: options.consumer,
108
+ consumer_label: options.consumer_label,
105
109
  provider: options.provider,
110
+ provider_label: options.provider_label,
106
111
  events: events,
107
112
  team_uuid: options.team_uuid
108
113
  }
@@ -118,10 +123,20 @@ module PactBroker
118
123
  rescue PactBroker::Client::Error => e
119
124
  raise WebhookCreationError, "#{e.class} - #{e.message}"
120
125
  end
126
+
127
+ def validate_mutual_exclusiveness_of_participant_name_and_label_options
128
+ if options.consumer && options.consumer_label
129
+ raise WebhookCreationError.new("Consumer name (--consumer) and label (--consumer_label) options are mutually exclusive")
130
+ end
131
+
132
+ if options.provider && options.provider_label
133
+ raise WebhookCreationError.new("Provider name (--provider) and label (--provider_label) options are mutually exclusive")
134
+ end
135
+ end
121
136
  end
122
137
  end
123
138
  end
124
139
  end
125
140
  end
126
141
  end
127
- end
142
+ end
@@ -30,7 +30,11 @@ module PactBroker
30
30
  end
31
31
 
32
32
  def not_supported_message
33
- "This version of the Pact Broker does not support recording #{action}s. Please upgrade to version 2.80.0 or later."
33
+ if is_pactflow?
34
+ "This version of Pactflow does not support recording #{action}s, or you do not have the required permission to read environments. Please upgrade to the latest version if using Pactflow On-Premises, and ensure the user has the environment read permission."
35
+ else
36
+ "This version of the Pact Broker does not support recording #{action}s. Please upgrade to version 2.80.0 or later."
37
+ end
34
38
  end
35
39
 
36
40
  def environment_exists?
@@ -108,7 +108,7 @@ module PactBroker
108
108
  potential_application_instances = currently_deployed_version_entities_for_pacticipant.collect{|e| e.applicationInstance || e.target }
109
109
 
110
110
  if application_instance
111
- omit_text = potential_application_instances.include?(nil) ? "omit the application instance to undeploy from the anonymous instance" : nil
111
+ omit_text = potential_application_instances.include?(nil) ? "omit the application instance" : nil
112
112
  specify_text = potential_application_instances.compact.any? ? "specify one of the following application instances to record the undeployment from: #{potential_application_instances.compact.join(", ")}" : nil
113
113
  "#{pacticipant_name} is not currently deployed to application instance '#{application_instance}' in #{environment_name} environment. Please #{[omit_text, specify_text].compact.join(" or ")}."
114
114
  else
@@ -5,6 +5,7 @@ module PactBroker
5
5
  module Environments
6
6
  class EnvironmentCommand < PactBroker::Client::BaseCommand
7
7
  NOT_SUPPORTED_MESSAGE = "This version of the Pact Broker does not support environments. Please upgrade to version 2.80.0 or later."
8
+ PACTFLOW_NOT_SUPPORTED_MESSAGE = "This version of Pactflow does not support environments or you do not have the required permission to read them. Please upgrade to the latest version if using Pactflow On-Premises and ensure the user has the environment read permission."
8
9
 
9
10
  private
10
11
 
@@ -39,7 +40,7 @@ module PactBroker
39
40
  @existing_environment_params ||= existing_environment_resource!
40
41
  .response
41
42
  .body
42
- .except("uuid", "_links", "createdAt", "updatedAt")
43
+ .except("uuid", "_links", "_embedded", "createdAt", "updatedAt")
43
44
  end
44
45
 
45
46
  def contacts
@@ -57,7 +58,11 @@ module PactBroker
57
58
 
58
59
  def check_if_command_supported
59
60
  unless index_resource.can?("pb:environments")
60
- raise PactBroker::Client::Error.new(NOT_SUPPORTED_MESSAGE)
61
+ if is_pactflow?
62
+ raise PactBroker::Client::Error.new(PACTFLOW_NOT_SUPPORTED_MESSAGE)
63
+ else
64
+ raise PactBroker::Client::Error.new(NOT_SUPPORTED_MESSAGE)
65
+ end
61
66
  end
62
67
  end
63
68
  end
@@ -25,9 +25,8 @@ module PactBroker
25
25
  using PactBroker::Client::HashRefinements
26
26
 
27
27
  COMMAND = 'git rev-parse --abbrev-ref HEAD'.freeze
28
- BRANCH_ENV_VAR_NAMES = %w{BUILDKITE_BRANCH CIRCLE_BRANCH TRAVIS_BRANCH GIT_BRANCH GIT_LOCAL_BRANCH APPVEYOR_REPO_BRANCH CI_COMMIT_REF_NAME BITBUCKET_BRANCH}.freeze
29
- COMMIT_ENV_VAR_NAMES = %w{BUILDKITE_COMMIT CIRCLE_SHA1 TRAVIS_COMMIT GIT_COMMIT APPVEYOR_REPO_COMMIT CI_COMMIT_ID BITBUCKET_COMMIT}
30
-
28
+ BRANCH_ENV_VAR_NAMES = %w{GITHUB_REF BUILDKITE_BRANCH CIRCLE_BRANCH TRAVIS_BRANCH GIT_BRANCH GIT_LOCAL_BRANCH APPVEYOR_REPO_BRANCH CI_COMMIT_REF_NAME BITBUCKET_BRANCH}.freeze
29
+ COMMIT_ENV_VAR_NAMES = %w{GITHUB_SHA BUILDKITE_COMMIT CIRCLE_SHA1 TRAVIS_COMMIT GIT_COMMIT APPVEYOR_REPO_COMMIT CI_COMMIT_ID BITBUCKET_COMMIT}
31
30
  BUILD_URL_ENV_VAR_NAMES = %w{BUILDKITE_BUILD_URL CIRCLE_BUILD_URL TRAVIS_BUILD_WEB_URL BUILD_URL }
32
31
 
33
32
  def self.commit
@@ -38,6 +37,10 @@ module PactBroker
38
37
  find_branch_from_known_env_vars || find_branch_from_env_var_ending_with_branch || branch_from_git_command(options[:raise_error])
39
38
  end
40
39
 
40
+ def self.build_url
41
+ github_build_url || BUILD_URL_ENV_VAR_NAMES.collect{ | name | value_from_env_var(name) }.compact.first
42
+ end
43
+
41
44
  # private
42
45
 
43
46
  def self.find_commit_from_env_vars
@@ -45,7 +48,8 @@ module PactBroker
45
48
  end
46
49
 
47
50
  def self.find_branch_from_known_env_vars
48
- BRANCH_ENV_VAR_NAMES.collect { |env_var_name| value_from_env_var(env_var_name) }.compact.first
51
+ val = BRANCH_ENV_VAR_NAMES.collect { |env_var_name| value_from_env_var(env_var_name) }.compact.first
52
+ val.gsub(%r{^refs/heads/}, "") if val
49
53
  end
50
54
 
51
55
  def self.find_branch_from_env_var_ending_with_branch
@@ -104,6 +108,13 @@ module PactBroker
104
108
  return []
105
109
  end
106
110
  end
111
+
112
+ def self.github_build_url
113
+ parts = %w{GITHUB_SERVER_URL GITHUB_REPOSITORY GITHUB_RUN_ID}.collect{ | name | value_from_env_var(name) }
114
+ if parts.all?
115
+ [parts[0], parts[1], "actions", "runs", parts[2]].join("/")
116
+ end
117
+ end
107
118
  end
108
119
  end
109
120
  end
@@ -141,9 +141,9 @@ module PactBroker
141
141
  end
142
142
 
143
143
  def method_missing(method_name, *args, &block)
144
- if @data.key?(method_name.to_s)
144
+ if @data.respond_to?(:key?) && @data.key?(method_name.to_s)
145
145
  @data[method_name.to_s]
146
- elsif @links.key?(method_name)
146
+ elsif @links.respond_to?(:key?) && @links.key?(method_name)
147
147
  Link.new(@links[method_name], @client).run(*args)
148
148
  else
149
149
  nil