pact_broker 2.82.0 → 2.85.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +53 -0
  4. data/Dockerfile +1 -1
  5. data/db/migrations/20210815_add_provider_version_id_index_to_verifications.rb +7 -0
  6. data/db/migrations/20210816_create_branches_tables.rb +40 -0
  7. data/db/migrations/20210818_add_consumer_version_selectors_to_verification.rb +8 -0
  8. data/db/migrations/20210831_add_index_to_pact_publications.rb +7 -0
  9. data/db/migrations/20210908_add_auto_created.rb +24 -0
  10. data/db/migrations/20210913_add_pending_to_verifications.rb +7 -0
  11. data/issue-reproduction/Dockerfile-pact-broker +1 -1
  12. data/lib/pact/doc/markdown/consumer_contract_renderer.rb +3 -3
  13. data/lib/pact_broker/api/contracts/{verifiable_pacts_json_query_schema.rb → pacts_for_verification_json_query_schema.rb} +1 -1
  14. data/lib/pact_broker/api/contracts/{verifiable_pacts_query_schema.rb → pacts_for_verification_query_string_schema.rb} +1 -1
  15. data/lib/pact_broker/api/decorators/branch_version_decorator.rb +20 -0
  16. data/lib/pact_broker/api/decorators/dashboard_decorator.rb +4 -2
  17. data/lib/pact_broker/api/decorators/embedded_branch_version_decorator.rb +21 -0
  18. data/lib/pact_broker/api/decorators/embedded_tag_decorator.rb +0 -5
  19. data/lib/pact_broker/api/decorators/matrix_decorator.rb +11 -2
  20. data/lib/pact_broker/api/decorators/pacticipant_decorator.rb +8 -0
  21. data/lib/pact_broker/api/decorators/{verifiable_pacts_query_decorator.rb → pacts_for_verification_query_decorator.rb} +2 -2
  22. data/lib/pact_broker/api/decorators/reason_decorator.rb +2 -2
  23. data/lib/pact_broker/api/decorators/verification_summary_decorator.rb +1 -2
  24. data/lib/pact_broker/api/decorators/version_decorator.rb +1 -1
  25. data/lib/pact_broker/api/middleware/configuration.rb +33 -0
  26. data/lib/pact_broker/api/pact_broker_urls.rb +13 -1
  27. data/lib/pact_broker/api/renderers/html_pact_renderer.rb +15 -11
  28. data/lib/pact_broker/api/resources/branch_version.rb +48 -0
  29. data/lib/pact_broker/api/resources/index.rb +6 -0
  30. data/lib/pact_broker/api/resources/pact_versions_for_branch.rb +40 -0
  31. data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +6 -6
  32. data/lib/pact_broker/api/resources/verifications.rb +7 -2
  33. data/lib/pact_broker/api/resources/version.rb +0 -8
  34. data/lib/pact_broker/api.rb +2 -0
  35. data/lib/pact_broker/app.rb +2 -0
  36. data/lib/pact_broker/badges/service.rb +3 -1
  37. data/lib/pact_broker/config/runtime_configuration.rb +12 -0
  38. data/lib/pact_broker/configuration.rb +33 -29
  39. data/lib/pact_broker/contracts/service.rb +1 -1
  40. data/lib/pact_broker/db/clean/selector.rb +54 -0
  41. data/lib/pact_broker/db/clean.rb +7 -1
  42. data/lib/pact_broker/db/clean_incremental.rb +13 -5
  43. data/lib/pact_broker/db/data_migrations/create_branches.rb +97 -0
  44. data/lib/pact_broker/db/data_migrations/set_pacticipant_main_branch.rb +2 -0
  45. data/lib/pact_broker/db/migrate_data.rb +1 -1
  46. data/lib/pact_broker/db/models.rb +6 -0
  47. data/lib/pact_broker/deployments/deployed_version.rb +4 -0
  48. data/lib/pact_broker/deployments/deployed_version_service.rb +4 -3
  49. data/lib/pact_broker/deployments/environment.rb +4 -0
  50. data/lib/pact_broker/deployments/environment_service.rb +13 -8
  51. data/lib/pact_broker/diagnostic/resources/base_resource.rb +4 -0
  52. data/lib/pact_broker/diagnostic/resources/dependencies.rb +1 -1
  53. data/lib/pact_broker/diagnostic/resources/heartbeat.rb +2 -3
  54. data/lib/pact_broker/doc/views/index/pacticipant-branch-version.markdown +14 -0
  55. data/lib/pact_broker/doc/views/webhooks.markdown +1 -0
  56. data/lib/pact_broker/domain/index_item.rb +15 -17
  57. data/lib/pact_broker/domain/pacticipant.rb +11 -0
  58. data/lib/pact_broker/domain/tag.rb +1 -2
  59. data/lib/pact_broker/domain/verification.rb +29 -14
  60. data/lib/pact_broker/domain/version.rb +112 -29
  61. data/lib/pact_broker/domain/webhook.rb +22 -10
  62. data/lib/pact_broker/domain/webhook_request.rb +2 -2
  63. data/lib/pact_broker/index/service.rb +83 -28
  64. data/lib/pact_broker/locale/en.yml +4 -0
  65. data/lib/pact_broker/matrix/quick_row.rb +6 -6
  66. data/lib/pact_broker/matrix/service.rb +4 -0
  67. data/lib/pact_broker/matrix/unresolved_selector.rb +3 -2
  68. data/lib/pact_broker/metrics/service.rb +7 -1
  69. data/lib/pact_broker/pacts/metadata.rb +7 -2
  70. data/lib/pact_broker/pacts/pact_publication.rb +59 -25
  71. data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +113 -33
  72. data/lib/pact_broker/pacts/pact_publication_selector_dataset_module.rb +18 -13
  73. data/lib/pact_broker/pacts/pact_publication_wip_dataset_module.rb +16 -4
  74. data/lib/pact_broker/pacts/pact_version.rb +13 -1
  75. data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +4 -10
  76. data/lib/pact_broker/pacts/repository.rb +6 -1
  77. data/lib/pact_broker/pacts/selected_pact.rb +20 -0
  78. data/lib/pact_broker/pacts/selector.rb +98 -33
  79. data/lib/pact_broker/pacts/service.rb +21 -0
  80. data/lib/pact_broker/repositories.rb +5 -0
  81. data/lib/pact_broker/services.rb +9 -0
  82. data/lib/pact_broker/test/http_test_data_builder.rb +35 -9
  83. data/lib/pact_broker/test/test_data_builder.rb +32 -26
  84. data/lib/pact_broker/ui/app.rb +7 -1
  85. data/lib/pact_broker/ui/controllers/dashboard.rb +80 -0
  86. data/lib/pact_broker/ui/controllers/groups.rb +23 -8
  87. data/lib/pact_broker/ui/helpers/url_helper.rb +5 -1
  88. data/lib/pact_broker/ui/view_models/index_item.rb +56 -3
  89. data/lib/pact_broker/ui/view_models/matrix_branch.rb +39 -0
  90. data/lib/pact_broker/ui/view_models/matrix_line.rb +11 -16
  91. data/lib/pact_broker/ui/view_models/matrix_tag.rb +0 -1
  92. data/lib/pact_broker/ui/views/dashboard/show.haml +195 -0
  93. data/lib/pact_broker/ui/views/groups/show.html.erb +60 -14
  94. data/lib/pact_broker/ui/views/index/_dashboard_navbar.haml +7 -0
  95. data/lib/pact_broker/ui/views/index/_navbar.haml +0 -7
  96. data/lib/pact_broker/ui/views/index/show-with-tags.haml +14 -11
  97. data/lib/pact_broker/ui/views/index/show.haml +35 -13
  98. data/lib/pact_broker/ui/views/matrix/show.haml +15 -11
  99. data/lib/pact_broker/verifications/pseudo_branch_status.rb +2 -0
  100. data/lib/pact_broker/verifications/repository.rb +6 -11
  101. data/lib/pact_broker/verifications/service.rb +11 -5
  102. data/lib/pact_broker/version.rb +1 -1
  103. data/lib/pact_broker/versions/branch.rb +29 -0
  104. data/lib/pact_broker/versions/branch_head.rb +45 -0
  105. data/lib/pact_broker/versions/branch_service.rb +24 -0
  106. data/lib/pact_broker/versions/branch_version.rb +64 -0
  107. data/lib/pact_broker/versions/branch_version_repository.rb +34 -0
  108. data/lib/pact_broker/versions/eager_loaders.rb +0 -42
  109. data/lib/pact_broker/versions/repository.rb +25 -12
  110. data/lib/pact_broker/versions/service.rb +3 -22
  111. data/lib/pact_broker/webhooks/event_listener.rb +3 -3
  112. data/lib/pact_broker/webhooks/execution_configuration.rb +16 -0
  113. data/lib/pact_broker/webhooks/execution_configuration_creator.rb +3 -0
  114. data/lib/pact_broker/webhooks/job.rb +1 -1
  115. data/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +20 -3
  116. data/lib/pact_broker/webhooks/trigger_service.rb +2 -2
  117. data/lib/pact_broker/webhooks/webhook_execution_result.rb +3 -7
  118. data/lib/pact_broker/webhooks/webhook_request_logger.rb +4 -12
  119. data/lib/pact_broker/webhooks/webhook_request_template.rb +6 -8
  120. data/lib/sequel/plugins/insert_ignore.rb +4 -0
  121. data/lib/sequel/plugins/upsert.rb +4 -0
  122. data/pact_broker.gemspec +4 -0
  123. data/public/javascripts/index.js +152 -50
  124. data/public/javascripts/pact.js +14 -14
  125. data/public/stylesheets/index.css +1 -2
  126. data/public/stylesheets/pact.css +11 -0
  127. data/scaffolding/templates/decorator.rb.erb +3 -1
  128. data/scaffolding/templates/migration.erb +1 -1
  129. data/scaffolding/templates/model.erb +2 -2
  130. data/scaffolding/templates/repository.rb.erb +2 -2
  131. data/scaffolding/templates/repository_spec.rb.erb +1 -1
  132. data/scaffolding/templates/resource.erb +2 -2
  133. data/scaffolding/templates/resource_spec.rb.erb +1 -1
  134. data/scaffolding/templates/service.rb.erb +3 -3
  135. data/scaffolding/templates/service_spec.rb.erb +1 -1
  136. data/script/data/auto-create-things-for-tags.rb +2 -0
  137. data/script/data/branches.rb +35 -0
  138. data/script/data/contract-published-requiring-verification.rb +1 -1
  139. data/script/data/environments.rb +0 -0
  140. data/script/data/issue-494.rb +25 -0
  141. data/script/data/pending.rb +26 -0
  142. data/script/data/tags.rb +35 -0
  143. data/script/data/webhook.rb +22 -0
  144. data/script/seed.rb +50 -89
  145. data/spec/features/create_branch_version_spec.rb +29 -0
  146. data/spec/features/create_tag_spec.rb +1 -1
  147. data/spec/features/create_version_spec.rb +2 -4
  148. data/spec/features/delete_pact_versions_for_branch_spec.rb +34 -0
  149. data/spec/features/get_branch_version_spec.rb +12 -0
  150. data/spec/features/publish_pact_all_in_one_spec.rb +0 -1
  151. data/spec/features/update_version_spec.rb +0 -55
  152. data/spec/fixtures/approvals/modifiable_resources.approved.json +7 -0
  153. data/spec/fixtures/approvals/publish_contract_nothing_exists.approved.json +1 -2
  154. data/spec/fixtures/approvals/publish_contract_nothing_exists_with_webhook.approved.json +1 -2
  155. data/spec/fixtures/approvals/publish_contract_verification_already_exists.approved.json +1 -2
  156. data/spec/fixtures/dashboard.json +4 -2
  157. data/spec/integration/app_spec.rb +6 -6
  158. data/spec/integration/ui/index_spec.rb +0 -2
  159. data/spec/integration/ui/matrix_spec.rb +0 -1
  160. data/spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb +2 -2
  161. 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
  162. data/spec/lib/pact_broker/api/contracts/{verifiable_pacts_json_query_schema_spec.rb → pacts_for_verification_json_query_schema_spec.rb} +3 -3
  163. data/spec/lib/pact_broker/api/contracts/{verifiable_pacts_query_schema_spec.rb → pacts_for_verification_query_string_schema_spec.rb} +3 -3
  164. data/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb +7 -7
  165. data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +19 -4
  166. data/spec/lib/pact_broker/api/decorators/{verifiable_pacts_query_decorator_spec.rb → pacts_for_verification_query_decorator_spec.rb} +3 -3
  167. data/spec/lib/pact_broker/api/decorators/reason_decorator_spec.rb +2 -2
  168. data/spec/lib/pact_broker/api/decorators/verification_summary_decorator_spec.rb +2 -0
  169. data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +7 -3
  170. data/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +1 -1
  171. data/spec/lib/pact_broker/api/middleware/configuration_spec.rb +43 -0
  172. data/spec/lib/pact_broker/api/resources/verifications_spec.rb +6 -4
  173. data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +1 -1
  174. data/spec/lib/pact_broker/badges/service_spec.rb +22 -0
  175. data/spec/lib/pact_broker/contracts/service_spec.rb +24 -3
  176. data/spec/lib/pact_broker/db/clean_spec.rb +2 -2
  177. data/spec/lib/pact_broker/db/data_migrations/create_branches_spec.rb +57 -0
  178. data/spec/lib/pact_broker/diagnostic/resources/dependencies_spec.rb +4 -4
  179. data/spec/lib/pact_broker/diagnostic/resources/heartbeat_spec.rb +3 -4
  180. data/spec/lib/pact_broker/domain/index_item_spec.rb +1 -1
  181. data/spec/lib/pact_broker/domain/version_spec.rb +127 -36
  182. data/spec/lib/pact_broker/domain/webhook_request_spec.rb +2 -1
  183. data/spec/lib/pact_broker/domain/webhook_spec.rb +15 -5
  184. data/spec/lib/pact_broker/index/service_spec.rb +1 -5
  185. data/spec/lib/pact_broker/index/service_view_spec.rb +144 -0
  186. data/spec/lib/pact_broker/matrix/service_spec.rb +10 -1
  187. data/spec/lib/pact_broker/metrics/service_spec.rb +4 -1
  188. data/spec/lib/pact_broker/pacts/metadata_spec.rb +11 -3
  189. data/spec/lib/pact_broker/pacts/pact_publication_dataset_module_spec.rb +109 -10
  190. data/spec/lib/pact_broker/pacts/pact_publication_latest_verification_spec.rb +29 -0
  191. data/spec/lib/pact_broker/pacts/pact_publication_selector_dataset_module_spec.rb +3 -2
  192. data/spec/lib/pact_broker/pacts/pact_publication_spec.rb +5 -5
  193. data/spec/lib/pact_broker/pacts/repository_find_for_currently_deployed_spec.rb +2 -2
  194. data/spec/lib/pact_broker/pacts/repository_find_for_currently_supported_releases_spec.rb +2 -2
  195. data/spec/lib/pact_broker/pacts/repository_spec.rb +15 -2
  196. data/spec/lib/pact_broker/pacts/selector_spec.rb +45 -3
  197. data/spec/lib/pact_broker/pacts/service_spec.rb +61 -0
  198. data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +5 -5
  199. data/spec/lib/pact_broker/relationships/groupify_spec.rb +0 -5
  200. data/spec/lib/pact_broker/ui/view_models/index_item_spec.rb +21 -6
  201. data/spec/lib/pact_broker/verifications/pseudo_branch_status_spec.rb +9 -1
  202. data/spec/lib/pact_broker/verifications/repository_spec.rb +39 -30
  203. data/spec/lib/pact_broker/verifications/service_spec.rb +9 -5
  204. data/spec/lib/pact_broker/versions/branch_service_spec.rb +71 -0
  205. data/spec/lib/pact_broker/versions/branch_version_repository_spec.rb +81 -0
  206. data/spec/lib/pact_broker/versions/branch_version_spec.rb +27 -0
  207. data/spec/lib/pact_broker/versions/repository_spec.rb +91 -6
  208. data/spec/lib/pact_broker/versions/service_spec.rb +4 -3
  209. data/spec/lib/pact_broker/webhooks/job_spec.rb +4 -4
  210. data/spec/lib/pact_broker/webhooks/render_spec.rb +6 -0
  211. data/spec/lib/pact_broker/webhooks/trigger_service_spec.rb +9 -5
  212. data/spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb +6 -12
  213. data/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb +3 -2
  214. data/spec/lib/sequel/plugins/upsert_spec.rb +11 -5
  215. data/spec/migrations/44_add_provider_version_to_verification_spec.rb +6 -9
  216. data/spec/service_consumers/pact_helper.rb +2 -0
  217. data/spec/spec_helper.rb +1 -1
  218. data/spec/support/generated_markdown.md +3 -3
  219. metadata +90 -17
  220. data/lib/pact_broker/versions/lazy_loaders.rb +0 -13
  221. data/spec/lib/pact_broker/api/resources/webhook_execution_result_spec.rb +0 -56
