pact_broker 2.99.0 → 2.102.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -0
  3. data/Gemfile +1 -0
  4. data/README.md +14 -4
  5. data/db/migrations/20220622_default_allow_dangerous_contract_modification_to_false_for_new_installations.rb +22 -0
  6. data/db/migrations/20220625_delete_pacticipants_with_no_name.rb +62 -0
  7. data/db/migrations/migration_helper.rb +6 -0
  8. data/docs/CONFIGURATION.md +3 -1
  9. data/docs/api/PACTICIPANTS.md +290 -0
  10. data/docs/api/WEBHOOKS.md +40 -40
  11. data/lib/pact_broker/api/contracts/pacticipant_create_schema.rb +28 -0
  12. data/lib/pact_broker/api/decorators/embedded_version_decorator.rb +0 -1
  13. data/lib/pact_broker/api/decorators/reason_decorator.rb +1 -15
  14. data/lib/pact_broker/api/decorators/triggered_webhook_decorator.rb +1 -2
  15. data/lib/pact_broker/api/resources/all_webhooks.rb +1 -4
  16. data/lib/pact_broker/api/resources/base_resource.rb +58 -5
  17. data/lib/pact_broker/api/resources/branch_version.rb +10 -1
  18. data/lib/pact_broker/api/resources/clean.rb +11 -9
  19. data/lib/pact_broker/api/resources/currently_deployed_versions_for_environment.rb +0 -4
  20. data/lib/pact_broker/api/resources/currently_supported_versions_for_environment.rb +0 -4
  21. data/lib/pact_broker/api/resources/deployed_version.rb +20 -16
  22. data/lib/pact_broker/api/resources/deployed_versions_for_version_and_environment.rb +1 -1
  23. data/lib/pact_broker/api/resources/environment.rb +5 -5
  24. data/lib/pact_broker/api/resources/environments.rb +1 -5
  25. data/lib/pact_broker/api/resources/label.rb +4 -0
  26. data/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb +10 -0
  27. data/lib/pact_broker/api/resources/pact.rb +14 -5
  28. data/lib/pact_broker/api/resources/pact_webhooks.rb +1 -4
  29. data/lib/pact_broker/api/resources/pacticipant.rb +11 -5
  30. data/lib/pact_broker/api/resources/pacticipant_resource_methods.rb +0 -1
  31. data/lib/pact_broker/api/resources/pacticipant_webhooks.rb +1 -4
  32. data/lib/pact_broker/api/resources/pacticipants.rb +7 -6
  33. data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +19 -11
  34. data/lib/pact_broker/api/resources/publish_contracts.rb +12 -16
  35. data/lib/pact_broker/api/resources/released_version.rb +20 -8
  36. data/lib/pact_broker/api/resources/released_versions_for_version_and_environment.rb +11 -7
  37. data/lib/pact_broker/api/resources/tag.rb +7 -3
  38. data/lib/pact_broker/api/resources/verifications.rb +7 -9
  39. data/lib/pact_broker/api/resources/version.rb +8 -8
  40. data/lib/pact_broker/api/resources/webhook.rb +5 -4
  41. data/lib/pact_broker/api/resources/webhook_execution.rb +4 -6
  42. data/lib/pact_broker/config/runtime_configuration.rb +1 -1
  43. data/lib/pact_broker/contracts/contract_to_publish.rb +4 -0
  44. data/lib/pact_broker/contracts/contracts_to_publish.rb +4 -0
  45. data/lib/pact_broker/contracts/service.rb +23 -5
  46. data/lib/pact_broker/doc/views/index/pacticipant-branch-version.markdown +13 -2
  47. data/lib/pact_broker/doc/views/provider-pacts-for-verification.markdown +1 -1
  48. data/lib/pact_broker/domain/pacticipant.rb +1 -0
  49. data/lib/pact_broker/domain/tag.rb +8 -32
  50. data/lib/pact_broker/domain/verification.rb +3 -2
  51. data/lib/pact_broker/domain/version.rb +26 -10
  52. data/lib/pact_broker/locale/en.yml +8 -4
  53. data/lib/pact_broker/matrix/deployment_status_summary.rb +28 -19
  54. data/lib/pact_broker/matrix/parse_query.rb +5 -0
  55. data/lib/pact_broker/matrix/quick_row.rb +5 -2
  56. data/lib/pact_broker/matrix/repository.rb +3 -3
  57. data/lib/pact_broker/matrix/resolved_selector.rb +47 -10
  58. data/lib/pact_broker/matrix/service.rb +17 -7
  59. data/lib/pact_broker/matrix/unresolved_selector.rb +14 -2
  60. data/lib/pact_broker/messages.rb +0 -15
  61. data/lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb +3 -3
  62. data/lib/pact_broker/pacticipants/repository.rb +5 -4
  63. data/lib/pact_broker/pacticipants/service.rb +11 -1
  64. data/lib/pact_broker/pacts/generate_sha.rb +1 -0
  65. data/lib/pact_broker/pacts/pact_version.rb +1 -0
  66. data/lib/pact_broker/pacts/verifiable_pact_messages.rb +4 -2
  67. data/lib/pact_broker/repositories/helpers.rb +13 -0
  68. data/lib/pact_broker/string_refinements.rb +8 -0
  69. data/lib/pact_broker/test/http_test_data_builder.rb +15 -0
  70. data/lib/pact_broker/test/test_data_builder.rb +20 -0
  71. data/lib/pact_broker/ui/controllers/index.rb +3 -1
  72. data/lib/pact_broker/ui/views/index/show.haml +3 -4
  73. data/lib/pact_broker/ui/views/matrix/show.haml +5 -2
  74. data/lib/pact_broker/verifications/pact_version_provider_tag_successful_verification.rb +15 -0
  75. data/lib/pact_broker/version.rb +1 -1
  76. data/lib/pact_broker/versions/branch_service.rb +7 -0
  77. data/lib/pact_broker/versions/branch_version_repository.rb +17 -0
  78. data/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +1 -1
  79. data/lib/rack/pact_broker/cascade.rb +87 -0
  80. data/lib/webmachine/describe_routes.rb +43 -9
  81. metadata +8 -5
  82. data/lib/db.rb +0 -79
  83. data/lib/pact_broker/api/resources/default_base_resource.rb +0 -0
