pact_broker 2.80.0 → 2.81.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -2
  3. data/CHANGELOG.md +21 -0
  4. data/db/ddl_statements/latest_verifications_for_pact_versions.rb +28 -0
  5. data/db/migrations/20210711_add_consumer_version_order_to_pact_publication.rb +12 -0
  6. data/db/migrations/20210712_add_interaction_count_to_pact_versions.rb +8 -0
  7. data/lib/db.rb +4 -0
  8. data/lib/pact_broker/api.rb +8 -10
  9. data/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema.rb +25 -5
  10. data/lib/pact_broker/api/contracts/verifiable_pacts_query_schema.rb +0 -1
  11. data/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator.rb +24 -0
  12. data/lib/pact_broker/api/resources/dashboard.rb +4 -1
  13. data/lib/pact_broker/api/resources/deployed_versions_for_version_and_environment.rb +3 -7
  14. data/lib/pact_broker/api/resources/index.rb +10 -12
  15. data/lib/pact_broker/api/resources/latest_provider_pacts.rb +1 -1
  16. data/lib/pact_broker/api/resources/pagination_methods.rb +14 -0
  17. data/lib/pact_broker/api/resources/tag.rb +14 -0
  18. data/lib/pact_broker/configuration.rb +4 -1
  19. data/lib/pact_broker/db/data_migrations/set_consumer_version_order_for_pact_publications.rb +28 -0
  20. data/lib/pact_broker/db/data_migrations/set_interactions_counts.rb +41 -0
  21. data/lib/pact_broker/db/migrate_data.rb +2 -0
  22. data/lib/pact_broker/db/seed_example_data.rb +5 -0
  23. data/lib/pact_broker/deployments/deployed_version_service.rb +13 -9
  24. data/lib/pact_broker/domain/verification.rb +40 -0
  25. data/lib/pact_broker/domain/version.rb +4 -0
  26. data/lib/pact_broker/index/service.rb +4 -5
  27. data/lib/pact_broker/integrations/integration.rb +27 -6
  28. data/lib/pact_broker/logging.rb +10 -0
  29. data/lib/pact_broker/matrix/unresolved_selector.rb +1 -1
  30. data/lib/pact_broker/metrics/service.rb +17 -0
  31. data/lib/pact_broker/pacts/all_pact_publications.rb +4 -2
  32. data/lib/pact_broker/pacts/content.rb +2 -2
  33. data/lib/pact_broker/pacts/metadata.rb +11 -5
  34. data/lib/pact_broker/pacts/pact_publication.rb +41 -6
  35. data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +55 -11
  36. data/lib/pact_broker/pacts/pact_publication_selector_dataset_module.rb +20 -0
  37. data/lib/pact_broker/pacts/pact_version.rb +14 -15
  38. data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +86 -31
  39. data/lib/pact_broker/pacts/parse.rb +1 -0
  40. data/lib/pact_broker/pacts/repository.rb +51 -41
  41. data/lib/pact_broker/pacts/selector.rb +18 -2
  42. data/lib/pact_broker/pacts/service.rb +13 -22
  43. data/lib/pact_broker/pacts/verifiable_pact_messages.rb +11 -0
  44. data/lib/pact_broker/repositories/helpers.rb +4 -0
  45. data/lib/pact_broker/repositories/scopes.rb +15 -0
  46. data/lib/pact_broker/test/test_data_builder.rb +2 -1
  47. data/lib/pact_broker/ui/helpers/matrix_helper.rb +1 -0
  48. data/lib/pact_broker/ui/views/index/show-with-tags.haml +1 -1
  49. data/lib/pact_broker/ui/views/matrix/show.haml +2 -0
  50. data/lib/pact_broker/verifications/latest_verification_for_pact_version.rb +2 -2
  51. data/lib/pact_broker/verifications/repository.rb +9 -10
  52. data/lib/pact_broker/version.rb +1 -1
  53. data/public/javascripts/matrix.js +3 -0
  54. data/spec/features/create_tag_spec.rb +10 -0
  55. data/spec/features/execute_webhook_spec.rb +1 -3
  56. data/spec/features/get_integrations_spec.rb +2 -2
  57. data/spec/features/get_provider_pacts_for_verification_spec.rb +5 -3
  58. data/spec/features/metadata_spec.rb +66 -0
  59. data/spec/features/publish_verification_results_and_version_spec.rb +70 -0
  60. data/spec/fixtures/approvals/get_provider_pacts_for_verification.approved.json +2 -2
  61. data/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_combinations_spec.rb +9 -0
  62. data/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_spec.rb +15 -0
  63. data/spec/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator_spec.rb +12 -0
  64. data/spec/lib/pact_broker/api/resources/dashboard_spec.rb +23 -2
  65. data/spec/lib/pact_broker/api/resources/latest_provider_pacts_spec.rb +3 -3
  66. data/spec/lib/pact_broker/api/resources/provider_pacts_spec.rb +1 -1
  67. data/spec/lib/pact_broker/api/resources/tag_spec.rb +39 -13
  68. data/spec/lib/pact_broker/db/data_migrations/set_interactions_counts_spec.rb +38 -0
  69. data/spec/lib/pact_broker/deployments/deployed_version_service_spec.rb +42 -0
  70. data/spec/lib/pact_broker/domain/verification_spec.rb +17 -0
  71. data/spec/lib/pact_broker/index/service_spec.rb +28 -16
  72. data/spec/lib/pact_broker/integrations/integration_spec.rb +21 -10
  73. data/spec/lib/pact_broker/metrics/service_spec.rb +25 -0
  74. data/spec/lib/pact_broker/pacts/content_spec.rb +1 -1
  75. data/spec/lib/pact_broker/pacts/metadata_spec.rb +95 -29
  76. data/spec/lib/pact_broker/pacts/pact_publication_selector_dataset_module_spec.rb +39 -0
  77. data/spec/lib/pact_broker/pacts/pact_version_spec.rb +68 -12
  78. data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_branch_spec.rb +1 -1
  79. data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb +1 -1
  80. data/spec/lib/pact_broker/pacts/repository_spec.rb +59 -52
  81. data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +9 -0
  82. data/spec/lib/pact_broker/verifications/latest_verification_for_pact_version_spec.rb +18 -0
  83. data/spec/support/shared_context.rb +0 -1
  84. metadata +20 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46291e7e974e823aee921175212537b972fea3789b7355526a0258903d6cc31c