@@ -0,0 +1,34 @@
1
+ module PactBroker
2
+ module Versions
3
+ class BranchVersionRepository
4
+ include PactBroker::Services
5
+
6
+ def add_branch(version, branch_name, auto_created: false)
7
+ branch = find_or_create_branch(version.pacticipant, branch_name)
8
+ branch_version = version.branch_version_for_branch(branch)
9
+ if branch_version
10
+ branch_version.update(updated_at: Sequel.datetime_class.now)
11
+ else
12
+ branch_version = PactBroker::Versions::BranchVersion.new(version: version, branch: branch, auto_created: auto_created).insert_ignore
13
+ PactBroker::Versions::BranchHead.new(branch: branch, branch_version: branch_version).upsert
14
+ end
15
+ pacticipant_service.maybe_set_main_branch(version.pacticipant, branch_name)
16
+ branch_version
17
+ end
18
+
19
+ private
20
+
21
+ def find_or_create_branch(pacticipant, branch_name)
22
+ find_branch(pacticipant, branch_name) || create_branch(pacticipant, branch_name)
23
+ end
24
+
25
+ def find_branch(pacticipant, branch_name)
26
+ PactBroker::Versions::Branch.where(pacticipant: pacticipant, name: branch_name).single_record
27
+ end
28
+
29
+ def create_branch(pacticipant, branch_name)
30
+ PactBroker::Versions::Branch.new(pacticipant: pacticipant, name: branch_name).insert_ignore
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,48 +1,6 @@
1
1
  module PactBroker