@@ -27,11 +27,7 @@ module PactBroker
27
27
  end
28
28
 
29
29
  def malformed_request?
30
- if request.post?
31
- invalid_json? || validation_errors_for_schema?(schema, params.merge(uuid: uuid))
32
- else
33
- false
34
- end
30
+ super || (request.post? && validation_errors_for_schema?(schema, params.merge(uuid: uuid)))
35
31
  end
36
32
 
37
33
  def create_path
@@ -17,6 +17,10 @@ module PactBroker
17
17
  ["GET", "PUT", "DELETE", "OPTIONS"]
18
18
  end
19
19
 
20
+ def put_can_create?
21
+ true
22
+ end
23
+
20
24
  def from_json
21
25
  unless label
22
26
  @label = label_service.create(identifier_from_path)
@@ -23,6 +23,16 @@ module PactBroker
23
23
  consumer && provider
24
24
  end
25
25
 
26
+ def malformed_request?
27
+ error_messages = matrix_service.validate_options(options)
28
+ if error_messages.any?
29
+ set_json_validation_error_messages error_messages
30
+ true
31
+ else
32
+ false
33
+ end
34
+ end
35
+
26
36
  def to_json
27
37
  decorator_class(:matrix_decorator).new(results).to_json(decorator_options)
28
38
  end
@@ -36,18 +36,27 @@ module PactBroker
36
36
  ["GET", "PUT", "DELETE", "PATCH", "OPTIONS"]
37
37
  end
38
38
 
39
+ def request_body_required?
40
+ request.put? || request.patch?
41
+ end
42
+
43
+ def put_can_create?
44
+ true
45
+ end
46
+
47
+ def patch_can_create?
48
+ true
49
+ end
50
+
39
51
  def is_conflict?
40
52
  merge_conflict = request.patch? && resource_exists? && Pacts::Merger.conflict?(pact.json_content, pact_params.json_content)
41
53
 
42
54
  potential_duplicate_pacticipants?(pact_params.pacticipant_names) || merge_conflict || disallowed_modification?
43
55
  end
44
56
 
57
+
45
58
  def malformed_request?
