pact_broker 2.97.0 → 2.100.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +52 -0
  3. data/docs/CONFIGURATION.md +37 -5
  4. data/lib/pact_broker/api/decorators/reason_decorator.rb +1 -15
  5. data/lib/pact_broker/api/middleware/http_debug_logs.rb +13 -7
  6. data/lib/pact_broker/api/resources/base_resource.rb +4 -0
  7. data/lib/pact_broker/api/resources/deployed_version.rb +8 -2
  8. data/lib/pact_broker/api/resources/deployed_versions_for_version_and_environment.rb +1 -5
  9. data/lib/pact_broker/api/resources/latest_pacts.rb +1 -1
  10. data/lib/pact_broker/api/resources/pact.rb +0 -8
  11. data/lib/pact_broker/api/resources/pact_content_diff.rb +7 -2
  12. data/lib/pact_broker/api/resources/pact_versions.rb +1 -5
  13. data/lib/pact_broker/api/resources/pact_versions_for_branch.rb +1 -5
  14. data/lib/pact_broker/api/resources/pacticipant_resource_methods.rb +0 -1
  15. data/lib/pact_broker/api/resources/provider_pacts.rb +1 -1
  16. data/lib/pact_broker/api/resources/publish_contracts.rb +1 -1
  17. data/lib/pact_broker/api/resources/released_version.rb +8 -2
  18. data/lib/pact_broker/api/resources/released_versions_for_version_and_environment.rb +1 -1
  19. data/lib/pact_broker/api/resources/tagged_pact_versions.rb +1 -5
  20. data/lib/pact_broker/api/resources/verification.rb +0 -4
  21. data/lib/pact_broker/api/resources/verifications.rb +0 -4
  22. data/lib/pact_broker/api/resources/version.rb +8 -0
  23. data/lib/pact_broker/app.rb +2 -0
  24. data/lib/pact_broker/config/runtime_configuration.rb +4 -2
  25. data/lib/pact_broker/config/runtime_configuration_database_methods.rb +1 -1
  26. data/lib/pact_broker/contracts/contract_to_publish.rb +4 -0
  27. data/lib/pact_broker/contracts/contracts_to_publish.rb +4 -0
  28. data/lib/pact_broker/contracts/service.rb +23 -5
  29. data/lib/pact_broker/domain/tag.rb +8 -32
  30. data/lib/pact_broker/domain/version.rb +18 -10
  31. data/lib/pact_broker/locale/en.yml +7 -4
  32. data/lib/pact_broker/matrix/deployment_status_summary.rb +28 -19
  33. data/lib/pact_broker/matrix/every_row.rb +19 -1
  34. data/lib/pact_broker/matrix/integration.rb +5 -5
  35. data/lib/pact_broker/matrix/parse_query.rb +5 -0
  36. data/lib/pact_broker/matrix/quick_row.rb +41 -5
  37. data/lib/pact_broker/matrix/repository.rb +5 -3
  38. data/lib/pact_broker/matrix/resolved_selector.rb +47 -10
  39. data/lib/pact_broker/matrix/service.rb +4 -2
  40. data/lib/pact_broker/matrix/unresolved_selector.rb +14 -2
  41. data/lib/pact_broker/messages.rb +0 -15
  42. data/lib/pact_broker/pacticipants/service.rb +11 -1
  43. data/lib/pact_broker/pacts/create_formatted_diff.rb +1 -0
  44. data/lib/pact_broker/pacts/eager_loaders.rb +4 -1
  45. data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +25 -0
  46. data/lib/pact_broker/pacts/pact_publication_wip_dataset_module.rb +0 -15
  47. data/lib/pact_broker/pacts/verifiable_pact_messages.rb +4 -2
  48. data/lib/pact_broker/repositories/helpers.rb +13 -0
  49. data/lib/pact_broker/test/http_test_data_builder.rb +18 -2
  50. data/lib/pact_broker/ui/views/groups/show.html.erb +2 -2
  51. data/lib/pact_broker/ui/views/matrix/show.haml +5 -2
  52. data/lib/pact_broker/version.rb +1 -1
  53. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42a4c440061063f19b90c35a0d680f6d2a9802df42e3b4fc4b93031a6e8efb72