2
2
  module Versions
3
3
  module EagerLoaders
4
- class LatestVersionForBranch
5
- def self.call(eo, **_other)
6
- initialize_association(eo[:rows])
7
- populate_associations(eo[:rows])
8
- end
9
-
10
- def self.initialize_association(versions)
11
- versions.each{|version| version.associations[:latest_version_for_branch] = nil }
12
- end
13
-
14
- def self.populate_associations(versions)
15
- group_by_pacticipant_id(versions).each do | pacticipant, participant_versions |
16
- populate_associations_by_pacticipant(pacticipant, participant_versions)
17
- end
18
- end
19
-
20
- def self.group_by_pacticipant_id(versions)
21
- versions.to_a.group_by(&:pacticipant_id)
22
- end
23
-
24
- def self.populate_associations_by_pacticipant(pacticipant_id, versions)
25
- latest_versions_for_branches = latest_versions_for_pacticipant_branches(
26
- pacticipant_id,
27
- versions.collect(&:branch).uniq.compact,
28
- versions.first.class
29
- )
30
- self.populate_versions_with_branches(versions, latest_versions_for_branches)
31
- end
32
-
33
- def self.populate_versions_with_branches(versions, latest_versions_for_branches)
34
- versions.select(&:branch).each do | version |
35
- version.associations[:latest_version_for_branch] = latest_versions_for_branches[[version.pacticipant_id, version.branch]]
36
- end
37
- end
38
-
39
- def self.latest_versions_for_pacticipant_branches(pacticipant_id, branches, version_class)
40
- version_class.latest_versions_for_pacticipant_branches(pacticipant_id, branches).each_with_object({}) do | row, hash |
41
- hash[[row.pacticipant_id, row.branch]] = row
42
- end
43
- end
44
- end
45
-
46
4
  class LatestVersionForPacticipant