46
- if request.patch? || request.put?
47
- invalid_json? || contract_validation_errors?(Contracts::PutPactParamsContract.new(pact_params), pact_params)
48
- else
49
- false
50
- end
59
+ super || ((request.patch? || request.really_put?) && contract_validation_errors?(Contracts::PutPactParamsContract.new(pact_params), pact_params))
51
60
  end
52
61
 
53
62
  def resource_exists?
@@ -25,10 +25,7 @@ module PactBroker
25
25
  end
26
26
 
27
27
  def malformed_request?
28
- if request.post?
29
- return invalid_json? || validation_errors?(webhook)
30
- end
31
- false
28
+ super || (request.post? && validation_errors?(webhook))
32
29
  end
33
30
 
34
31
  def validation_errors? webhook
@@ -21,18 +21,23 @@ module PactBroker
21
21
  ["GET", "PUT", "PATCH", "DELETE", "OPTIONS"]
22
22
  end
23
23
 
24
+ def put_can_create?
25
+ false
26
+ end
27
+
28
+ def patch_can_create?
29
+ true
30
+ end
31
+
24
32
  def known_methods
25
33
  super + ["PATCH"]
26
34
  end
27
35
 
28
36
  def malformed_request?
29
- if request.patch? || request.put?
30
- invalid_json? || validation_errors_for_schema?
31
- else
32
- false
33
- end
37
+ super || ((request.patch? || request.really_put?) && any_request_body? && validation_errors_for_schema?)
34
38
  end
35
39
 
40
+ # PUT or PATCH with content-type application/json
36
41
  def from_json
37
42
  if pacticipant
38
43
  @pacticipant = update_existing_pacticipant
@@ -47,6 +52,7 @@ module PactBroker
47
52
  response.body = to_json
48
53
  end
49
54
 
55
+ # PUT or PATCH with content-type application/merge-patch+json
50
56
  def from_merge_patch_json
51
57
  if request.patch?
52
58
  from_json
@@ -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
@@ -27,10 +27,7 @@ module PactBroker
27
27
  end
28
28
 
29
29
  def malformed_request?
30
- if request.post?
31
- return invalid_json? || webhook_validation_errors?(webhook)
32
- end
33
- false
30
+ super || (request.post? && webhook_validation_errors?(webhook))
34
31
  end
35
32
 
36
33
  def create_path
@@ -2,7 +2,7 @@ require "pact_broker/api/resources/base_resource"
2
2
  require "pact_broker/api/decorators/pacticipant_decorator"
3
3
  require "pact_broker/domain/pacticipant"
4
4
  require "pact_broker/hash_refinements"
5
- require "pact_broker/api/contracts/pacticipant_schema"
5
+ require "pact_broker/api/contracts/pacticipant_create_schema"
6
6
 
7
7
  module PactBroker
8
8
  module Api
@@ -23,10 +23,11 @@ module PactBroker
23
23
  end
24
24
 
25
25
  def malformed_request?
26
- if request.post?
27
- return invalid_json? || validation_errors_for_schema?
28
- end
29
- false
26
+ super || (request.post? && validation_errors_for_schema?)
27
+ end
28
+
29
+ def request_body_required?
30
+ request.post?
30
31
  end
31
32
 
32
33
  def post_is_create?
@@ -65,7 +66,7 @@ module PactBroker
65
66
  private
66
67
 
67
68
  def schema
68
- PactBroker::Api::Contracts::PacticipantSchema
69
+ PactBroker::Api::Contracts::PacticipantCreateSchema
69
70
  end
70
71
 
71
72
  def pacticipants
@@ -11,28 +11,27 @@ module PactBroker
11
11
  class ProviderPactsForVerification < ProviderPacts
12
12
  using PactBroker::HashRefinements
13
13
 
14
+ def content_types_provided
15
+ [["application/hal+json", :to_json]]
16
+ end
17
+
14
18
  def allowed_methods
15
19
  ["GET", "POST", "OPTIONS"]
16
20
  end
17
21
 
18
- def content_types_accepted
19
- [["application/json"]]
22
+ def malformed_request?
23
+ super || ((request.get? || (request.post? && content_type_json?)) && schema_validation_errors?)
20
24
  end
21
25
 
