pact_broker 2.83.0 → 2.84.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -0
  3. data/Dockerfile +1 -1
  4. data/db/migrations/20210816_create_branches_tables.rb +40 -0
  5. data/db/migrations/20210831_add_index_to_pact_publications.rb +7 -0
  6. data/db/migrations/20210908_add_auto_created.rb +24 -0
  7. data/issue-reproduction/Dockerfile-pact-broker +1 -1
  8. data/lib/pact_broker/api/contracts/{verifiable_pacts_json_query_schema.rb → pacts_for_verification_json_query_schema.rb} +1 -1
  9. data/lib/pact_broker/api/contracts/{verifiable_pacts_query_schema.rb → pacts_for_verification_query_string_schema.rb} +1 -1
  10. data/lib/pact_broker/api/decorators/branch_version_decorator.rb +20 -0
  11. data/lib/pact_broker/api/decorators/dashboard_decorator.rb +4 -2
  12. data/lib/pact_broker/api/decorators/embedded_branch_version_decorator.rb +21 -0
  13. data/lib/pact_broker/api/decorators/embedded_tag_decorator.rb +0 -5
  14. data/lib/pact_broker/api/decorators/matrix_decorator.rb +11 -2
  15. data/lib/pact_broker/api/decorators/pacticipant_decorator.rb +8 -0
  16. data/lib/pact_broker/api/decorators/{verifiable_pacts_query_decorator.rb → pacts_for_verification_query_decorator.rb} +2 -2
  17. data/lib/pact_broker/api/decorators/version_decorator.rb +1 -1
  18. data/lib/pact_broker/api/pact_broker_urls.rb +8 -0
  19. data/lib/pact_broker/api/resources/branch_version.rb +48 -0
  20. data/lib/pact_broker/api/resources/index.rb +6 -0
  21. data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +6 -6
  22. data/lib/pact_broker/api/resources/version.rb +0 -8
  23. data/lib/pact_broker/api.rb +1 -0
  24. data/lib/pact_broker/config/runtime_configuration.rb +12 -0
  25. data/lib/pact_broker/contracts/service.rb +1 -1
  26. data/lib/pact_broker/db/data_migrations/create_branches.rb +97 -0
  27. data/lib/pact_broker/db/data_migrations/set_pacticipant_main_branch.rb +2 -0
  28. data/lib/pact_broker/db/migrate_data.rb +1 -1
  29. data/lib/pact_broker/db/models.rb +6 -0
  30. data/lib/pact_broker/deployments/deployed_version.rb +4 -0
  31. data/lib/pact_broker/deployments/deployed_version_service.rb +4 -3
  32. data/lib/pact_broker/deployments/environment.rb +4 -0
  33. data/lib/pact_broker/deployments/environment_service.rb +13 -8
  34. data/lib/pact_broker/doc/views/index/pacticipant-branch-version.markdown +14 -0
  35. data/lib/pact_broker/doc/views/webhooks.markdown +1 -0
  36. data/lib/pact_broker/domain/index_item.rb +15 -17
  37. data/lib/pact_broker/domain/pacticipant.rb +11 -0
  38. data/lib/pact_broker/domain/tag.rb +1 -2
  39. data/lib/pact_broker/domain/verification.rb +16 -13
  40. data/lib/pact_broker/domain/version.rb +87 -33
  41. data/lib/pact_broker/index/service.rb +8 -4
  42. data/lib/pact_broker/locale/en.yml +1 -0
  43. data/lib/pact_broker/matrix/quick_row.rb +6 -6
  44. data/lib/pact_broker/metrics/service.rb +7 -1
  45. data/lib/pact_broker/pacts/pact_publication.rb +22 -25
  46. data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +74 -33
  47. data/lib/pact_broker/pacts/pact_publication_selector_dataset_module.rb +18 -13
  48. data/lib/pact_broker/pacts/pact_publication_wip_dataset_module.rb +16 -4
  49. data/lib/pact_broker/pacts/pact_version.rb +11 -0
  50. data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +3 -3
  51. data/lib/pact_broker/pacts/selected_pact.rb +2 -2
  52. data/lib/pact_broker/pacts/selector.rb +98 -33
  53. data/lib/pact_broker/repositories.rb +5 -0
  54. data/lib/pact_broker/services.rb +9 -0
  55. data/lib/pact_broker/test/http_test_data_builder.rb +32 -7
  56. data/lib/pact_broker/test/test_data_builder.rb +25 -24
  57. data/lib/pact_broker/ui/view_models/index_item.rb +11 -0
  58. data/lib/pact_broker/ui/view_models/matrix_branch.rb +39 -0
  59. data/lib/pact_broker/ui/view_models/matrix_line.rb +11 -16
  60. data/lib/pact_broker/ui/views/index/show-with-tags.haml +12 -11
  61. data/lib/pact_broker/ui/views/matrix/show.haml +8 -8
  62. data/lib/pact_broker/version.rb +1 -1
  63. data/lib/pact_broker/versions/branch.rb +29 -0
  64. data/lib/pact_broker/versions/branch_head.rb +45 -0
  65. data/lib/pact_broker/versions/branch_service.rb +24 -0
  66. data/lib/pact_broker/versions/branch_version.rb +64 -0
  67. data/lib/pact_broker/versions/branch_version_repository.rb +34 -0
  68. data/lib/pact_broker/versions/eager_loaders.rb +0 -42
  69. data/lib/pact_broker/versions/repository.rb +25 -12
  70. data/lib/pact_broker/versions/service.rb +3 -22
  71. data/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +11 -2
  72. data/lib/sequel/plugins/insert_ignore.rb +4 -0
  73. data/lib/sequel/plugins/upsert.rb +4 -0
  74. data/public/javascripts/index.js +129 -34
  75. data/scaffolding/templates/decorator.rb.erb +3 -1
  76. data/scaffolding/templates/migration.erb +1 -1
  77. data/scaffolding/templates/model.erb +2 -2
  78. data/scaffolding/templates/repository.rb.erb +2 -2
  79. data/scaffolding/templates/repository_spec.rb.erb +1 -1
  80. data/scaffolding/templates/resource.erb +2 -2
  81. data/scaffolding/templates/resource_spec.rb.erb +1 -1
  82. data/scaffolding/templates/service.rb.erb +3 -3
  83. data/scaffolding/templates/service_spec.rb.erb +1 -1
  84. data/script/data/branches.rb +35 -0
  85. data/script/data/issue-494.rb +25 -0
  86. data/spec/features/create_branch_version_spec.rb +29 -0
  87. data/spec/features/create_tag_spec.rb +1 -1
  88. data/spec/features/create_version_spec.rb +2 -4
  89. data/spec/features/get_branch_version_spec.rb +12 -0
  90. data/spec/features/publish_pact_all_in_one_spec.rb +0 -1
  91. data/spec/features/update_version_spec.rb +0 -55
  92. data/spec/fixtures/approvals/modifiable_resources.approved.json +3 -0
  93. data/spec/fixtures/approvals/publish_contract_nothing_exists.approved.json +1 -2
  94. data/spec/fixtures/approvals/publish_contract_nothing_exists_with_webhook.approved.json +1 -2
  95. data/spec/fixtures/approvals/publish_contract_verification_already_exists.approved.json +1 -2
  96. data/spec/fixtures/dashboard.json +4 -2
  97. data/spec/integration/ui/index_spec.rb +0 -2
  98. data/spec/integration/ui/matrix_spec.rb +0 -1
  99. data/spec/lib/pact_broker/api/contracts/{verifiable_pacts_json_query_schema_combinations_spec.rb → pacts_for_verification_json_query_schema_combinations_spec.rb} +6 -6
  100. data/spec/lib/pact_broker/api/contracts/{verifiable_pacts_json_query_schema_spec.rb → pacts_for_verification_json_query_schema_spec.rb} +3 -3
  101. data/spec/lib/pact_broker/api/contracts/{verifiable_pacts_query_schema_spec.rb → pacts_for_verification_query_string_schema_spec.rb} +3 -3
  102. data/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb +7 -7
  103. data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +19 -4
  104. data/spec/lib/pact_broker/api/decorators/{verifiable_pacts_query_decorator_spec.rb → pacts_for_verification_query_decorator_spec.rb} +3 -3
  105. data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +7 -3
  106. data/spec/lib/pact_broker/contracts/service_spec.rb +24 -3
  107. data/spec/lib/pact_broker/db/data_migrations/create_branches_spec.rb +57 -0
  108. data/spec/lib/pact_broker/domain/index_item_spec.rb +1 -1
  109. data/spec/lib/pact_broker/domain/version_spec.rb +1 -35
  110. data/spec/lib/pact_broker/metrics/service_spec.rb +4 -1
  111. data/spec/lib/pact_broker/pacts/pact_publication_dataset_module_spec.rb +109 -10
  112. data/spec/lib/pact_broker/pacts/pact_publication_selector_dataset_module_spec.rb +3 -2
  113. data/spec/lib/pact_broker/pacts/pact_publication_spec.rb +5 -5
  114. data/spec/lib/pact_broker/pacts/repository_find_for_currently_deployed_spec.rb +2 -2
  115. data/spec/lib/pact_broker/pacts/repository_find_for_currently_supported_releases_spec.rb +2 -2
  116. data/spec/lib/pact_broker/pacts/selector_spec.rb +45 -3
  117. data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +5 -5
  118. data/spec/lib/pact_broker/relationships/groupify_spec.rb +0 -5
  119. data/spec/lib/pact_broker/ui/view_models/index_item_spec.rb +15 -3
  120. data/spec/lib/pact_broker/verifications/repository_spec.rb +1 -1
  121. data/spec/lib/pact_broker/versions/branch_service_spec.rb +71 -0
  122. data/spec/lib/pact_broker/versions/branch_version_repository_spec.rb +81 -0
  123. data/spec/lib/pact_broker/versions/branch_version_spec.rb +27 -0
  124. data/spec/lib/pact_broker/versions/repository_spec.rb +91 -6
  125. data/spec/lib/pact_broker/versions/service_spec.rb +4 -3
  126. data/spec/lib/pact_broker/webhooks/render_spec.rb +6 -0
  127. data/spec/lib/sequel/plugins/upsert_spec.rb +11 -5
  128. data/spec/migrations/44_add_provider_version_to_verification_spec.rb +6 -9
  129. metadata +42 -15
  130. data/lib/pact_broker/versions/lazy_loaders.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36d8ba30424126875c015264b7ba7e8fd7feb281a019f3436b5c714c7c5ddd0a