47
5
  def self.call(eo, **_other)
48
6
  populate_associations(eo[:rows])
@@ -2,6 +2,9 @@ require "sequel"
2
2
  require "pact_broker/logging"
3
3
  require "pact_broker/domain/version"
4
4
  require "pact_broker/tags/repository"
5
+ require "pact_broker/versions/branch"
6
+ require "pact_broker/versions/branch_version"
7
+ require "pact_broker/versions/branch_head"
5
8
 
6
9
  module PactBroker
7
10
  module Versions
@@ -49,22 +52,29 @@ module PactBroker
49
52
  end
50
53
 
51
54
  # There may be a race condition if two simultaneous requests come in to create the same version
52
- def create args
55
+ def create(args)
53
56
  logger.info "Upserting version #{args[:number]} for pacticipant_id=#{args[:pacticipant_id]}"
54
57
  version_params = {
55
58
  number: args[:number],
56
59
  pacticipant_id: args[:pacticipant_id],
57
60
  created_at: Sequel.datetime_class.now,
58
- updated_at: Sequel.datetime_class.now
59
- }
61
+ updated_at: Sequel.datetime_class.now,
62
+ build_url: args[:build_url]
63
+ }.compact
60
64
 
61
- PactBroker::Domain::Version.new(version_params).upsert
65
+
66
+ version = PactBroker::Domain::Version.new(version_params).upsert
67
+ # branch can't be set from CRUD on the version resource, but it's convenient to be able
68
+ # to make a version with a branch for internal code.
69
+ branch_version_repository.add_branch(version, args[:branch]) if args[:branch]
70
+ version
62
71
  end