22
- def malformed_request?
23
- if (errors = query_schema.call(query)).any?
24
- set_json_validation_error_messages(errors)
26
+ def process_post
27
+ if content_type_json?
28
+ response.body = to_json
25
29
  true
26
30
  else
27
- false
31
+ 415
28
32
  end
29
33
  end
30
34
 
31
- def process_post
32
- response.body = to_json
33
- true
34
- end
35
-
36
35
  def read_methods
37
36
  super + %w{POST}
38
37
  end
@@ -96,6 +95,15 @@ module PactBroker
96
95
  def nested_query
97
96
  @nested_query ||= Rack::Utils.parse_nested_query(request.uri.query)
98
97
  end
98
+
99
+ def schema_validation_errors?
100
+ if (errors = query_schema.call(query)).any?
101
+ set_json_validation_error_messages(errors)
102
+ true
103
+ else
104
+ false
105
+ end
106
+ end
99
107
  end
100
108
  end
101
109
  end
@@ -11,11 +11,7 @@ module PactBroker
11
11
  include WebhookExecutionMethods
12
12
 
13
13
  def content_types_provided
14
- [["application/hal+json", :to_json]]
15
- end
16
-
17
- def content_types_accepted
18
- [["application/json"]]
14
+ [["application/hal+json"]]
19
15
  end
20
16
 
21
17
  def allowed_methods
@@ -23,20 +19,20 @@ module PactBroker
23
19
  end
24
20
 
25
21
  def malformed_request?
26
- if request.post?
27
- invalid_json? || validation_errors_for_schema?
28
- else
29
- false
30
- end
22
+ super || (request.post? && content_type_json? && validation_errors_for_schema?)
31
23
  end
32
24
 
33
25
  def process_post
34
- if conflict_notices.any?
35
- set_conflict_response
36
- 409
26
+ if content_type_json?
27
+ if conflict_notices.any?
28
+ set_conflict_response
29
+ 409
30
+ else
31
+ publish_contracts
32
+ true
33
+ end
37
34
  else
38
- publish_contracts
39
- true
35
+ 415
40
36
  end
41
37
  end
42
38
 
@@ -100,7 +96,7 @@ module PactBroker
100
96
  end
101
97
 
102
98
  def conflict_notices
103
- @conflict_notices ||= contract_service.conflict_notices(parsed_contracts)
99
+ @conflict_notices ||= contract_service.conflict_notices(parsed_contracts, base_url: base_url)
104
100
  end
105
101
 
106
102
  def base64_decode(content)
@@ -8,11 +8,6 @@ module PactBroker
8
8
  class ReleasedVersion < BaseResource
9
9
  include PactBroker::Messages
10
10
 
11
- def initialize
12
- super
13
- @currently_supported_param = params(default: {})[:currentlySupported]
14
- end
15
-
16
11
  def content_types_provided
17
12
  [["application/hal+json", :to_json]]
18
13
  end
@@ -27,6 +22,10 @@ module PactBroker
27
22
  ["GET", "PATCH", "OPTIONS"]
28
23
  end
29
24
 
25
+ def patch_can_create?
26
+ false
27
+ end
28
+
30
29
  def resource_exists?
31
30
  !!released_version
32
31
  end
@@ -48,16 +47,29 @@ module PactBroker
48
47
  end
49
48
 
50
49
  def policy_name
51
- :'versions::version'
50
+ :'versions::released_version'
51
+ end
52
+
53
+ def policy_record_context
54
+ {
55
+ pacticipant: released_version&.pacticipant
56
+ }
52
57
  end
53
58
 
54
59
  def policy_record
55
- released_version&.version
60
+ released_version&.environment
56
61
  end
57
62
 
58
63
  private
59
64
 
60
- attr_reader :currently_supported_param
65
+ # can't use ||= with a potentially nil value
66
+ def currently_supported_param
67
+ if defined?(@currently_deployed_param)
68
+ @currently_supported_param
69
+ else
70
+ @currently_supported_param = params(default: {})[:currentlySupported]
71
+ end
72
+ end
61
73
 
62
74
  def process_currently_supported_param
63
75
  if currently_supported_param == false
@@ -5,11 +5,6 @@ module PactBroker
5
5
  module Api
6
6
  module Resources
7
7
  class ReleasedVersionsForVersionAndEnvironment < BaseResource