4
- data.tar.gz: 7e4acbf7aab9709d30db431a1fc2cee5048934f17170b76f5788ad9db9115e72
3
+ metadata.gz: f22862d2054c07b06fb947f8a1f710dab261ae6ac1207e6a15adebb07dc488db
4
+ data.tar.gz: 5cc63160ad026673f194af54237080aeb6eb8ab4f9ac93cbe5cd71b63727d60e
5
5
  SHA512:
6
- metadata.gz: c06b5cc6227a1141d5e5ccd02701096b4987d26860baf8836431317a26f7809fddefb41c355115bd485a39f8f44eee94884f164c36b7c8bbfacbaf0e62bd1e49
7
- data.tar.gz: 0c55019fbfb51cdb54bdc23896164a17621b927fed18eb5807cf5c4392723ec052baaff6aeabf61ed887e910eccd18afde0b7511349b2475b5cd3ec42ca4d4f6
6
+ metadata.gz: 8b6c0cefc1e4847ed53627f0b2aae7cfd5be46e351ce1969f21b80f5f8899990cca3f612d9ab14a82d58c0521b91fb5f5a820f4c7d9e72f17fbc391f1583daff
7
+ data.tar.gz: 4c1c3fa1a8e983718f1f841c8b17088678c6f4ada22c36b3ededb71a46c2bf004712c4716a8af33c17e068c88b88a6b69f219a286549841c20fa8c79ae41a214
data/CHANGELOG.md CHANGED
@@ -1,3 +1,55 @@
1
+ <a name="v2.100.0"></a>
2
+ ### v2.100.0 (2022-05-20)
3
+
4
+ #### Features
5
+
6
+ * check for potential duplicate pacticipants in publish contracts endpoint (#558) ([ed714f03](/../../commit/ed714f03))
7
+ * add support for "can i merge" matrix query ([bb108ed2](/../../commit/bb108ed2))
8
+ * remove inefficient skynet query for tags ([bdc2599c](/../../commit/bdc2599c))
9
+ * update text for matrix version description when no version is in an enviroment ([3eb5581d](/../../commit/3eb5581d))
10
+
11
+ * **pacts for verification**
12
+ * update wip and pending descriptions for wip pacts ([b06d4477](/../../commit/b06d4477))
13
+
14
+ * **matrix**
15
+ * add support for selectors specified by branch and environment name when reporting that a version does not exist ([07ff8044](/../../commit/07ff8044))
16
+
17
+ #### Bug Fixes
18
+
19
+ * **matrix**
20
+ * identify the correct failed version when a selector resolves to multiple versions ([11e7dc1c](/../../commit/11e7dc1c))
21
+
22
+ <a name="v2.99.0"></a>
23
+ ### v2.99.0 (2022-05-13)
24
+
25
+ #### Features
26
+
27
+ * remove disable_use_branch_heads_for_latest_branch_pacts feature toggle ([5c6f1766](/../../commit/5c6f1766))
28
+ * remove new_wip_calculation feature toggle ([add6cb08](/../../commit/add6cb08))
29
+ * timeout long running pact content diff requests (#555) ([88abb2cf](/../../commit/88abb2cf))
30
+ * change sql_log_level default from debug to none ([9f7aed46](/../../commit/9f7aed46))
31
+
32
+ #### Bug Fixes
33
+
34
+ * **ui**
35
+ * fix unescaped pacticipant name and main branch in details and network pages ([b8b1d306](/../../commit/b8b1d306))
36
+
37
+ * return a 400 when invalid JSON is used to create a version ([9af2cfaf](/../../commit/9af2cfaf))
38
+ * only log API requests/responses, not web assets, when http_debug_logging_enabled is true ([1f232c08](/../../commit/1f232c08))
39
+
40
+ * **matrix**
41
+ * fix performance issue when querying matrix with one selector ([3a08d128](/../../commit/3a08d128))
42
+
43
+ * **pacts for verification**
44
+ * return the pacts for the branch heads when using the branch selector ([6dac495e](/../../commit/6dac495e))
45
+
46
+ <a name="v2.98.0"></a>
47
+ ### v2.98.0 (2022-03-29)
48
+
49
+ #### Features
50
+
51
+ * support debug logging of entire request and response ([42eb4a17](/../../commit/42eb4a17))
52
+
1
53
  <a name="v2.97.0"></a>
2
54
  ### v2.97.0 (2022-03-29)
3
55
 
@@ -53,6 +53,18 @@ While the default is `file` for the Ruby application, it is set to `stdout` on t
53
53
  **Default:** `file`<br/>
54
54
  **Allowed values:** `stdout`, `file`<br/>
55
55
 
56
+ ### http_debug_logging_enabled
57
+
58
+ Enable this setting to print the entire request and response to the logs at debug level. Used for troubleshooting issues.
59
+ Do not leave this on permanently, as it will have performance and security issues.
60
+ Ensure the application [`log_level`](#log_level) is set to `debug` when this setting is enabled.
61
+
62
+ **Supported versions:** From v2.98.0<br/>
63
+ **Environment variable name:** `PACT_BROKER_HTTP_DEBUG_LOGGING_ENABLED`<br/>
64
+ **YAML configuration key name:** `http_debug_logging_enabled`<br/>
65
+ **Default:** `false`<br/>
66
+ **Allowed values:** `true`, `false`<br/>
67
+
56
68
  ### hide_pactflow_messages
57
69
 
58
70
  Set to `true` to hide the messages in the logs about Pactflow
@@ -145,7 +157,7 @@ To disable noisy SQL query logging when the application `log_level` is set to `d
145
157
 
146
158
  **Environment variable name:** `PACT_BROKER_SQL_LOG_LEVEL`<br/>
147
159
  **YAML configuration key name:** `sql_log_level`<br/>
148
- **Default:** `debug`<br/>
160
+ **Default:** From 2.99+, the default is `none`. In previous versions, the default is `debug`.<br/>
149
161
  **Allowed values:** `none`, `debug`, `info`, `warn`, `error`, `fatal`<br/>
150
162
 
151
163
  ### sql_log_warn_duration
@@ -422,8 +434,6 @@ chain in PEM format, indented by 2 more characters.
422
434
  When setting the path, the full path to the certificate file in PEM format must be specified. When using Docker, you must ensure the
423
435
  certificate file is [mounted into the container](https://docs.docker.com/storage/volumes/).
424
436
 
425
- *NOTE: USING ENVIRONMENT VARIABLES TO SET THE WEBHOOK CERTIFICATES IS NOT SUPPORTED.*
426
-
427
437
  YAML Example:
428
438
 
429
439
  ```yaml
@@ -436,11 +446,24 @@ webhook_certificates:
436
446
  jHT1Ty2CglM=
437
447
  -----END CERTIFICATE-----
438
448
  - description: "An example self signed certificate with a path"
439
- path: /full/path/to/the/cert.pem
449
+ path: "/full/path/to/the/cert.pem"
450
+
451
+ ```
440
452
 
453
+ Environment variable example:
454
+
455
+ ```shell
456
+ PACT_BROKER_WEBHOOK_CERTIFICATES__0__LABEL="An example self signed certificate with content"
457
+ PACT_BROKER_WEBHOOK_CERTIFICATES__0__CONTENT="-----BEGIN CERTIFICATE-----
458
+ MIIDZDCCAkygAwIBAgIBATANBgkqhkiG9w0BAQsFADBCMRMwEQYKCZImiZPyLGQB
459
+ <REST OF CERTIFICATE>
460
+ jHT1Ty2CglM=
461
+ -----END CERTIFICATE-----"
462
+ PACT_BROKER_WEBHOOK_CERTIFICATES__1__LABEL="An example self signed certificate with a path"
463
+ PACT_BROKER_WEBHOOK_CERTIFICATES__1__PATH="/full/path/to/the/cert.pem"
441
464
  ```
442
465
 
443
- **Supported versions:** From v2.90.0<br/>
466
+ **Supported versions:** From v2.90.0 for YAML and 2.97.0 for environment variables.<br/>
444
467
  **Environment variable name:** `PACT_BROKER_WEBHOOK_CERTIFICATES`<br/>
445
468
  **YAML configuration key name:** `webhook_certificates`<br/>
446
469
 
@@ -632,6 +655,15 @@ with a unique version number.
632
655
  **Allowed values:** `true`, `false`<br/>
633
656
  **More information:** https://docs.pact.io/versioning<br/>
634
657
 
658
+ ### pact_content_diff_timeout
659
+
660
+ The maximum amount of time in seconds to attempt to generate the diff between two pacts before aborting the request. This is required due to performance issues in the underlying diff generation code.
661
+
662
+ **Supported versions:** From 2.99.0<br/>
663
+ **Environment variable name:** `PACT_BROKER_PACT_CONTENT_DIFF_TIMEOUT`<br/>
664
+ **YAML configuration key name:** `pact_content_diff_timeout`<br/>
665
+ **Default:** `15`<br/>
666
+
635
667
  <br/>
636
668
 
637
669
  ## Miscellaneous
@@ -30,7 +30,7 @@ module PactBroker
30
30
  when PactBroker::Matrix::PactNotVerifiedByRequiredProviderVersion
31
31
  "There is no verified pact between #{reason.consumer_selector.description} and #{reason.provider_selector.description}"
32
32
  when PactBroker::Matrix::SpecifiedVersionDoesNotExist
33
- version_does_not_exist_description(reason.selector)
33
+ reason.selector.version_does_not_exist_description
34
34
  when PactBroker::Matrix::VerificationFailed
35
35
  "The verification for the pact between #{reason.consumer_selector.description} and #{reason.provider_selector.description} failed"
36
36
  when PactBroker::Matrix::NoDependenciesMissing
@@ -53,20 +53,6 @@ module PactBroker
53
53
  end
54
54
  end
55
55
 
56
- def version_does_not_exist_description selector
57
- if selector.version_does_not_exist?
58
- if selector.tag
59
- "No version with tag #{selector.tag} exists for #{selector.pacticipant_name}"
60
- elsif selector.pacticipant_version_number
61
- "No pacts or verifications have been published for version #{selector.pacticipant_version_number} of #{selector.pacticipant_name}"
62
- else
63
- "No pacts or verifications have been published for #{selector.pacticipant_name}"
64
- end
65
- else
66
- ""
67
- end
68
- end
69
-
70
56
  # TODO move this somewhere else
71
57
  def interaction_description(interaction)
72
58
  if interaction["providerState"] && interaction["providerState"] != ""
@@ -1,10 +1,12 @@
1
1
  require "pact_broker/logging"
2
+ require "rack/pact_broker/request_target"
2
3
 
3
4
  module PactBroker
4
5
  module Api
5
6
  module Middleware
6
7
  class HttpDebugLogs
7
8
  include PactBroker::Logging
9
+ include Rack::PactBroker::RequestTarget
8
10
 
9
11
  EXCLUDE_HEADERS = ["puma.", "rack.", "pactbroker."]
10
12
  RACK_SESSION = "rack.session"
@@ -15,13 +17,17 @@ module PactBroker
15
17
  end
16
18
 
17
19
  def call(env)
18
- env_to_log = env.reject { | header, _ | header.start_with?(*EXCLUDE_HEADERS) }
19
- env_to_log["rack.session"] = env["rack.session"].to_hash if env["rack.session"]
20
- env_to_log["rack.input"] = request_body(env) if env["rack.input"]
21
- logger.debug("env", payload: env_to_log)
22
- status, headers, body = @app.call(env)
23
- logger.debug("response", payload: { "status" => status, "headers" => headers, "body" => body })
24
- [status, headers, body]
20
+ if request_for_api?(env)
21
+ env_to_log = env.reject { | header, _ | header.start_with?(*EXCLUDE_HEADERS) }
22
+ env_to_log["rack.session"] = env["rack.session"].to_hash if env["rack.session"]
23
+ env_to_log["rack.input"] = request_body(env) if env["rack.input"]
24
+ logger.debug("env", payload: env_to_log)
25
+ status, headers, body = @app.call(env)
26
+ logger.debug("response", payload: { "status" => status, "headers" => headers, "body" => body })
27
+ [status, headers, body]
28
+ else
29
+ @app.call(env)
30
+ end
25
31
  end
26
32
 
27
33
  def request_body(env)
@@ -152,6 +152,10 @@ module PactBroker
152
152
  @request_body ||= request.body.to_s
153
153
  end
154
154
 
155
+ def any_request_body?
156
+ request_body && request_body.size > 0
157
+ end
158
+
155
159
  def consumer_name
156
160
  identifier_from_path[:consumer_name]
157
161
  end
@@ -58,11 +58,17 @@ module PactBroker
58
58
  end
59
59
 
60
60
  def policy_name
61
- :'versions::version'
61
+ :'versions::deployed_version'
62
+ end
63
+
64
+ def policy_record_context
65
+ {
66
+ pacticipant: deployed_version&.pacticipant
67
+ }
62
68
  end
63
69
 
64
70
  def policy_record
65
- deployed_version&.version
71
+ deployed_version&.environment
66
72
  end
67
73
 
68
74
  private
@@ -40,11 +40,7 @@ module PactBroker
40
40
  end
41
41
 
42
42
  def policy_name
43
- :'versions::deployed_version'
44
- end
45
-
46
- def policy_record
47
- environment
43
+ :'versions::deployed_versions'
48
44
  end
49
45
 
50
46
  private
@@ -22,7 +22,7 @@ module PactBroker
22
22
  end
23
23
 
24
24
  def policy_name
25
- :'pacts::pacts'
25
+ :'pacts::latest_pacts'
26
26
  end
27
27
  end
28
28
  end
@@ -94,14 +94,6 @@ module PactBroker
94
94
  :'pacts::pact'
95
95
  end
96
96
 
97
- def policy_pacticipant
98
- if resource_exists?
99
- consumer
100
- else
101
- nil
102
- end
103
- end
104
-
105
97
  private
106
98
 
107
99
  def pact
@@ -1,6 +1,7 @@
1
1
  require "pact_broker/api/resources/base_resource"
2
2
  require "pact_broker/pacts/pact_params"
3
3
  require "pact_broker/pacts/diff"
4
+ require "timeout"
4
5
 
5
6
  module PactBroker
6
7
  module Api
@@ -19,8 +20,12 @@ module PactBroker
19
20
  end
20
21
 
21
22
  def to_text
22
- output = PactBroker::Pacts::Diff.new.process pact_params.merge(base_url: base_url), comparison_pact_params, raw: false
23
- response.body = output
23
+ Timeout::timeout(PactBroker.configuration.pact_content_diff_timeout) do
24
+ output = PactBroker::Pacts::Diff.new.process pact_params.merge(base_url: base_url), comparison_pact_params, raw: false
25
+ response.body = output
26
+ end
27
+ rescue Timeout::Error
28
+ 408
24
29
  end
25
30
 
26
31
  def pact
@@ -32,11 +32,7 @@ module PactBroker
32
32
  end
33
33
 
34
34
  def policy_name
35
- :'pacts::pacts'
36
- end
37
-
38
- def policy_pacticipant
39
- consumer
35
+ :'pacts::pact_versions'
40
36
  end
41
37
  end
42
38
  end
@@ -28,11 +28,7 @@ module PactBroker
28
28
  end
29
29
 
30
30
  def policy_name
31
- :'pacts::pacts'
32
- end
33
-
34
- def policy_pacticipant
35
- consumer
31
+ :'pacts::pact_versions'
36
32
  end
37
33
  end
38
34
  end
@@ -1,7 +1,6 @@
1
1
  module PactBroker
2
2
  module Api
3
3
  module Resources
4
-
5
4
  module PacticipantResourceMethods
6
5
 
7
6
  def potential_duplicate_pacticipants? pacticipant_names
@@ -20,7 +20,7 @@ module PactBroker
20
20
  end
21
21
 
22
22
  def policy_name
23
- :'pacts::pacts'
23
+ :'pacts::provider_pacts'
24
24
  end
25
25
 
26
26
  def to_json
@@ -100,7 +100,7 @@ module PactBroker
100
100
  end
101
101
 
102
102
  def conflict_notices
103
- @conflict_notices ||= contract_service.conflict_notices(parsed_contracts)
103
+ @conflict_notices ||= contract_service.conflict_notices(parsed_contracts, base_url: base_url)
104
104
  end
105
105
 
106
106
  def base64_decode(content)
@@ -48,11 +48,17 @@ module PactBroker
48
48
  end
49
49
 
50
50
  def policy_name
51
- :'versions::version'
51
+ :'versions::released_version'
52
+ end
53
+
54
+ def policy_record_context
55
+ {
56
+ pacticipant: released_version&.pacticipant
57
+ }
52
58
  end
53
59
 
54
60
  def policy_record
55
- released_version&.version
61
+ released_version&.environment
56
62
  end
57
63
 
58
64
  private
@@ -45,7 +45,7 @@ module PactBroker
45
45
  end
46
46
 
47
47
  def policy_name
48
- :'versions::released_version'
48
+ :'versions::released_versions'
49
49
  end
50
50
 
51
51
  def policy_record
@@ -36,11 +36,7 @@ module PactBroker
36
36
  end
37
37
 
38
38
  def policy_name
39
- :'pacts::pacts'
40
- end
41
-
42
- def policy_pacticipant
43
- consumer
39
+ :'pacts::pact_versions'
44
40
  end
45
41
  end
46
42
  end
@@ -54,10 +54,6 @@ module PactBroker
54
54
  :'verifications::verification'
55
55
  end
56
56
 
57
- def policy_pacticipant
58
- provider
59
- end
60
-
61
57
  private
62
58
 
63
59
  def verification
@@ -62,10 +62,6 @@ module PactBroker
62
62
  :'verifications::verifications'
63
63
  end
64
64
 
65
- def policy_pacticipant
66
- provider
67
- end
68
-
69
65
  private
70
66
 
71
67
  def pact
@@ -25,6 +25,14 @@ module PactBroker
25
25
  !!version
26
26
  end
27
27
 
28
+ def malformed_request?
29
+ if request.put? && any_request_body?
30
+ invalid_json?
31
+ else
32
+ false
33
+ end
34
+ end
35
+
28
36
  def from_json
29
37
  if request.really_put?
30
38
  handle_request do
@@ -29,6 +29,7 @@ require "pact_broker/api/middleware/configuration"
29
29
  require "pact_broker/api/middleware/basic_auth"
30
30
  require "pact_broker/config/basic_auth_configuration"
31
31
  require "pact_broker/api/authorization/resource_access_policy"
32
+ require "pact_broker/api/middleware/http_debug_logs"
32
33
 
33
34
  module PactBroker
34
35
 
@@ -174,6 +175,7 @@ module PactBroker
174
175
  end
175
176
 
176
177
  def configure_middleware
178
+ @app_builder.use PactBroker::Api::Middleware::HttpDebugLogs if configuration.http_debug_logging_enabled
177
179
  configure_basic_auth
178
180
  configure_rack_protection
179
181
  @app_builder.use Rack::PactBroker::InvalidUriProtection
@@ -39,7 +39,8 @@ module PactBroker
39
39
  log_format: nil,
40
40
  warning_error_class_names: ["Sequel::ForeignKeyConstraintViolation"],
41
41
  hide_pactflow_messages: false,
42
- log_configuration_on_startup: true
42
+ log_configuration_on_startup: true,
43
+ http_debug_logging_enabled: false
43
44
  )
44
45
 
45
46
  on_load :validate_logging_attributes!
@@ -70,7 +71,8 @@ module PactBroker
70
71
  badge_provider_mode: :redirect,
71
72
  enable_public_badge_access: false,
72
73
  shields_io_base_url: "https://img.shields.io",
73
- use_case_sensitive_resource_names: true
74
+ use_case_sensitive_resource_names: true,
75
+ pact_content_diff_timeout: 15
74
76
  )
75
77
 
76
78
  # domain attributes
@@ -16,7 +16,7 @@ module PactBroker
16
16
  database_port: nil,
17
17
  database_url: nil,
18
18
  database_sslmode: nil,
19
- sql_log_level: :debug,
19
+ sql_log_level: :none,
20
20
  sql_log_warn_duration: 5,
21
21
  sql_enable_caller_logging: false,
22
22
  database_max_connections: nil,
@@ -14,6 +14,10 @@ module PactBroker
14
14
  def merge?
15
15
  on_conflict == "merge"
16
16
  end
17
+
18
+ def pacticipant_names
19
+ [consumer_name, provider_name]
20
+ end
17
21
  end
18
22
  end
19
23
  end
@@ -6,6 +6,10 @@ module PactBroker
6
6
  new(pacticipant_name, pacticipant_version_number, tags, branch, build_url, contracts)
7
7
  end
8
8
  # rubocop: enable Metrics/ParameterLists
9
+
10
+ def pacticipant_names
11
+ contracts.flat_map(&:pacticipant_names).uniq
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -43,19 +43,26 @@ module PactBroker
43
43
  )
44
44
  end
45
45
 
46
- def conflict_notices(parsed_contracts)
46
+ def conflict_notices(parsed_contracts, base_url: )
47
47
  notices = []
48
+ add_pact_conflict_notices(notices, parsed_contracts)
49
+ add_pacticipant_conflict_notices(notices, parsed_contracts, base_url)
50
+ notices
51
+ end
52
+
53
+ def add_pact_conflict_notices(notices, parsed_contracts)
48
54
  parsed_contracts.contracts.collect do | contract_to_publish |
49
55
  pact_params = create_pact_params(parsed_contracts, contract_to_publish)
50
56
  existing_pact = pact_service.find_pact(pact_params)
51
57
  if existing_pact && pact_service.disallowed_modification?(existing_pact, contract_to_publish.decoded_content)
52
- add_conflict_notice(notices, parsed_contracts, contract_to_publish, existing_pact.json_content, contract_to_publish.decoded_content)
58
+ add_pact_conflict_notice(notices, parsed_contracts, contract_to_publish, existing_pact.json_content, contract_to_publish.decoded_content)
53
59
  end
54
60
  end
55
- notices
56
61
  end
57
62
 
58
- def add_conflict_notice(notices, parsed_contracts, contract_to_publish, existing_json_content, new_json_content)
63
+ private :add_pact_conflict_notices
64
+
65
+ def add_pact_conflict_notice(notices, parsed_contracts, contract_to_publish, existing_json_content, new_json_content)
59
66
  message_params = {
60
67
  consumer_name: contract_to_publish.provider_name,
61
68
  consumer_version_number: parsed_contracts.pacticipant_version_number,
@@ -65,7 +72,18 @@ module PactBroker
65
72
  notices << Notice.info(PactBroker::Pacts::CreateFormattedDiff.call(new_json_content, existing_json_content))
66
73
  end
67
74
 
68
- private :add_conflict_notice
75
+ private :add_pact_conflict_notice
76
+
77
+ def add_pacticipant_conflict_notices(notices, parsed_contracts, base_url)
78
+ if PactBroker.configuration.check_for_potential_duplicate_pacticipant_names
79
+ duplicate_pacticipant_messages = pacticipant_service.messages_for_potential_duplicate_pacticipants(parsed_contracts.pacticipant_names, base_url)
80
+ duplicate_pacticipant_messages.each do | message_text |
81
+ notices << Notice.error(message_text)
82
+ end
83
+ end
84
+ end
85
+
86
+ private :add_pacticipant_conflict_notices
69
87
 
70
88
  def create_version(parsed_contracts)
71
89
  version_params = {
@@ -39,53 +39,28 @@ module PactBroker
39
39
  end
40
40
 
41
41
  def latest_tags
42
- self_join = {
43
- Sequel[:tags][:pacticipant_id] => Sequel[:tags_2][:pacticipant_id],
44
- Sequel[:tags][:name] => Sequel[:tags_2][:name]
45
- }
46
-
47
- PactBroker::Domain::Tag
42
+ Tag
48
43
  .select_all_qualified
49
- .left_join(:tags, self_join, { table_alias: :tags_2 }) do
50
- Sequel[:tags_2][:version_order] > Sequel[:tags][:version_order]
51
- end
52
- .where(Sequel[:tags_2][:name] => nil)
44
+ .max_group_by(:version_order, [:pacticipant_id, :name])
53
45
  end
54
46
 
55
47
  # Does NOT care about whether or not there is a pact publication
56
48
  # for the version
57
49
  def latest_tags_for_pacticipant_ids(pacticipant_ids)
58
- self_join = {
59
- Sequel[:tags][:pacticipant_id] => Sequel[:tags_2][:pacticipant_id],
60
- Sequel[:tags][:name] => Sequel[:tags_2][:name],
61
- Sequel[:tags_2][:pacticipant_id] => pacticipant_ids,
62
- }
63
-
64
50
  Tag
65
51
  .select_all_qualified
66
- .left_join(:tags, self_join, { table_alias: :tags_2 }) do
67
- Sequel[:tags_2][:version_order] > Sequel[:tags][:version_order]
52
+ .max_group_by(:version_order, [:pacticipant_id, :name]) do | ds |
53
+ ds.where(Sequel[:tags][:pacticipant_id] => pacticipant_ids)
68
54
  end
69
- .where(Sequel[:tags_2][:name] => nil)
70
- .where(Sequel[:tags][:pacticipant_id] => pacticipant_ids)
71
55
  end
72
56
 
73
57
  def latest_tags_for_pacticipant_ids_and_tag_names(pacticipant_ids, tag_names)
74
- self_join = {
75
- Sequel[:tags][:pacticipant_id] => Sequel[:tags_2][:pacticipant_id],
76
- Sequel[:tags][:name] => Sequel[:tags_2][:name],
77
- Sequel[:tags_2][:pacticipant_id] => pacticipant_ids,
78
- Sequel[:tags_2][:name] => tag_names
79
- }
80
-
81
58
  Tag
82
59
  .select_all_qualified
83
- .left_join(:tags, self_join, { table_alias: :tags_2 }) do
84
- Sequel[:tags_2][:version_order] > Sequel[:tags][:version_order]
60
+ .max_group_by(:version_order, [:pacticipant_id, :name]) do | ds |
61
+ ds.where(Sequel[:tags][:name] => tag_names)
62
+ .where(Sequel[:tags][:pacticipant_id] => pacticipant_ids)
85
63
  end
86
- .where(Sequel[:tags_2][:name] => nil)
87
- .where(Sequel[:tags][:pacticipant_id] => pacticipant_ids)
88
- .where(Sequel[:tags][:name] => tag_names)
89
64
  end
90
65
 
91
66
  # ignores tags that don't have a pact publication
@@ -110,6 +85,7 @@ module PactBroker
110
85
  .join(lp, versions_pact_publications_join)
111
86
  end
112
87
 
88
+ # TODO convert this to use max and join
113
89
  def head_tags_for_pact_publication(pact_publication)
114
90
  Tag.where(version_id: pact_publication.consumer_version_id).all.select do | tag |
115
91
  tag_pp_join = {