63
72
 
64
73
  def create_or_update(pacticipant, version_number, open_struct_version)
65
74
  saved_version = PactBroker::Domain::Version.where(pacticipant_id: pacticipant.id, number: version_number).single_record
66
75
  params = open_struct_version.to_h
67
76
  tags = params.delete(:tags)
77
+ branch_name = params.delete(:branch)
68
78
  if saved_version
69
79
  saved_version.update(params)
70
80
  else
@@ -74,10 +84,11 @@ module PactBroker
74
84
  params.merge(
75
85
  pacticipant_id: pacticipant.id,
76
86
  number: version_number
77
- )
87
+ ).compact
78
88
  ).upsert
79
89
  end
80
90
 
91
+ branch_version_repository.add_branch(saved_version, branch_name) if branch_name
81
92
  replace_tags(saved_version, tags) if tags
82
93
  saved_version
83
94
  end
@@ -86,8 +97,7 @@ module PactBroker
86
97
  saved_version = PactBroker::Domain::Version.new(
87
98
  number: version_number,
88
99
  pacticipant: pacticipant,
89
- build_url: open_struct_version.build_url,
90
- branch: open_struct_version.branch
100
+ build_url: open_struct_version.build_url
91
101
  ).upsert
92
102
 
93
103
  if open_struct_version.tags