8
- def initialize
9
- super
10
- @existing_released_version = version && environment && released_version_service.find_released_version_for_version_and_environment(version, environment)
11
- end
12
-
13
8
  def content_types_accepted
14
9
  [["application/json", :from_json]]
15
10
  end
@@ -35,6 +30,7 @@ module PactBroker
35
30
  end
36
31
 
37
32
  def from_json
33
+ existing_released_version # make sure we have this before we update the database
38
34
  @released_version = released_version_service.create_or_update(next_released_version_uuid, version, environment)
39
35
  response.body = decorator_class(:released_version_decorator).new(released_version).to_json(decorator_options)
40
36
  true
@@ -45,7 +41,7 @@ module PactBroker
45
41
  end
46
42
 
47
43
  def policy_name
48
- :'versions::released_version'
44
+ :'versions::released_versions'
49
45
  end
50
46
 
51
47
  def policy_record
@@ -61,7 +57,15 @@ module PactBroker
61
57
 
62
58
  private
63
59
 
64
- attr_reader :released_version, :existing_released_version
60
+ attr_reader :released_version
61
+
62
+ def existing_released_version
63
+ if defined?(@existing_released_version)
64
+ @existing_released_version
65
+ else
66
+ @existing_released_version = version && environment && released_version_service.find_released_version_for_version_and_environment(version, environment)
67
+ end
68
+ end
65
69
 
66
70
  def version
67
71
  @version ||= version_service.find_by_pacticipant_name_and_number(identifier_from_path)
@@ -17,9 +17,13 @@ module PactBroker
17
17
  ["GET","PUT","DELETE", "OPTIONS"]
18
18
  end
19
19
 
20
+ def put_can_create?
21
+ true
22
+ end
23
+
20
24
  def from_json
21
25
  unless tag
22
- @tag = tag_service.create identifier_from_path
26
+ @tag = tag_service.create(identifier_from_path)
23
27
  # Make it return a 201 by setting the Location header
24
28
  response.headers["Location"] = tag_url(base_url, tag)
25
29
  end
@@ -36,11 +40,11 @@ module PactBroker
36
40
  end
37
41
 
38
42
  def tag
39
- @tag ||= tag_service.find identifier_from_path
43
+ @tag ||= tag_service.find(identifier_from_path)
40
44
  end
41
45
 
42
46
  def delete_resource
43
- tag_service.delete identifier_from_path
47
+ tag_service.delete(identifier_from_path)
44
48
  true
45
49
  end
46
50
 
@@ -34,15 +34,7 @@ module PactBroker
34
34
  end
35
35
 
36
36
  def malformed_request?
37
- if request.post?
38
- return true if invalid_json?
39
- errors = verification_service.errors(params)
40
- if !errors.empty?
41
- set_json_validation_error_messages(errors.messages)
42
- return true
43
- end
44
- end
45
- false
37
+ super || (request.post? && any_validation_errors?)
46
38
  end
47
39
 
48
40
  def create_path
@@ -91,6 +83,12 @@ module PactBroker
91
83
  def verification_params
92
84
  params(symbolize_names: false).merge("wip" => wip?, "pending" => pending?)
93
85
  end
86
+
87
+ def any_validation_errors?
88
+ errors = verification_service.errors(params)
89
+ set_json_validation_error_messages(errors.messages) if !errors.empty?
90
+ !errors.empty?
91
+ end
94
92
  end
95
93
  end
96
94
  end
@@ -21,16 +21,16 @@ module PactBroker
21
21
  ["GET", "PUT", "PATCH", "DELETE", "OPTIONS"]
22
22
  end
23
23
 
24
- def resource_exists?
25
- !!version
24
+ def put_can_create?
25
+ true
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
28
+ def patch_can_create?
29
+ true
30
+ end
31
+
32
+ def resource_exists?
33
+ !!version
34
34
  end
35
35
 
36
36
  def from_json
@@ -22,15 +22,16 @@ module PactBroker
22
22
  ["GET", "PUT", "DELETE", "OPTIONS"]
23
23
  end
24
24
 
25
+ def put_can_create?
26
+ true
27
+ end
28
+
25
29
  def resource_exists?
26
30
  !!webhook
27
31
  end
28
32
 
29
33
  def malformed_request?