4
- data.tar.gz: fdf706a490c487fa1a7f442864bca233d3c8488cdd688575dcfca0932014c61e
3
+ metadata.gz: 264cb3fe694b76c1efc4ee585043f68957485f477ef60154357d72535741dc9e
4
+ data.tar.gz: 2081f35b9a33d5e8ebe9817f5fda62b35378f437a66e69c2611555dc0f78228b
5
5
  SHA512:
6
- metadata.gz: 0fefcf924101d8e979e0ed1ccb96c7d771cb823e4f7c4d0ac527981414323a6bcddfa9b9cec68086e39da1ab261596e86c0ae808efe21aa621d1364b78be5cd0
7
- data.tar.gz: 32c2af6c35ccba62a58273bc8b3f6882969f02ef23d7ada3b0e74054f8b0cdbc284837b96c9f01be6b954bcc1cd4300e0e88c13cc0886fdc88993d6cf865077e
6
+ metadata.gz: bf0de96a30b0893206130d39f9ae19d23eb411e81440d7a2099aa6dfe36cdb5ddd9d135f51d164f17b439d7a8db07ea060e5bc0a7e6b0a980e87b100f6e23cf1
7
+ data.tar.gz: de1636fa911c024295c7b6d94df91219f7a7fe9a8ed3d838cbad635477b4623b220a0493181bac49652994bd19fb7a40f330a8a9bfc8efc25ceb20727c2653bd
data/.rubocop.yml CHANGED
@@ -209,9 +209,9 @@ Metrics/BlockNesting:
209
209
  Max: 4
210
210
 
211
211
  Metrics/ClassLength:
212
- Description: 'Avoid classes longer than 250 lines of code.'
212
+ Description: 'Avoid classes longer than 260 lines of code.'
213
213
  Enabled: true
214
- Max: 250
214
+ Max: 260
215
215
  Exclude:
216
216
  - lib/pact_broker/test/*.rb
217
217
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ <a name="v2.81.0"></a>
2
+ ### v2.81.0 (2021-07-17)
3
+
4
+ #### Features
5
+
6
+ * enable environments, deployed versions and released versions endpoints without a feature toggle required ([84a59c10](/../../commit/84a59c10))
7
+ * add detailed debug logging for WIP pact calculations ([81290238](/../../commit/81290238))
8
+ * add debug level logging for WIP pacts calculations ([a7c16833](/../../commit/a7c16833))
9
+ * include deployed and released versions in index page when viewing latest tags ([655e9dd5](/../../commit/655e9dd5))
10
+ * add interactions counts to metrics endpoint ([c765afe1](/../../commit/c765afe1))
11
+ * automatically create a deployed version when a tag is created with the same name as an environment ([56a583af](/../../commit/56a583af))
12
+ * support viewing all versions for branch in matrix UI ([12f92951](/../../commit/12f92951))
13
+ * validate environment name in consumer version selector ([f1ad8f6b](/../../commit/f1ad8f6b))
14
+ * support the deployedOrReleased: true consumer version selector ([042a1612](/../../commit/042a1612))
15
+ * add interactions_count and messages_count to pact_versions table ([c17adbe6](/../../commit/c17adbe6))
16
+ * shorten length of metadata in pact URLs by using the consumer version id instead of number ([27b34bc9](/../../commit/27b34bc9))
17
+
18
+ #### Bug Fixes
19
+
20
+ * Display pagination correctly in index page with tag (#469) ([cda9c15e](/../../commit/cda9c15e))
21
+
1
22
  <a name="v2.80.0"></a>
2
23
  ### v2.80.0 (2021-07-06)
3
24
 
@@ -0,0 +1,28 @@
1
+ def latest_verifications_for_pact_versions_v4(connection)
2
+ v = :verifications
3
+ connection.from(v)
4
+ .select(
5
+ Sequel[v][:id],
6
+ Sequel[v][:number],
7
+ Sequel[v][:success],
8
+ Sequel[v][:build_url],
9
+ Sequel[v][:pact_version_id],
10
+ Sequel[v][:execution_date],
11
+ Sequel[v][:created_at],
12
+ Sequel[v][:provider_version_id],
13
+ Sequel[:s][:number].as(:provider_version_number),
14
+ Sequel[:s][:order].as(:provider_version_order),
15
+ Sequel[v][:test_results],
16
+ Sequel[v][:consumer_id],
17
+ Sequel[v][:provider_id],
18
+ )
19
+ .join(:latest_verification_ids_for_pact_versions,
20
+ {
21
+ Sequel[v][:pact_version_id] => Sequel[:lv][:pact_version_id],
22
+ Sequel[v][:id] => Sequel[:lv][:latest_verification_id]
23
+ }, { table_alias: :lv })
24
+ .join(:versions,
25
+ {
26
+ Sequel[v][:provider_version_id] => Sequel[:s][:id]
27
+ }, { table_alias: :s })
28
+ end
@@ -0,0 +1,12 @@
1
+ Sequel.migration do
2
+ change do
3
+ alter_table(:pact_publications) do
4
+ add_column(:consumer_version_order, Integer) # duplicate column, no need for referential integrity
5
+ end
6
+
7
+ # TODO
8
+ # alter_table(:pact_publications) do
9
+ # set_column_not_null(:consumer_version_order)
10
+ # end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ Sequel.migration do
2
+ change do
3
+ alter_table(:pact_versions) do
4
+ add_column(:messages_count, Integer)
5
+ add_column(:interactions_count, Integer)
6
+ end
7
+ end
8
+ end
data/lib/db.rb CHANGED
@@ -63,6 +63,10 @@ module DB
63
63
  config.fetch(env).fetch(ENV.fetch("DATABASE_ADAPTER","default"))
64
64
  end
65
65
 
66
+ def self.sqlite?
67
+ !!(PACT_BROKER_DB.adapter_scheme.to_s =~ /sqlite/)
68
+ end
69
+
66
70
  def self.mysql?
67
71
  !!(PACT_BROKER_DB.adapter_scheme.to_s =~ /mysql/)
68
72
  end
@@ -117,16 +117,14 @@ module PactBroker
117
117
 
118
118
  add ["contracts", "publish"], Api::Resources::PublishContracts, { resource_name: "publish_contracts" }
119
119
 
120
- if PactBroker.feature_enabled?(:environments)
121
- add ["environments"], Api::Resources::Environments, { resource_name: "environments" }
122
- add ["environments", :environment_uuid], Api::Resources::Environment, { resource_name: "environment" }
123
- add ["environments", :environment_uuid, "deployed-versions", "currently-deployed"], Api::Resources::CurrentlyDeployedVersionsForEnvironment, { resource_name: "environment_currently_deployed_deployed_versions" }
124
- add ["environments", :environment_uuid, "released-versions", "currently-supported"], Api::Resources::CurrentlySupportedVersionsForEnvironment, { resource_name: "environment_currently_supported_released_versions" }
125
- add ["pacticipants", :pacticipant_name, "versions", :pacticipant_version_number, "deployed-versions", "environment", :environment_uuid], Api::Resources::DeployedVersionsForVersionAndEnvironment, { resource_name: "deployed_versions_for_version_and_environment" }
126
- add ["pacticipants", :pacticipant_name, "versions", :pacticipant_version_number, "released-versions", "environment", :environment_uuid], Api::Resources::ReleasedVersionsForVersionAndEnvironment, { resource_name: "released_versions_for_version_and_environment" }
127
- add ["released-versions", :uuid], Api::Resources::ReleasedVersion, { resource_name: "released_version" }
128
- add ["deployed-versions", :uuid], Api::Resources::DeployedVersion, { resource_name: "deployed_version" }
129
- end
120
+ add ["environments"], Api::Resources::Environments, { resource_name: "environments" }
121
+ add ["environments", :environment_uuid], Api::Resources::Environment, { resource_name: "environment" }
122
+ add ["environments", :environment_uuid, "deployed-versions", "currently-deployed"], Api::Resources::CurrentlyDeployedVersionsForEnvironment, { resource_name: "environment_currently_deployed_deployed_versions" }
123
+ add ["environments", :environment_uuid, "released-versions", "currently-supported"], Api::Resources::CurrentlySupportedVersionsForEnvironment, { resource_name: "environment_currently_supported_released_versions" }
124
+ add ["pacticipants", :pacticipant_name, "versions", :pacticipant_version_number, "deployed-versions", "environment", :environment_uuid], Api::Resources::DeployedVersionsForVersionAndEnvironment, { resource_name: "deployed_versions_for_version_and_environment" }
125
+ add ["pacticipants", :pacticipant_name, "versions", :pacticipant_version_number, "released-versions", "environment", :environment_uuid], Api::Resources::ReleasedVersionsForVersionAndEnvironment, { resource_name: "released_versions_for_version_and_environment" }
126
+ add ["released-versions", :uuid], Api::Resources::ReleasedVersion, { resource_name: "released_version" }
127
+ add ["deployed-versions", :uuid], Api::Resources::DeployedVersion, { resource_name: "deployed_version" }
130
128
 
131
129
  add ["integrations"], Api::Resources::Integrations, {resource_name: "integrations"}
132
130
  add ["integrations", "provider", :provider_name, "consumer", :consumer_name], Api::Resources::Integration, {resource_name: "integration"}
@@ -15,6 +15,10 @@ module PactBroker
15
15
  using PactBroker::HashRefinements
16
16
  using PactBroker::StringRefinements
17
17
 
18
+ BRANCH_KEYS = [:latest, :tag, :fallbackTag, :branch, :fallbackBranch]
19
+ ENVIRONMENT_KEYS = [:environment, :deployed, :released, :deployedOrReleased]
20
+ ALL_KEYS = BRANCH_KEYS + ENVIRONMENT_KEYS
21
+
18
22
  SCHEMA = Dry::Validation.Schema do
19
23
  configure do
20
24
  predicates(DryValidationPredicates)
@@ -29,6 +33,7 @@ module PactBroker
29
33
  # end
30
34
  # end
31
35
 
36
+ optional(:mainBranch).filled(included_in?: [true])
32
37
  optional(:tag).filled(:str?)
33
38
  optional(:branch).filled(:str?)
34
39
  optional(:latest).filled(included_in?: [true, false])
@@ -37,7 +42,8 @@ module PactBroker
37
42
  optional(:consumer).filled(:str?, :not_blank?)
38
43
  optional(:deployed).filled(included_in?: [true])
39
44
  optional(:released).filled(included_in?: [true])
40
- optional(:environment).filled(:str?)
45
+ optional(:deployedOrReleased).filled(included_in?: [true])
46
+ optional(:environment).filled(:str?, :environment_with_name_exists?)
41
47
 
42
48
  # rule(fallbackTagMustBeForLatest: [:fallbackTag, :latest]) do | fallback_tag, latest |
43
49
  # fallback_tag.filled?.then(latest.eql?(true))
@@ -87,13 +93,19 @@ module PactBroker
87
93
  errors << "fallbackBranch can only be set if latest is true (at index #{index})"
88
94
  end
89
95
 
90
- if not_provided?(selector[:tag]) &&
96
+ if not_provided?(selector[:mainBranch]) &&
97
+ not_provided?(selector[:tag]) &&
91
98
  not_provided?(selector[:branch]) &&
92
99
  not_provided?(selector[:environment]) &&
93
100
  selector[:deployed] != true &&
94
101
  selector[:released] != true &&
102
+ selector[:deployedOrReleased] != true &&
95
103
  selector[:latest] != true
96
- errors << "must specify a value for environment or tag, or specify latest=true, or specify deployed=true or released=true (at index #{index})"
104
+ errors << "must specify a value for environment or tag or branch, or specify mainBranch=true, latest=true, deployed=true, released=true or deployedOrReleased=true (at index #{index})"
105
+ end
106
+
107
+ if selector[:mainBranch] && selector.slice(*ALL_KEYS - [:consumer, :mainBranch]).any?
108
+ errors << "cannot specify mainBranch=true with any other criteria apart from consumer (at index #{index})"
97
109
  end
98
110
 
99
111
  if selector[:tag] && selector[:branch]
@@ -116,8 +128,16 @@ module PactBroker
116
128
  errors << "cannot specify both deployed=true and released=true (at index #{index})"
117
129
  end
118
130
 
119
- non_environment_fields = selector.slice(:latest, :tag, :fallbackTag, :branch, :fallbackBranch).keys.sort
120
- environment_related_fields = selector.slice(:environment, :deployed, :released).keys.sort
131
+ if selector[:deployed] && selector[:deployedOrReleased]
132
+ errors << "cannot specify both deployed=true and deployedOrReleased=true (at index #{index})"
133
+ end
134
+
135
+ if selector[:released] && selector[:deployedOrReleased]
136
+ errors << "cannot specify both released=true and deployedOrReleased=true (at index #{index})"
137
+ end
138
+
139
+ non_environment_fields = selector.slice(*BRANCH_KEYS).keys.sort
140
+ environment_related_fields = selector.slice(*ENVIRONMENT_KEYS).keys.sort
121
141
 
122
142
  if (non_environment_fields.any? && environment_related_fields.any?)
123
143
  errors << "cannot specify the #{pluralize("field", non_environment_fields.count)} #{non_environment_fields.join("/")} with the #{pluralize("field", environment_related_fields.count)} #{environment_related_fields.join("/")} (at index #{index})"
@@ -30,7 +30,6 @@ module PactBroker
30
30
  def self.call(params)
31
31
  select_first_message(flatten_indexed_messages(SCHEMA.call(params&.symbolize_keys).messages(full: true)))
32
32
  end
33
-
34
33
  end
35
34
  end
36
35
  end
@@ -15,6 +15,7 @@ module PactBroker
15
15
  property :provider_version_branch
16
16
 
17
17
  collection :consumer_version_selectors, default: PactBroker::Pacts::Selectors.new, class: PactBroker::Pacts::Selector do
18
+ property :main_branch
18
19
  property :tag
19
20
  property :branch, setter: -> (fragment:, represented:, **) {
20
21
  represented.branch = fragment
@@ -30,6 +31,11 @@ module PactBroker
30
31
  property :environment_name, as: :environment
31
32
  property :currently_deployed, as: :deployed
32
33
  property :currently_supported, as: :released
34
+ property :deployed_or_released,
35
+ setter: ->(represented:, **) {
36
+ represented.currently_deployed = true
37
+ represented.currently_supported = true
38
+ }
33
39
  end
34
40
 
35
41
  property :include_pending_status, default: false,
@@ -45,11 +51,29 @@ module PactBroker
45
51
  def from_hash(hash)
46
52
  # This handles both the snakecase keys from the GET query and the camelcase JSON POST body
47
53
  result = super(hash&.snakecase_keys)
54
+
55
+ result.consumer_version_selectors = split_out_deployed_or_released_selectors(result.consumer_version_selectors)
56
+
48
57
  if result.consumer_version_selectors && !result.consumer_version_selectors.is_a?(PactBroker::Pacts::Selectors)
49
58
  result.consumer_version_selectors = PactBroker::Pacts::Selectors.new(result.consumer_version_selectors)
50
59
  end
51
60
  result
52
61
  end
62
+
63
+ private
64
+
65
+ def split_out_deployed_or_released_selectors(consumer_version_selectors)
66
+ consumer_version_selectors.flat_map do | selector |
67
+ if selector.currently_deployed && selector.currently_supported
68
+ [
69
+ PactBroker::Pacts::Selector.new(selector.to_hash.without(:currently_supported)),
70
+ PactBroker::Pacts::Selector.new(selector.to_hash.without(:currently_deployed))
71
+ ]
72
+ else
73
+ [selector]
74
+ end
75
+ end
76
+ end
53
77
  end
54
78
  end
55
79
  end
@@ -1,11 +1,14 @@
1
1
  require "pact_broker/api/resources/base_resource"
2
2
  require "pact_broker/api/decorators/dashboard_decorator"
3
3
  require "pact_broker/api/decorators/dashboard_text_decorator"
4
+ require "pact_broker/api/resources/pagination_methods"
4
5
 
5
6
  module PactBroker
6
7
  module Api
7
8
  module Resources
8
9
  class Dashboard < BaseResource
10
+ include PaginationMethods
11
+
9
12
  def content_types_provided
10
13
  [
11
14
  ["application/hal+json", :to_json],
@@ -32,7 +35,7 @@ module PactBroker
32
35
  private
33
36
 
34
37
  def index_items
35
- index_service.find_index_items_for_api(identifier_from_path)
38
+ index_service.find_index_items_for_api(identifier_from_path.merge(pagination_options))
36
39
  end
37
40
  end
38
41
  end
@@ -5,11 +5,6 @@ module PactBroker
5
5
  module Api
6
6
  module Resources
7
7
  class DeployedVersionsForVersionAndEnvironment < BaseResource
8
- def initialize
9
- super
10
- @existing_deployed_version = version && environment && deployed_version_service.find_currently_deployed_version_for_version_and_environment_and_target(version, environment, target)
11
- end
12
-
13
8
  def content_types_accepted
14
9
  [["application/json", :from_json]]
15
10
  end
@@ -31,11 +26,12 @@ module PactBroker
31
26
  end
32
27
 
33
28
  def create_path
34
- deployed_version_url(existing_deployed_version || OpenStruct.new(uuid: deployed_version_uuid), base_url)
29
+ "dummy"
35
30
  end
36
31
 
37
32
  def from_json
38
- @deployed_version = existing_deployed_version || deployed_version_service.create(deployed_version_uuid, version, environment, target)
33
+ @deployed_version = deployed_version_service.find_or_create(deployed_version_uuid, version, environment, target)
34
+ response.headers["Location"] = deployed_version_url(deployed_version, base_url)
39
35
  response.body = decorator_class(:deployed_version_decorator).new(deployed_version).to_json(decorator_options)
40
36
  end
41
37
 
@@ -156,19 +156,17 @@ module PactBroker
156
156
  }]
157
157
  }
158
158
 
159
- if PactBroker.feature_enabled?(:environments)
160
- links_hash["pb:environments"] = {
161
- title: "Environments",
162
- href: environments_url(base_url),
163
- templated: false
164
- }
159
+ links_hash["pb:environments"] = {
160
+ title: "Environments",
161
+ href: environments_url(base_url),
162
+ templated: false
163
+ }
165
164
 
166
- links_hash["pb:environment"] = {
167
- title: "Environment",
168
- href: environments_url(base_url) + "/{uuid}",
169
- templated: true
170
- }
171
- end
165
+ links_hash["pb:environment"] = {
166
+ title: "Environment",
167
+ href: environments_url(base_url) + "/{uuid}",
168
+ templated: true
169
+ }
172
170
 
173
171
  if PactBroker.feature_enabled?("disable_pacts_for_verification", true)
174
172
  links_hash.delete("pb:provider-pacts-for-verification")
@@ -9,7 +9,7 @@ module PactBroker
9
9
  private
10
10
 
11
11
  def pacts
12
- pact_service.find_latest_pact_versions_for_provider provider_name, tag: identifier_from_path[:tag]
12
+ pact_service.find_latest_pacts_for_provider(provider_name, tag: identifier_from_path[:tag])
13
13
  end
14
14
 
15
15
  def resource_title
@@ -0,0 +1,14 @@
1
+ module PactBroker
2
+ module Api
3
+ module Resources
4
+ module PaginationMethods
5
+ def pagination_options
6
+ {
7
+ page_number: request.query["pageNumber"]&.to_i,
8
+ page_size: request.query["pageSize"]&.to_i
9
+ }.compact
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -23,6 +23,7 @@ module PactBroker
23
23
  # Make it return a 201 by setting the Location header
24
24
  response.headers["Location"] = tag_url(base_url, tag)
25
25
  end
26
+ create_deployed_version
26
27
  response.body = to_json
27
28
  end
28
29
 
@@ -46,6 +47,19 @@ module PactBroker
46
47
  def policy_name
47
48
  :'tags::tag'
48
49
  end
50
+
51
+ def create_deployed_version
52
+ if create_deployed_versions_for_tags?
53
+ if (environment = environment_service.find_by_name(identifier_from_path[:tag_name]))
54
+ deployed_version_service.find_or_create(deployed_version_service.next_uuid, tag.version, environment, nil)
55
+ end
56
+ end
57
+ end
58
+
59
+ # Come up with a cleaner way to abstract this for PF so it can be configured per tenant
60
+ def create_deployed_versions_for_tags?
61
+ PactBroker.configuration.create_deployed_versions_for_tags
62
+ end
49
63
  end
50
64
  end
51
65
  end
@@ -41,7 +41,8 @@ module PactBroker
41
41
  :allow_missing_migration_files,
42
42
  :auto_migrate_db_data,
43
43
  :use_rack_protection,
44
- :metrics_sql_statement_timeout
44
+ :metrics_sql_statement_timeout,
45
+ :create_deployed_versions_for_tags
45
46
  ]
46
47
 
47
48
  attr_accessor :base_url, :log_dir, :database_connection, :auto_migrate_db, :auto_migrate_db_data, :allow_missing_migration_files, :example_data_seeder, :seed_example_data, :use_hal_browser, :html_pact_renderer, :use_rack_protection
@@ -61,6 +62,7 @@ module PactBroker
61
62
  attr_reader :custom_logger
62
63
  attr_accessor :policy_builder, :policy_scope_builder, :base_resource_class_factory
63
64
  attr_accessor :metrics_sql_statement_timeout
65
+ attr_accessor :create_deployed_versions_for_tags
64
66
 
65
67
  alias_method :policy_finder=, :policy_builder=
66
68
  alias_method :policy_scope_finder=, :policy_scope_builder=
@@ -133,6 +135,7 @@ module PactBroker
133
135
  }
134
136
  config.warning_error_class_names = ["Sequel::ForeignKeyConstraintViolation", "PG::QueryCanceled"]
135
137
  config.metrics_sql_statement_timeout = 30
138
+ config.create_deployed_versions_for_tags = true
136
139
  config
137
140
  end
138
141
  # rubocop: enable Metrics/MethodLength
@@ -0,0 +1,28 @@
1
+ require "pact_broker/db/data_migrations/helpers"
2
+
3
+ module PactBroker
4
+ module DB
5
+ module DataMigrations
6
+ class SetConsumerVersionOrderForPactPublications
7
+ extend Helpers
8
+
9
+ def self.call connection
10
+ if required_columns_exist?(connection)
11
+ connection.from(:pact_publications)
12
+ .where(consumer_version_order: nil)
13
+ .update(
14
+ consumer_version_order: connection.from(:versions)
15
+ .select(:order)
16
+ .where(Sequel[:versions][:id] => Sequel[:pact_publications][:consumer_version_id])
17
+ )
18
+ end
19
+ end
20
+
21
+ def self.required_columns_exist?(connection)
22
+ columns_exist?(connection, :pact_publications, [:consumer_version_id, :consumer_version_order]) &&
23
+ columns_exist?(connection, :versions, [:id, :order])
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end