@@ -112,7 +122,15 @@ module PactBroker
112
122
  end
113
123
 
114
124
  def delete_by_id version_ids
125
+ branches = Versions::Branch.where(id: Versions::BranchHead.select(:branch_id).where(version_id: version_ids)).all # these will be deleted
115
126
  Domain::Version.where(id: version_ids).delete
127
+ branches.each do | branch |
128
+ new_head_branch_version = Versions::BranchVersion.find_latest_for_branch(branch)
129
+ if new_head_branch_version
130
+ PactBroker::Versions::BranchHead.new(branch: branch, branch_version: new_head_branch_version).upsert
131
+ end
132
+ end
133
+ nil
116
134
  end
117
135
 
118
136
  def delete_orphan_versions consumer, provider
@@ -129,11 +147,6 @@ module PactBroker
129
147
  PactBroker::Domain::Version.select_all_qualified.for_selector(selector).all
130
148
  end
131
149
 
132
- def set_branch_if_unset(version, branch)
133
- version.update(branch: branch) if version.branch.nil?
134
- version
135
- end
136
-
137
150
  def find_latest_version_from_main_branch(pacticipant)
138
151
  if pacticipant.main_branch
139
152
  latest_from_main_branch = PactBroker::Domain::Version
@@ -10,23 +10,6 @@ module PactBroker
10
10
  extend PactBroker::Services
11
11
  include PactBroker::Logging
12
12
 
13
- def self.conflict_errors(_existing_version, _open_struct_version, _version_url)
14
- # This validation is causing problems in the PF build when branches are merged
15
- # TODO remove this properly when re-doing the version -> branch relationship
16
- {}
17
- # if existing_version&.branch && open_struct_version.to_h.key?(:branch) && existing_version.branch != open_struct_version.branch
18
- # message_params = {
19
- # old_branch: existing_version&.branch,
20
- # new_branch: open_struct_version.branch,
21
- # version_url: version_url
22
- # }
23
- # error_message = message("errors.validation.cannot_modify_version_branch", message_params)
24
- # { branch: [error_message] }
25
- # else
26
- # {}
27
- # end
28
- end
29
-
30
13
  def self.find_latest_by_pacticpant_name params
31
14
  version_repository.find_latest_by_pacticpant_name params.fetch(:pacticipant_name)
32
15
  end
@@ -42,14 +25,12 @@ module PactBroker
42
25
  def self.create_or_overwrite(pacticipant_name, version_number, version)
43
26
  pacticipant = pacticipant_repository.find_by_name_or_create(pacticipant_name)
44
27
  version = version_repository.create_or_overwrite(pacticipant, version_number, version)
45
- pacticipant_service.maybe_set_main_branch(pacticipant, version.branch)
46
28
  version
47
29
  end
48
30
 
49
31
  def self.create_or_update(pacticipant_name, version_number, version)
50
32
  pacticipant = pacticipant_repository.find_by_name_or_create(pacticipant_name)
51
33
  version = version_repository.create_or_update(pacticipant, version_number, version)
52
- pacticipant_service.maybe_set_main_branch(pacticipant, version.branch)
53
34
  version
54
35
  end
55
36
 
@@ -66,9 +47,9 @@ module PactBroker
66
47
  end
67
48
 
68
49
  def self.maybe_set_version_branch_from_tag(version, tag_name)
69
- if use_tag_as_branch?(version) && !version.branch
70
- logger.info "Setting #{version.pacticipant.name} version #{version.number} branch to '#{tag_name}' from first tag (because use_first_tag_as_branch=true)"
71
- version_repository.set_branch_if_unset(version, tag_name)
50
+ if use_tag_as_branch?(version) && version.branch_versions.empty?
51
+ logger.info "Adding #{version.pacticipant.name} version #{version.number} to branch '#{tag_name}' (from first tag, because use_first_tag_as_branch=true)"
52
+ branch_version_repository.add_branch(version, tag_name, auto_created: true)
72
53
  end
73
54
  end
74
55
 
@@ -51,12 +51,12 @@ module PactBroker
51
51
 
52
52
  def log_detected_event
53
53
  event = detected_events.last
54
- logger.info "Event detected", payload: { event_name: event.name, event_comment: event.comment }
54
+ logger.debug "Event detected", payload: { event_name: event.name, event_comment: event.comment }
55
55
  if event.triggered_webhooks&.any?
