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
@@ -87,6 +87,7 @@ module PactBroker
87
87
  add ["pacticipants", :pacticipant_name, "latest-version"], Api::Resources::LatestVersion, {resource_name: "latest_pacticipant_version"}
88
88
  add ["pacticipants", :pacticipant_name, "versions", :pacticipant_version_number, "tags", :tag_name], Api::Resources::Tag, {resource_name: "pacticipant_version_tag"}
89
89
  add ["pacticipants", :pacticipant_name, "labels", :label_name], Api::Resources::Label, {resource_name: "pacticipant_label"}
90
+ add ["pacticipants", :pacticipant_name, "branches", :branch_name, "versions", :version_number], Api::Resources::BranchVersion, { resource_name: "branch_version" }
90
91
 
91
92
  # Webhooks
92
93
  add ["webhooks", "provider", :provider_name, "consumer", :consumer_name ], Api::Resources::PacticipantWebhooks, {resource_name: "pacticipant_webhooks"}
@@ -8,6 +8,18 @@ require "pact_broker/string_refinements"
8
8
  require "pact_broker/hash_refinements"
9
9
  require "pact_broker/error"
10
10
 
11
+ module Anyway
12
+ module Tracing
13
+ class << self
14
+ # Override this method so that we get the real caller location, not the forwardable one from
15
+ # the `extend Forwardable` in the PactBroker::Configuration class.
16
+ def current_trace_source
17
+ source_stack.last || accessor_source(caller_locations(2, 2).find { | location | !location.path.end_with?("forwardable.rb") })
18
+ end
19
+ end
20
+ end
21
+ end
22
+
11
23
  module PactBroker
12
24
  module Config
13
25
  class RuntimeConfiguration < Anyway::Config
@@ -76,7 +76,7 @@ module PactBroker
76
76
 
77
77
  def create_tags(parsed_contracts, version)
78
78
  (parsed_contracts.tags || []).collect do | tag_name |
79
- tag_repository.create(version: version, name: tag_name)
79
+ tag_service.create(pacticipant_name: version.pacticipant.name, pacticipant_version_number: version.number, tag_name: tag_name)
80
80
  end
81
81
  end
82
82
 
@@ -0,0 +1,97 @@
1
+ require "pact_broker/db/data_migrations/helpers"
2
+
3
+ module PactBroker
4
+ module DB
5
+ module DataMigrations
6
+ class CreateBranches
7
+ extend Helpers
8
+
9
+ def self.call connection
10
+ if required_columns_exist?(connection)
11
+ branch_ids = create_branch_versions(connection)
12
+ upsert_branch_heads(connection, branch_ids)
13
+ end
14
+ end
15
+
16
+ def self.required_columns_exist?(connection)
17
+ column_exists?(connection, :versions, :branch) &&
18
+ connection.table_exists?(:branches) &&
19
+ connection.table_exists?(:branch_versions) &&
20
+ connection.table_exists?(:branch_heads)
21
+ end
22
+
23
+ def self.create_branch_versions(connection)
24
+ versions_without_a_branch_version(connection).collect do | version |
25
+ create_branch_version(connection, version)
26
+ end.uniq
27
+ end
28
+
29
+ def self.upsert_branch_heads(connection, branch_ids)
30
+ branch_ids.each do | branch_id |
31
+ upsert_branch_head(connection, branch_id)
32
+ end
33
+ end
34
+
35
+ def self.versions_without_a_branch_version(connection)
36
+ branch_versions_join = {
37
+ Sequel[:versions][:id] => Sequel[:branch_versions][:version_id],
38
+ Sequel[:branch_versions][:branch_name] => Sequel[:versions][:branch]
39
+ }
40
+
41
+ connection[:versions]
42
+ .select(Sequel[:versions].*)
43
+ .exclude(branch: nil)
44
+ .left_outer_join(:branch_versions, branch_versions_join)
45
+ .where(Sequel[:branch_versions][:branch_name] => nil)
46
+ .order(:pacticipant_id, :order)
47
+ end
48
+
49
+ def self.create_branch_version(connection, version)
50
+ branch_values = {
51
+ name: version[:branch],
52
+ pacticipant_id: version[:pacticipant_id],
53
+ created_at: version[:created_at],
54
+ updated_at: version[:created_at]
55
+ }
56
+ connection[:branches].insert_ignore.insert(branch_values)
57
+ branch_id = connection[:branches].select(:id).where(pacticipant_id: version[:pacticipant_id], name: version[:branch]).single_record[:id]
58
+
59
+ branch_version_values = {
60
+ pacticipant_id: version[:pacticipant_id],
61
+ version_id: version[:id],
62
+ version_order: version[:order],
63
+ branch_id: branch_id,
64
+ branch_name: version[:branch],
65
+ created_at: version[:created_at],
66
+ updated_at: version[:created_at]
67
+ }
68
+
69
+ connection[:branch_versions].insert_ignore.insert(branch_version_values)
70
+ branch_id
71
+ end
72
+
73
+ def self.upsert_branch_head(connection, branch_id)
74
+ latest_branch_version = connection[:branch_versions].where(branch_id: branch_id).order(:version_order).last
75
+
76
+ if connection[:branch_heads].where(branch_id: branch_id).empty?
77
+ branch_head_values = {
78
+ pacticipant_id: latest_branch_version[:pacticipant_id],
79
+ branch_id: branch_id,
80
+ branch_version_id: latest_branch_version[:id],
81
+ version_id: latest_branch_version[:version_id],
82
+ branch_name: latest_branch_version[:branch_name]
83
+ }
84
+ connection[:branch_heads].insert(branch_head_values)
85
+ else
86
+ connection[:branch_heads]
87
+ .where(branch_id: branch_id)
88
+ .update(
89
+ branch_version_id: latest_branch_version[:id],
90
+ version_id: latest_branch_version[:version_id]
91
+ )
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -1,6 +1,8 @@
1
1
  require "pact_broker/db/data_migrations/helpers"