4
- data.tar.gz: 4858eeee386bb44f6d9880b79a92b71d3760b8307fb5faebe07efa8f773fb2ba
3
+ metadata.gz: d104329cabc691c2ec288acee11837621c8970181a6dddf7d4bf7e4c5d3f48fe
4
+ data.tar.gz: d7c5c2a75605aa5f947495670d995d5d5500f487dff86ae676da3bd883c55510
5
5
  SHA512:
6
- metadata.gz: 23a3f387f860177de7cfdc7152127fd295aa124b415e0d1b7b66c657947c0b89ea06decff7bf2b840d75b690b844bd0fb2999ddb14deb4b269d21e9e5cc7d736
7
- data.tar.gz: 98c2642b548b2b08ac71fe55a66c18981392ea575bc6c2ca389c19c1f283b134c814cf2479e03d7899bb70a8d244c1987fca10556833df5c3c506e45dfd5ee07
6
+ metadata.gz: 7a973402c0c004acd5f94cc0c04efec0ded2039f43dfd3e2ca7ba014b853f958345b2ada02c05af05748416dbe466596920d8112c34efd71a5533c212ab6002c
7
+ data.tar.gz: 9bf006fa32ad47353df1bb9704a8da05205de57da618273ca0c0cb3b487c570951caa1e0ab3624177aa82a12c329d63aeba11c07c87b1eaa1e368956edd72250
data/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ <a name="v2.84.0"></a>
2
+ ### v2.84.0 (2021-09-10)
3
+
4
+ #### Features
5
+
6
+ * use the first tag as the branch when publishing pacts using the contracts/publish endpoint ([7b903c1d](/../../commit/7b903c1d))
7
+ * support multiple branches per version (#495) ([acff2fcc](/../../commit/acff2fcc))
8
+ * Support deleting all pacts for a specific tag in the UI (#480) ([10dda8ae](/../../commit/10dda8ae))
9
+ * add webhook template parameter for GItlab verification statuses (#493) ([390ae0d8](/../../commit/390ae0d8))
10
+
11
+ * **pacts for verification**
12
+ * include pending status for responses by default when includePendingStatus is not specified ([748d3b87](/../../commit/748d3b87))
13
+
14
+ #### Bug Fixes
15
+
16
+ * when the latest version for a tag does not have a pact, do not return a pact for the 'latest tag' selector ([374c77ce](/../../commit/374c77ce))
17
+ * issue-reproduction/Dockerfile-pact-broker to reduce vulnerabilities (#491) ([9692b465](/../../commit/9692b465))
18
+ * Dockerfile to reduce vulnerabilities (#496) ([57c190ef](/../../commit/57c190ef))
19
+
1
20
  <a name="v2.83.0"></a>
2
21
  ### v2.83.0 (2021-08-19)
3
22
 
data/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM ruby:2.7.3-alpine3.13
1
+ FROM ruby:2.7.4-alpine3.13
2
2
 
3
3
  WORKDIR /home
4
4
 
@@ -0,0 +1,40 @@
1
+ Sequel.migration do
2
+ change do
3
+ create_table(:branches, charset: "utf8") do
4
+ primary_key :id
5
+ String :name
6
+ foreign_key :pacticipant_id, :pacticipants, null: false, on_delete: :cascade
7
+ DateTime :created_at, null: false
8
+ DateTime :updated_at, null: false
9
+ index [:pacticipant_id, :name], unique: true, name: :branches_pacticipant_id_name_index
10
+ end
11
+
12
+ create_table(:branch_versions, charset: "utf8") do
13
+ primary_key :id
14
+ foreign_key :branch_id, :branches, null: false, foreign_key_constraint_name: :branch_versions_branches_fk, on_delete: :cascade
15
+ foreign_key :version_id, :versions, null: false, foreign_key_constraint_name: :branch_versions_versions_fk, on_delete: :cascade
16
+ Integer :version_order, null: false
17
+ Integer :pacticipant_id, null: false
18
+ String :branch_name, null: false
19
+ DateTime :created_at, null: false
20
+ DateTime :updated_at, null: false
21
+ index [:branch_id, :version_id], unique: true, name: :branch_versions_branch_id_version_id_index
22
+ index [:version_id], name: :branch_versions_version_id_index
23
+ index [:branch_name], name: :branch_versions_branch_name_index
24
+ # Can probably drop this index when the "latest pact" logic changes
25
+ index [:pacticipant_id, :branch_id, :version_order], name: :branch_versions_pacticipant_id_branch_id_version_order_index
26
+ end
27
+
28
+ create_table(:branch_heads) do
29
+ foreign_key :branch_id, :branches, null: false, on_delete: :cascade
30
+ foreign_key :branch_version_id, :branch_versions, null: false, on_delete: :cascade
31
+ Integer :version_id, null: false
32
+ Integer :pacticipant_id, null: false
33
+ String :branch_name, null: false
34
+ index [:branch_id], unique: true, name: :branch_heads_branch_id_index
35
+ index [:branch_name], name: :branch_heads_branch_name_index
36
+ index [:pacticipant_id], name: :branch_heads_pacticipant_id_index
37
+ index [:version_id], name: :branch_heads_version_id_index
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,7 @@
1
+ Sequel.migration do
2
+ change do
3
+ alter_table(:pact_publications) do
4
+ add_index [:consumer_id, :provider_id, :consumer_version_order], name: :pact_publications_cid_pid_cvo_index
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ Sequel.migration do
2
+ up do
3
+ alter_table(:branch_versions) do
4
+ add_column(:auto_created, TrueClass, default: false)
5
+ end
6
+
7
+ alter_table(:deployed_versions) do
8
+ add_column(:auto_created, TrueClass, default: false)
9
+ end
10
+
11
+ from(:branch_versions).update(auto_created: true)
12
+ from(:deployed_versions).update(auto_created: true)
13
+ end
14
+
15
+ down do
16
+ alter_table(:branch_versions) do
17
+ drop_column(:auto_created)
18
+ end
19
+
20
+ alter_table(:deployed_versions) do
21
+ drop_column(:auto_created)
22
+ end
23
+ end
24
+ end
@@ -1,4 +1,4 @@
1
- FROM ruby:2.7.3-alpine
1
+ FROM ruby:2.7-alpine
2
2
 
3
3
  RUN apk update \
4
4
  && apk --no-cache add \
@@ -8,7 +8,7 @@ require "pact_broker/messages"
8
8
  module PactBroker
9
9
  module Api
10
10
  module Contracts
11
- class VerifiablePactsJSONQuerySchema
11
+ class PactsForVerificationJSONQuerySchema
12
12
  extend DryValidationWorkarounds
13
13
  extend PactBroker::Messages
14
14
 
@@ -5,7 +5,7 @@ require "pact_broker/api/contracts/dry_validation_predicates"
5
5
  module PactBroker
6
6
  module Api
7
7
  module Contracts
8
- class VerifiablePactsQuerySchema
8
+ class PactsForVerificationQueryStringSchema
9
9
  extend DryValidationWorkarounds
10
10
  using PactBroker::HashRefinements
11
11
 
@@ -0,0 +1,20 @@
1
+ require "pact_broker/api/decorators/base_decorator"
2
+ require "pact_broker/api/decorators/timestamps"
3
+
4
+ module PactBroker
5
+ module Api
6
+ module Decorators
7
+ class BranchVersionDecorator < BaseDecorator
8
+
9
+ link :self do | user_options |
10
+ {
11
+ title: "Branch version",
12
+ href: branch_version_url(represented, user_options.fetch(:base_url))
13
+ }
14
+ end
15
+
16
+ include Timestamps
17
+ end
18
+ end
19
+ end
20
+ end
@@ -58,7 +58,8 @@ module PactBroker
58
58
  name: index_item.consumer_name,
59
59
  version: {
60
60
  number: index_item.consumer_version_number,
61
- branch: index_item.consumer_version_branch,
61
+ branch: index_item.consumer_version_branches.last,
62
+ headBranchNames: index_item.consumer_version_branches,
62
63
  _links: {
63
64
  self: {
64
65
  href: version_url(base_url, index_item.consumer_version)
@@ -87,7 +88,8 @@ module PactBroker
87
88
  if index_item.latest_verification
88
89
  hash[:version] = {
89
90
  number: index_item.provider_version_number,
90
- branch: index_item.provider_version_branch
91
+ branch: index_item.provider_version_branches.last,
92
+ headBranchNames: index_item.provider_version_branches
91
93
  }
92
94
  end
93
95
 
@@ -0,0 +1,21 @@
1
+ require_relative "base_decorator"
2
+ require_relative "timestamps"
3
+
4
+ module PactBroker
5
+ module Api
6
+ module Decorators
7
+ class EmbeddedBranchVersionDecorator < BaseDecorator
8
+ property :branch_name, as: :name
9
+ property :latest?, as: :latest
10
+
11
+ link :self do | options |
12
+ {
13
+ title: "Version branch",
14
+ name: represented.branch_name,
15
+ href: branch_version_url(represented, options[:base_url])
16
+ }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,15 +1,10 @@
1
1
  require_relative "base_decorator"
2
- require_relative "pact_pacticipant_decorator"
3
2
  require_relative "timestamps"
4
3
 
5
4
  module PactBroker
6
-
7
5
  module Api
8
-
9
6
  module Decorators
10
-
11
7
  class EmbeddedTagDecorator < BaseDecorator
12
-
13
8
  property :name
14
9
 
15
10
  link :self do | options |
@@ -2,6 +2,7 @@ require "ostruct"
2
2
  require "pact_broker/api/pact_broker_urls"
3
3
  require "pact_broker/api/decorators/reason_decorator"
4
4
  require "pact_broker/api/decorators/format_date_time"
5
+ require "pact_broker/api/decorators/embedded_branch_version_decorator"
5
6
 
6
7
  module PactBroker
7
8
  module Api
@@ -83,7 +84,8 @@ module PactBroker
83
84
  name: line.consumer_name,
84
85
  version: {
85
86
  number: line.consumer_version_number,
86
- branch: line.consumer_version_branch,
87
+ branch: line.consumer_version_branch_versions.last&.branch_name,
88
+ branches: branches(line.consumer_version_branch_versions, base_url),
87
89
  _links: {
88
90
  self: {
89
91
  href: version_url(base_url, consumer_version)
@@ -99,6 +101,12 @@ module PactBroker
99
101
  }
100
102
  end
101
103
 
104
+ def branches(branch_versions, base_url)
105
+ branch_versions.collect do | branch_version |
106
+ PactBroker::Api::Decorators::EmbeddedBranchVersionDecorator.new(branch_version).to_hash(user_options: { base_url: base_url })
107
+ end
108
+ end
109
+
102
110
  def tags(tags, base_url)
103
111
  tags.sort_by(&:created_at).collect do | tag |
104
112
  {
@@ -127,7 +135,8 @@ module PactBroker
127
135
  if !line.provider_version_number.nil?
128
136
  hash[:version] = {
129
137
  number: line.provider_version_number,
130
- branch: line.provider_version_branch,
138
+ branch: line.provider_version_branch_versions.last&.branch_name,
139
+ branches: branches(line.provider_version_branch_versions, base_url),
131
140
  _links: {
132
141
  self: {
133
142
  href: version_url(base_url, provider_version)
@@ -49,6 +49,14 @@ module PactBroker
49
49
  }
50
50
  end
51
51
 
52
+ link :'pb:branch-version' do | options |
53
+ {
54
+ title: "Get or add/create a version for a branch of #{represented.name}",
55
+ href: templated_branch_version_url_for_pacticipant(represented.name, options[:base_url]),
56
+ templated: true
57
+ }
58
+ end
59
+
52
60
  link :'pb:label' do | options |
53
61
  {
54
62
  title: "Get, create or delete a label for #{represented.name}",
@@ -8,7 +8,7 @@ require "pact_broker/pacts/selectors"
8
8
  module PactBroker
9
9
  module Api
10
10
  module Decorators
11
- class VerifiablePactsQueryDecorator < BaseDecorator
11
+ class PactsForVerificationQueryDecorator < BaseDecorator
12
12
  using PactBroker::HashRefinements
13
13
 
14
14
  collection :provider_version_tags, default: []
@@ -38,7 +38,7 @@ module PactBroker
38
38
  }
39
39
  end
40
40
 
41
- property :include_pending_status, default: false,
41
+ property :include_pending_status, default: true,
42
42
  setter: ->(fragment:, represented:, **) {
43
43
  represented.include_pending_status = (fragment == "true" || fragment == true)
44
44
  }
@@ -7,7 +7,7 @@ module PactBroker
7
7
  class VersionDecorator < BaseDecorator
8
8
 
9
9
  property :number, writeable: false
10
- property :branch
10
+ collection :branch_versions, as: :branches, embedded: true, writeable: false, extend: PactBroker::Api::Decorators::EmbeddedBranchVersionDecorator
11
11
  property :build_url, as: :buildUrl
12
12
 
13
13
  collection :tags, embedded: true, :extend => PactBroker::Api::Decorators::EmbeddedTagDecorator, class: OpenStruct
@@ -199,10 +199,18 @@ module PactBroker
199
199
  "#{tags_url(base_url, tag.version)}/#{url_encode(tag.name)}"
200
200
  end
201
201
 
202
+ def branch_version_url(branch_version, base_url = "")
203
+ "#{pacticipant_url(base_url, branch_version.pacticipant)}/branches/#{url_encode(branch_version.branch_name)}/versions/#{url_encode(branch_version.version_number)}"
204
+ end
205
+
202
206
  def templated_tag_url_for_pacticipant pacticipant_name, base_url = ""
203
207
  pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/versions/{version}/tags/{tag}"
204
208
  end
205
209
 
210
+ def templated_branch_version_url_for_pacticipant pacticipant_name, base_url = ""
211
+ pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/branches/{branch}/versions/{version}"
212
+ end
213
+
206
214
  def templated_version_url_for_pacticipant pacticipant_name, base_url = ""
207
215
  pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/versions/{version}"
208
216
  end
@@ -0,0 +1,48 @@
1
+ require "pact_broker/api/resources/base_resource"
2
+ require "pact_broker/api/decorators/branch_version_decorator"
3
+
4
+ module PactBroker
5
+ module Api
6
+ module Resources
7
+ class BranchVersion < BaseResource
8
+ def content_types_provided
9
+ [["application/hal+json", :to_json]]
10
+ end
11
+
12
+ def content_types_accepted
13
+ [["application/json", :from_json]]
14
+ end
15
+
16
+ def allowed_methods
17
+ ["GET", "PUT", "OPTIONS"]
18
+ end
19
+
20
+ def resource_exists?
21
+ !!branch_version
22
+ end
23
+
24
+ def to_json
25
+ decorator_class(:branch_version_decorator).new(branch_version).to_json(decorator_options)
26
+ end
27
+
28
+ def from_json
29
+ already_existed = !!branch_version
30
+ @branch_version = branch_service.find_or_create_branch_version(identifier_from_path)
31
+ # Make it return a 201 by setting the Location header
32
+ response.headers["Location"] = branch_version_url(branch_version, base_url) unless already_existed
33
+ response.body = to_json
34
+ end
35
+
36
+ def policy_name
37
+ :'versions::branch_version'
38
+ end
39
+
40
+ private
41
+
42
+ def branch_version
43
+ @branch_version ||= branch_service.find_branch_version(identifier_from_path)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -116,6 +116,12 @@ module PactBroker
116
116
  title: "Get, create or delete a tag for a pacticipant version",
117
117
  templated: true
118
118
  },
119
+ "pb:pacticipant-branch-version" =>
120
+ {
121
+ href: base_url + "/pacticipants/{pacticipant}/branches/{branch}/versions/{version}",
122
+ title: "Get or add/create a pacticipant version for a branch",
123
+ templated: true
124
+ },
119
125
  "pb:pacticipant-version" =>
120
126
  {
121
127
  href: base_url + "/pacticipants/{pacticipant}/versions/{version}",
@@ -1,8 +1,8 @@
1
1
  require "pact_broker/api/resources/provider_pacts"
2
2
  require "pact_broker/api/decorators/verifiable_pacts_decorator"
3
- require "pact_broker/api/contracts/verifiable_pacts_query_schema"
4
- require "pact_broker/api/decorators/verifiable_pacts_query_decorator"
5
- require "pact_broker/api/contracts/verifiable_pacts_json_query_schema"
3
+ require "pact_broker/api/contracts/pacts_for_verification_query_string_schema"
4
+ require "pact_broker/api/decorators/pacts_for_verification_query_decorator"
5
+ require "pact_broker/api/contracts/pacts_for_verification_json_query_schema"
6
6
  require "pact_broker/hash_refinements"
7
7
 
8
8
  module PactBroker
@@ -69,14 +69,14 @@ module PactBroker
69
69
 
70
70
  def query_schema
71
71
  if request.get?
72
- PactBroker::Api::Contracts::VerifiablePactsQuerySchema
72
+ PactBroker::Api::Contracts::PactsForVerificationQueryStringSchema
73
73
  else
74
- PactBroker::Api::Contracts::VerifiablePactsJSONQuerySchema
74
+ PactBroker::Api::Contracts::PactsForVerificationJSONQuerySchema
75
75
  end
76
76
  end
77
77
 
78
78
  def parsed_query_params
79
- @parsed_query_params ||= decorator_class(:verifiable_pacts_query_decorator).new(OpenStruct.new).from_hash(query)
79
+ @parsed_query_params ||= decorator_class(:pacts_for_verification_query_decorator).new(OpenStruct.new).from_hash(query)
80
80
  end
81
81
 
82
82
  def query
@@ -21,14 +21,6 @@ module PactBroker
21
21
  ["GET", "PUT", "PATCH", "DELETE", "OPTIONS"]
22
22
  end
23
23
 
24
- def is_conflict?
25
- if (errors = version_service.conflict_errors(version, parsed_version, resource_url)).any?
26
- set_json_validation_error_messages(errors)
27
- else
28
- false
29
- end
30
- end
31
-
32
24
  def resource_exists?
33
25
  !!version
34
26
  end