56
- triggered_webhook_descriptions = event.triggered_webhooks.collect{ |tw| { webhook_uuid: tw.webhook_uuid, triggered_webhook_uuid: tw.uuid, webhook_description: tw.webhook.description } }
56
+ triggered_webhook_descriptions = event.triggered_webhooks.collect{ |tw| { event_name: event.name, webhook_uuid: tw.webhook_uuid, triggered_webhook_uuid: tw.uuid, webhook_description: tw.webhook.description } }
57
57
  logger.info "Triggered webhooks for #{event.name}", payload: { triggered_webhooks: triggered_webhook_descriptions }
58
58
  else
59
- logger.info "No enabled webhooks found for event #{event.name}"
59
+ logger.debug "No enabled webhooks found for event #{event.name}"
60
60
  end
61
61
  end
62
62
 
@@ -25,14 +25,30 @@ module PactBroker
25
25
  with_updated_attribute(logging_options: { failure_log_message: value })
26
26
  end
27
27
 
28
+ def with_retry_schedule(value)
29
+ with_updated_attribute(retry_schedule: value)
30
+ end
31
+
32
+ def with_http_success_codes(value)
33
+ with_updated_attribute(http_success_codes: value)
34
+ end
35
+
28
36
  def with_webhook_context(value)
29
37
  with_updated_attribute(webhook_context: value)
30
38
  end
31
39
 
40
+ def with_user_agent(value)
41
+ with_updated_attribute(user_agent: value)
42
+ end
43
+
32
44
  def webhook_context
33
45
  self[:webhook_context]
34
46
  end
35
47
 
48
+ def retry_schedule
49
+ self[:retry_schedule]
50
+ end
51
+
36
52
  def [](key)
37
53
  params[key]
38
54
  end
@@ -7,6 +7,9 @@ module PactBroker
7
7
  def self.call(resource)
8
8
  PactBroker::Webhooks::ExecutionConfiguration.new
9
9
  .with_show_response(PactBroker.configuration.show_webhook_response?)
10
+ .with_retry_schedule(PactBroker.configuration.webhook_retry_schedule)
11
+ .with_http_success_codes(PactBroker.configuration.webhook_http_code_success)
12
+ .with_user_agent(PactBroker.configuration.user_agent)
10
13
  .with_webhook_context(base_url: resource.base_url)
11
14
  end
12
15
  end
@@ -104,7 +104,7 @@ module PactBroker
104
104
  end
105
105
 
106
106
  def retry_schedule
107
- PactBroker.configuration.webhook_retry_schedule
107
+ data[:webhook_execution_configuration].retry_schedule
108
108
  end
109
109
  end
110
110
  end
@@ -14,6 +14,7 @@ module PactBroker
14
14
  GITHUB_VERIFICATION_STATUS = "pactbroker.githubVerificationStatus"
15
15
  BITBUCKET_VERIFICATION_STATUS = "pactbroker.bitbucketVerificationStatus"
16
16
  AZURE_DEV_OPS_VERIFICATION_STATUS = "pactbroker.azureDevOpsVerificationStatus"
17
+ GITLAB_VERIFICATION_STATUS = "pactbroker.gitlabVerificationStatus"
17
18
  CONSUMER_LABELS = "pactbroker.consumerLabels"
18
19
  PROVIDER_LABELS = "pactbroker.providerLabels"
19
20
  EVENT_NAME = "pactbroker.eventName"
@@ -33,6 +34,7 @@ module PactBroker
33
34
  GITHUB_VERIFICATION_STATUS,
34
35
  BITBUCKET_VERIFICATION_STATUS,
35
36
  AZURE_DEV_OPS_VERIFICATION_STATUS,
37
+ GITLAB_VERIFICATION_STATUS,
36
38
  CONSUMER_LABELS,
37
39
  PROVIDER_LABELS,
38
40
  EVENT_NAME,
@@ -46,13 +48,12 @@ module PactBroker
46
48
  @base_url = webhook_context.fetch(:base_url)
47
49
  end
48
50
 
49
- # rubocop: disable Metrics/CyclomaticComplexity
50
51
  def to_hash
51
52
  @hash ||= {
52
53
  PACT_URL => pact ? PactBroker::Api::PactBrokerUrls.pact_version_url_with_webhook_metadata(pact, base_url) : "",
53
54
  VERIFICATION_RESULT_URL => verification_url,
54
55
  CONSUMER_VERSION_NUMBER => consumer_version_number,
55
- PROVIDER_VERSION_NUMBER => verification ? verification.provider_version_number : "",
56
+ PROVIDER_VERSION_NUMBER => provider_version_number,
56
57
  PROVIDER_VERSION_TAGS => provider_version_tags,
57
58
  PROVIDER_VERSION_BRANCH => provider_version_branch,
58
59
  CONSUMER_VERSION_TAGS => consumer_version_tags,
@@ -62,13 +63,13 @@ module PactBroker
62
63
  GITHUB_VERIFICATION_STATUS => github_verification_status,
63
64
  BITBUCKET_VERIFICATION_STATUS => bitbucket_verification_status,
64
65
  AZURE_DEV_OPS_VERIFICATION_STATUS => azure_dev_ops_verification_status,
66
+ GITLAB_VERIFICATION_STATUS => gitlab_verification_status,
65
67
  CONSUMER_LABELS => pacticipant_labels(pact && pact.consumer),
66
68
  PROVIDER_LABELS => pacticipant_labels(pact && pact.provider),
67
69
  EVENT_NAME => event_name,
68
70
  CURRENTLY_DEPLOYED_PROVIDER_VERSION_NUMBER => currently_deployed_provider_version_number
69
71
  }