2
2
  require "pact_broker/logging"
3
3
 
4
+ # Not required now we have the auto_detect_main_branch feature
5
+
4
6
  module PactBroker
5
7
  module DB
6
8
  module DataMigrations
@@ -23,10 +23,10 @@ module PactBroker
23
23
  DataMigrations::SetCreatedAtForLatestVerifications.call(database_connection)
24
24
  DataMigrations::SetExtraColumnsForTags.call(database_connection)
25
25
  DataMigrations::SetPacticipantDisplayName.call(database_connection)
26
- DataMigrations::SetPacticipantMainBranch.call(database_connection)
27
26
  DataMigrations::SetWebhookUuid.call(database_connection)
28
27
  DataMigrations::SetConsumerVersionOrderForPactPublications.call(database_connection)
29
28
  DataMigrations::SetExtraColumnsForTags.call(database_connection)
29
+ DataMigrations::CreateBranches.call(database_connection)
30
30
  end
31
31
  end
32
32
  end
@@ -16,6 +16,9 @@ require "pact_broker/deployments/deployed_version"
16
16
  require "pact_broker/deployments/released_version"
17
17
  require "pact_broker/matrix/row"
18
18
  require "pact_broker/matrix/head_row"
19
+ require "pact_broker/versions/branch"
20
+ require "pact_broker/versions/branch_version"
21
+ require "pact_broker/versions/branch_head"
19
22
 
20
23
  module PactBroker
21
24
  INTEGRATIONS_TABLES = [
@@ -30,6 +33,9 @@ module PactBroker
30
33
  PactBroker::Domain::Tag,
31
34
  PactBroker::Deployments::DeployedVersion,
32
35
  PactBroker::Deployments::ReleasedVersion,
36
+ PactBroker::Versions::BranchHead,
37
+ PactBroker::Versions::BranchVersion,
38
+ PactBroker::Versions::Branch,
33
39
  PactBroker::Domain::Version,
34
40
  PactBroker::Domain::Label,
35
41
  PactBroker::Domain::Pacticipant
@@ -15,6 +15,10 @@ module PactBroker
15
15
  dataset_module do
16
16
  include PactBroker::Repositories::Helpers
17
17
 
18
+ def user_created
19
+ where(auto_created: false)
20
+ end
21
+
18
22
  def last_deployed_version(pacticipant, environment)
19
23
  currently_deployed
20
24
  .where(pacticipant_id: pacticipant.id)
@@ -17,7 +17,7 @@ module PactBroker
17
17
  DeployedVersion.where(uuid: uuid).single_record
18
18
  end
19
19
 
20
- def self.find_or_create(uuid, version, environment, target)
20
+ def self.find_or_create(uuid, version, environment, target, auto_created: false)
21
21
  if (deployed_version = find_currently_deployed_version_for_version_and_environment_and_target(version, environment, target))
22
22
  deployed_version
23
23
  else
@@ -27,7 +27,8 @@ module PactBroker
27
27
  version: version,
28
28
  pacticipant_id: version.pacticipant_id,
29
29
  environment: environment,
30
- target: target
30
+ target: target,
31
+ auto_created: auto_created
31
32
  )