30
- if request.put?
31
- return invalid_json? || webhook_validation_errors?(parsed_webhook, uuid)
32
- end
33
- false
34
+ super || (request.put? && webhook_validation_errors?(parsed_webhook, uuid))
34
35
  end
35
36
 
36
37
  def from_json
@@ -13,10 +13,6 @@ module PactBroker
13
13
  include WebhookResourceMethods
14
14
  include WebhookExecutionMethods
15
15
 
16
- def content_types_accepted
17
- [["application/json"]]
18
- end
19
-
20
16
  def content_types_provided
21
17
  [["application/hal+json"]]
22
18
  end
@@ -37,14 +33,16 @@ module PactBroker
37
33
  end
38
34
 
39
35
  def malformed_request?
40
- if request.post?
36
+ if super
37
+ true
38
+ elsif request.post?
41
39
  if uuid
42
40
  false
43
41
  else
44
42
  webhook_validation_errors?(webhook)
45
43
  end
46
44
  else
47
- super
45
+ false
48
46
  end
49
47
  end
50
48
 
@@ -85,7 +85,7 @@ module PactBroker
85
85
  use_first_tag_as_branch_time_limit: 10,
86
86
  auto_detect_main_branch: true,
87
87
  main_branch_candidates: ["develop", "main", "master"],
88
- allow_dangerous_contract_modification: true,
88
+ allow_dangerous_contract_modification: false,
89
89
  semver_formats: ["%M.%m.%p%s%d", "%M.%m", "%M"],
90
90
  seed_example_data: true,
91
91
  features: []
@@ -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 = {
@@ -1,14 +1,25 @@
1
1
  # Pacticipant branch version
2
2
 
3
- Allowed methods: `GET`, `PUT`
3
+ Allowed methods: `GET`, `PUT`, `DELETE`
4
4
 
5
5
  Path: `/pacticipants/{pacticipant}/branches/{branch}/versions/{version}`
6
6
 
7
7
  Get or add/create a pacticipant version for a branch.
8
8
 
9
- ## Example
9
+ ## Create
10
+
11
+ ### Example
10
12
 
11
13
  Add a version to a branch. The pacticipant and branch are automatically created if they do not exist.
12
14
 
13
15
  curl -XPUT http://broker/pacticipants/Bar/branches/main/versions/1e70030c6579915e5ff56b107a0fd25cf5df7464 \
14
16
  -H "Content-Type: application/json" -d "{}"
17
+
18
+
19
+ ## Delete
20
+
21
+ Removes a pacticipant version from a branch. Does not delete the actual pacticipant version.
22
+
23
+ Send a `DELETE` request to the branch version resource.
24
+
25
+ curl -XDELETE http://broker/pacticipants/Bar/branches/main/versions/1e70030c6579915e5ff56b107a0fd25cf5df7464
@@ -48,7 +48,7 @@ Example: This data structure represents the way a user might specify "I want to
48
48
 
49
49
  `consumerVersionSelectors.tag`: the tag name(s) of the consumer versions to get the pacts for. *This field is still supported but it is recommended to use the `branch` in preference now.*
50
50
 
51
- `consumerVersionSelectors.fallbackTag`: the name of the tag to fallback to if the specified `tag` does not exist. This is useful when the consumer and provider use matching branch names to coordinate the development of new features. *This field is still supported but it is recommended to use the `fallbackBranch` in preference now.*
51
+ `consumerVersionSelectors.fallbackTag`: the name of the tag to fallback to if the specified `tag` does not exist. This is useful when the consumer and provider use matching branch names to coordinate the development of new features. *This field is still supported but it is recommended to use two separate selectors - one with the main branch name and one with the feature branch name.*
52
52
 
53
53
  `providerVersionBranch`: the repository branch name for the provider application version that will be published with the verification results. This is used by the Broker to determine whether or not a particular pact is in pending state or not.
54
54
 
@@ -44,6 +44,7 @@ module PactBroker
44
44
  using PactBroker::StringRefinements
45
45
 
46
46
  plugin :insert_ignore, identifying_columns: [:name]
47
+ plugin :upsert, identifying_columns: [:name]
47
48
  plugin :timestamps, update_on_create: true
48
49
 
49
50
  set_primary_key :id