70
72
  end
71
- # rubocop: enable Metrics/CyclomaticComplexity
72
73
 
73
74
  private
74
75
 
@@ -98,6 +99,14 @@ module PactBroker
98
99
  end
99
100
  end
100
101
 
102
+ def gitlab_verification_status
103
+ if verification
104
+ verification.success ? "success" : "failed"
105
+ else
106
+ "pending"
107
+ end
108
+ end
109
+
101
110
  def verification_url
102
111
  if verification
103
112
  PactBroker::Api::PactBrokerUrls.verification_url(verification, base_url)
@@ -146,6 +155,14 @@ module PactBroker
146
155
  end
147
156
  end
148
157
 
158
+ def provider_version_number
159
+ if webhook_context[:provider_version_number]
160
+ webhook_context[:provider_version_number]
161
+ else
162
+ verification ? verification.provider_version_number : ""
163
+ end
164
+ end
165
+
149
166
  def provider_version_branch
150
167
  if webhook_context[:provider_version_branch]
151
168
  webhook_context[:provider_version_branch]
@@ -31,8 +31,8 @@ module PactBroker
31
31
  end
32
32
 
33
33
  def execute_triggered_webhook_now triggered_webhook, webhook_execution_configuration_hash
34
- webhook_execution_result = triggered_webhook.execute webhook_execution_configuration_hash
35
- webhook_repository.create_execution triggered_webhook, webhook_execution_result
34
+ webhook_execution_result = triggered_webhook.execute(webhook_execution_configuration_hash)
35
+ webhook_repository.create_execution(triggered_webhook, webhook_execution_result)
36
36
  webhook_execution_result
37
37
  end
38
38
 
@@ -6,20 +6,16 @@ module PactBroker
6
6
  class WebhookExecutionResult
7
7
  attr_reader :request, :response, :logs, :error
8
8
 
9
- def initialize(request, response, logs, error = nil)
9
+ def initialize(request, response, success, logs, error = nil)
10
10
  @request = PactBroker::Webhooks::HttpRequestWithRedactedHeaders.new(request)
11
11
  @response = response ? PactBroker::Webhooks::HttpResponseWithUtf8SafeBody.new(response) : nil
12
+ @success = success
12
13
  @logs = logs
13
14
  @error = error
14
15
  end
15
16
 
16
17
  def success?
17
- if response
18
- # Response HTTP Code must be in success list otherwise it is false
19
- PactBroker.configuration.webhook_http_code_success.include? response.code.to_i
20
- else
21
- false
22
- end
18
+ @success
23
19
  end
24
20
  end
25
21
  end
@@ -29,15 +29,17 @@ module PactBroker
29
29
  @options = options
30
30
  end
31
31
 
32
- def log(uuid, webhook_request, http_response, error, webhook_context)
32
+ # rubocop: disable Metrics/ParameterLists
33
+ def log(uuid, webhook_request, http_response, success, error, webhook_context)
33
34
  safe_response = http_response ? HttpResponseWithUtf8SafeBody.new(http_response) : nil
34
35
  log_webhook_context(webhook_context)
35
36
  log_request(webhook_request)
36
37
  log_response(uuid, safe_response, webhook_context[:base_url]) if safe_response
37
38
  log_error(uuid, error, webhook_context[:base_url]) if error
38
- log_completion_message(success?(safe_response))
39
+ log_completion_message(success)
39
40
  log_stream.string
40
41
  end
42
+ # rubocop: enable Metrics/ParameterLists
41
43
 
42
44
  private
43
45
 
@@ -115,16 +117,6 @@ module PactBroker
115
117
  execution_logger.error "Error executing webhook #{uuid}. #{response_body_hidden_message(base_url)}"
116
118
  end
117
119
  end
118
-
119
- def success?(response)
120
- if response
121
- # Response HTTP Code must be in success list otherwise it is false
122
- PactBroker.configuration.webhook_http_code_success.include? response.code.to_i
123
- else
124
- false
125
- end
126
- end
127
-
128
120
  end
129
121
  end
130
122
  end