32
33
  end
33
34
  end
@@ -76,7 +77,7 @@ module PactBroker
76
77
  if PactBroker.configuration.create_deployed_versions_for_tags
77
78
  if (environment = environment_service.find_by_name(environment_name))
78
79
  logger.info("Creating deployed version for #{version.pacticipant.name} version #{version.number} in environment #{environment_name} (because create_deployed_versions_for_tags=true)")
79
- find_or_create(next_uuid, version, environment, nil)
80
+ find_or_create(next_uuid, version, environment, nil, auto_created: true)
80
81
  end
81
82
  end
82
83
  end
@@ -25,6 +25,10 @@ module PactBroker
25
25
  PactBroker::Deployments::ReleasedVersion.where(environment: self).delete
26
26
  super
27
27
  end
28
+
29
+ def production?
30
+ production
31
+ end
28
32
  end
29
33
  end
30
34
  end
@@ -7,12 +7,17 @@ module PactBroker
7
7
  module Deployments
8
8
  module EnvironmentService
9
9
  using PactBroker::StringRefinements
10
+ extend self
10
11
 
11
- def self.next_uuid
12
+ def self.included(base)
13
+ base.extend(self)
14
+ end
15
+
16
+ def next_uuid
12
17
  SecureRandom.uuid
13
18
  end
14
19
 
15
- def self.create(uuid, environment)
20
+ def create(uuid, environment)
16
21
  environment.uuid = uuid
17
22
  if environment.display_name.blank?
18
23
  environment.display_name = PactBroker::Pacticipants::GenerateDisplayName.call(environment.name)
@@ -20,7 +25,7 @@ module PactBroker
20
25
  environment.save
21
26
  end
22
27
 
23
- def self.update(uuid, environment)
28
+ def update(uuid, environment)
24
29
  environment.uuid = uuid
25
30
  if environment.display_name.blank?
26
31
  environment.display_name = PactBroker::Pacticipants::GenerateDisplayName.call(environment.name)
@@ -28,23 +33,23 @@ module PactBroker
28
33
  environment.upsert
29
34
  end
30
35
 
31
- def self.find_all
36
+ def find_all
32
37
  PactBroker::Deployments::Environment.order(Sequel.function(:lower, :display_name)).all
33
38
  end
34
39
 
35
- def self.find(uuid)
40
+ def find(uuid)
36
41
  PactBroker::Deployments::Environment.where(uuid: uuid).single_record
37
42
  end
38
43
 
39
- def self.find_by_name(name)
44
+ def find_by_name(name)
40
45
  PactBroker::Deployments::Environment.where(name: name).single_record
41
46
  end
42
47
 
43
- def self.delete(uuid)
48
+ def delete(uuid)
44
49
  PactBroker::Deployments::Environment.where(uuid: uuid).delete
45
50
  end
46
51
 
47
- def self.find_for_pacticipant(_pacticipant)
52
+ def find_for_pacticipant(_pacticipant)
48
53
  find_all
49
54
  end
50
55
  end
@@ -0,0 +1,14 @@
1
+ # Pacticipant branch version
2
+
3
+ Allowed methods: `GET`, `PUT`
4
+
5
+ Path: `/pacticipants/{pacticipant}/branches/{branch}/versions/{version}`
6
+
7
+ Get or add/create a pacticipant version for a branch.
8
+
9
+ ## Example
10
+
11
+ Add a version to a branch. The pacticipant and branch are automatically created if they do not exist.
12
+
13
+ curl -XPUT http://broker/pacticipants/Bar/branches/main/versions/1e70030c6579915e5ff56b107a0fd25cf5df7464 \
14
+ -H "Content-Type: application/json" -d "{}"
@@ -108,6 +108,7 @@ The following variables may be used in the request path, parameters or body, and
108
108
  * `${pactbroker.providerLabels}`: the list of labels for the provider associated with the pact content, separated by ", ".
109
109
  * `${pactbroker.githubVerificationStatus}`: the verification status using the correct keywords for posting to the the [Github commit status API](https://developer.github.com/v3/repos/statuses).
110
110
  * `${pactbroker.bitbucketVerificationStatus}`: the verification status using the correct keywords for posting to the the [Bitbucket commit status API](https://developer.atlassian.com/server/bitbucket/how-tos/updating-build-status-for-commits/).
111
+ * `${pactbroker.gitlabVerificationStatus}`: the verification status using the correct keywords for posting to the the [Gitlab Commits API](https://docs.gitlab.com/ee/api/commits.html#post-the-build-status-to-a-commit).
111
112
  * `${pactbroker.verificationResultUrl}`: the URL to the relevant verification result.
112
113
 
113
114
  Example usage:
@@ -5,23 +5,25 @@ module PactBroker
5
5
  module Domain
6
6
  class IndexItem
7
7
  attr_reader :consumer,
8
- :provider,
9
- :latest_pact,
10
- :latest_verification,
11
- :webhooks,
12
- :triggered_webhooks,
13
- :latest_verification_latest_tags
8
+ :provider,
9
+ :consumer_version,
10
+ :latest_pact,
11
+ :latest_verification,
12
+ :webhooks,
13
+ :triggered_webhooks,
14
+ :latest_verification_latest_tags,
14
15
 
15
16
  # rubocop:disable Metrics/ParameterLists
16
- def self.create(consumer, provider, latest_pact, latest, latest_verification, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [], latest_for_branch = nil)
17
- new(consumer, provider, latest_pact, latest, latest_verification, webhooks, triggered_webhooks, tags, latest_verification_latest_tags, latest_for_branch)
17
+ def self.create(consumer, provider, consumer_version, latest_pact, latest, latest_verification, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [], latest_for_branch = nil)
18
+ new(consumer, provider, consumer_version, latest_pact, latest, latest_verification, webhooks, triggered_webhooks, tags, latest_verification_latest_tags, latest_for_branch)
18
19
  end
19
20
  # rubocop:enable Metrics/ParameterLists
20
21
 
21
22
  # rubocop:disable Metrics/ParameterLists
22
- def initialize(consumer, provider, latest_pact = nil, latest = true, latest_verification = nil, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [], latest_for_branch = nil)
23
+ def initialize(consumer, provider, consumer_version = nil, latest_pact = nil, latest = true, latest_verification = nil, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [], latest_for_branch = nil)
23
24
  @consumer = consumer
24
25
  @provider = provider
26
+ @consumer_version = consumer_version
25
27
  @latest_pact = latest_pact
26
28
  @latest = latest
27
29
  @latest_verification = latest_verification
@@ -68,12 +70,8 @@ module PactBroker
68
70
  consumer_version.order
69
71
  end
70
72
 
71
- def consumer_version
72
- @latest_pact.consumer_version
73
- end
74
-
75
- def consumer_version_branch
76
- consumer_version.branch
73
+ def consumer_version_branches
74
+ consumer_version.branch_heads.collect(&:branch_name)
77
75
  end
78
76
 
79
77
  def consumer_version_environment_names
@@ -92,8 +90,8 @@ module PactBroker
92
90
  @latest_verification ? @latest_verification.provider_version_number : nil
93
91
  end
94
92
 
95
- def provider_version_branch
96
- provider_version&.branch
93
+ def provider_version_branches
94
+ provider_version&.branch_heads&.collect(&:branch_name) || []
97
95
  end
98
96
 
99
97
  def provider_version_environment_names
@@ -22,6 +22,8 @@ module PactBroker
22
22
  one_to_many :labels, :order => :name, :reciprocal => :pacticipant
23
23
  one_to_many :pacts
24
24
  one_to_one :latest_version, :class => "PactBroker::Versions::LatestVersion", primary_key: :id, key: :pacticipant_id
25
+ one_to_many :branch_heads, class: "PactBroker::Versions::BranchHead", primary_key: :id, key: :pacticipant_id
26
+ one_to_many :branches, class: "PactBroker::Versions::Branch", primary_key: :id, key: :pacticipant_id
25
27
 
26
28
  dataset_module do
27
29
  include PactBroker::Repositories::Helpers
@@ -38,6 +40,10 @@ module PactBroker
38
40
  def find_by_name(name)
39
41
  where(name_like(:name, name))
40
42
  end
43
+
44
+ def where_name(name)
45
+ where(name_like(:name, name))
46
+ end
41
47
  end
42
48
 
43
49
  def before_destroy
@@ -66,6 +72,10 @@ module PactBroker
66
72
  def any_versions?
67
73
  PactBroker::Domain::Version.where(pacticipant: self).any?
68
74
  end
75
+
76
+ def branch_head_for(branch_name)
77
+ branch_heads.find{ | branch_head | branch_head.branch_name == branch_name }
78
+ end
69
79
  end
70
80
  end
71
81
  end
@@ -87,6 +97,7 @@ end
87
97
  # pacticipants_name_key | UNIQUE btree (name)
88
98
  # ndx_ppt_name | btree (name)
89
99
  # Referenced By:
100
+ # branches | branches_pacticipant_id_fkey | (pacticipant_id) REFERENCES pacticipants(id) ON DELETE CASCADE
90
101
  # currently_deployed_version_ids | currently_deployed_version_ids_pacticipant_id_fkey | (pacticipant_id) REFERENCES pacticipants(id) ON DELETE CASCADE
91
102
  # labels | labels_pacticipant_id_fkey | (pacticipant_id) REFERENCES pacticipants(id)
92
103
  # latest_pact_publication_ids_for_consumer_versions | latest_pact_publication_ids_for_consumer_versi_consumer_id_fkey | (consumer_id) REFERENCES pacticipants(id) ON DELETE CASCADE
@@ -130,6 +130,7 @@ module PactBroker
130
130
 
131
131
  # rubocop: disable Metrics/CyclomaticComplexity
132
132
  def before_save
133
+ super
133
134
  if version
134
135
  if version.order && self.version_order.nil?
135
136
  self.version_order = version.order
@@ -146,8 +147,6 @@ module PactBroker
146
147
 
147
148
  if version_order.nil? || pacticipant_id.nil?
148
149
  raise PactBroker::Error.new("Need to set version_order and pacticipant_id for tags now")
149
- else
150
- super
151
150
  end
152
151
  end
153
152
  # rubocop: enable Metrics/CyclomaticComplexity
@@ -222,23 +222,26 @@ end
222
222
 
223
223
  # Table: verifications
224
224
  # Columns:
225
- # id | integer | PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
226
- # number | integer |
227
- # success | boolean | NOT NULL
228
- # provider_version | text |
229
- # build_url | text |
230
- # pact_version_id | integer | NOT NULL
231
- # execution_date | timestamp without time zone | NOT NULL
232
- # created_at | timestamp without time zone | NOT NULL
233
- # provider_version_id | integer |
234
- # test_results | text |
235
- # consumer_id | integer |
236
- # provider_id | integer |
237
- # wip | boolean | NOT NULL DEFAULT false
225
+ # id | integer | PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
226
+ # number | integer |
227
+ # success | boolean | NOT NULL
228
+ # provider_version | text |
229
+ # build_url | text |
230
+ # pact_version_id | integer | NOT NULL
231
+ # execution_date | timestamp without time zone | NOT NULL
232
+ # created_at | timestamp without time zone | NOT NULL
233
+ # provider_version_id | integer |
234
+ # test_results | text |
235
+ # consumer_id | integer |
236
+ # provider_id | integer |
237
+ # wip | boolean | NOT NULL DEFAULT false
238
+ # consumer_version_selector_hashes | text |
239
+ # tag_names | text |
238
240
  # Indexes:
239
241
  # verifications_pkey | PRIMARY KEY btree (id)
240
242
  # verifications_pact_version_id_number_index | UNIQUE btree (pact_version_id, number)
241
243
  # verifications_consumer_id_index | btree (consumer_id)
244
+ # verifications_pact_version_id_id_index | btree (pact_version_id, id)
242
245
  # verifications_provider_id_consumer_id_index | btree (provider_id, consumer_id)
243
246
  # verifications_provider_id_index | btree (provider_id)
244
247
  # Foreign key constraints: