pact_broker 2.93.1 → 2.94.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +49 -0
  3. data/db/migrations/migration_helper.rb +1 -1
  4. data/lib/db.rb +1 -1
  5. data/lib/pact_broker/api/decorators/format_date_time.rb +9 -1
  6. data/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment.rb +50 -0
  7. data/lib/pact_broker/api/resources/{can_i_deploy_pacticipant_version.rb → can_i_deploy_pacticipant_version_by_tag_to_tag.rb} +17 -14
  8. data/lib/pact_broker/api.rb +7 -3
  9. data/lib/pact_broker/badges/service.rb +1 -1
  10. data/lib/pact_broker/build_http_options.rb +4 -12
  11. data/lib/pact_broker/certificates/service.rb +3 -3
  12. data/lib/pact_broker/config/runtime_configuration_database_methods.rb +1 -1
  13. data/lib/pact_broker/date_helper.rb +0 -4
  14. data/lib/pact_broker/domain/pact.rb +1 -1
  15. data/lib/pact_broker/domain/version.rb +7 -0
  16. data/lib/pact_broker/domain/webhook.rb +1 -1
  17. data/lib/pact_broker/domain/webhook_request.rb +2 -2
  18. data/lib/pact_broker/locale/en.yml +3 -0
  19. data/lib/pact_broker/matrix/quick_row.rb +11 -9
  20. data/lib/pact_broker/matrix/repository.rb +6 -5
  21. data/lib/pact_broker/matrix/unresolved_selector.rb +1 -0
  22. data/lib/pact_broker/metrics/service.rb +1 -1
  23. data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +19 -3
  24. data/lib/pact_broker/pacts/selector.rb +4 -4
  25. data/lib/pact_broker/pacts/service.rb +3 -3
  26. data/lib/pact_broker/pacts/sort_content.rb +1 -1
  27. data/lib/pact_broker/repositories/helpers.rb +1 -1
  28. data/lib/pact_broker/string_refinements.rb +9 -0
  29. data/lib/pact_broker/ui/controllers/base_controller.rb +8 -0
  30. data/lib/pact_broker/ui/controllers/matrix.rb +1 -1
  31. data/lib/pact_broker/ui/views/dashboard/show.haml +30 -12
  32. data/lib/pact_broker/ui/views/matrix/show.haml +8 -8
  33. data/lib/pact_broker/version.rb +1 -1
  34. data/lib/pact_broker/versions/repository.rb +8 -0
  35. data/lib/pact_broker/versions/service.rb +4 -0
  36. data/lib/pact_broker/webhooks/execution_configuration.rb +8 -0
  37. data/lib/pact_broker/webhooks/execution_configuration_creator.rb +5 -0
  38. data/lib/pact_broker/webhooks/webhook_request_template.rb +4 -2
  39. data/lib/sequel/plugins/upsert.rb +1 -1
  40. data/vendor/hal-browser/browser.html +107 -87
  41. data/vendor/hal-browser/js/hal/http/client.js +1 -1
  42. data/vendor/hal-browser/js/hal/views/browser.js +1 -1
  43. data/vendor/hal-browser/js/hal/views/embedded_resource.js +1 -1
  44. data/vendor/hal-browser/js/hal/views/explorer.js +1 -1
  45. data/vendor/hal-browser/js/hal/views/inspector.js +1 -1
  46. data/vendor/hal-browser/login.html +8 -9
  47. data/vendor/hal-browser/styles.css +6 -9
  48. data/vendor/hal-browser/vendor/bootstrap-icons-1.7.2/bootstrap-icons.css +1556 -0
  49. data/vendor/hal-browser/vendor/bootstrap-icons-1.7.2/bootstrap-icons.json +1537 -0
  50. data/vendor/hal-browser/vendor/bootstrap-icons-1.7.2/bootstrap-icons.scss +3097 -0
  51. data/vendor/hal-browser/vendor/bootstrap-icons-1.7.2/file-text-fill.svg +3 -0
  52. data/vendor/hal-browser/vendor/bootstrap-icons-1.7.2/fonts/bootstrap-icons.woff +0 -0
  53. data/vendor/hal-browser/vendor/bootstrap-icons-1.7.2/fonts/bootstrap-icons.woff2 +0 -0
  54. data/vendor/hal-browser/vendor/css/bootstrap.css +8530 -4374
  55. data/vendor/hal-browser/vendor/js/URI.min.js +92 -83
  56. data/vendor/hal-browser/vendor/js/bootstrap.js +3825 -1745
  57. data/vendor/hal-browser/vendor/js/jquery-3.6.0.min.js +2 -0
  58. data/vendor/hal-browser/vendor/js/underscore.js +6 -1227
  59. metadata +15 -12
  60. data/public/bootstrap.zip +0 -0
  61. data/vendor/hal-browser/vendor/css/bootstrap-responsive.css +0 -1109
  62. data/vendor/hal-browser/vendor/js/jquery-1.10.2.js +0 -9789
  63. data/vendor/hal-browser/vendor/js/jquery-1.10.2.min.js +0 -6
  64. data/vendor/hal-browser/vendor/js/jquery-1.10.2.min.map +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de53f660bed816c0008b97aa61e0a83048b25ad3661d64c9ffdf2afae4c172e7
4
- data.tar.gz: 20a5cbff3cc5b088e10d7291230fd80192d133c8f69ffadd551a123a35010f84
3
+ metadata.gz: 15cc9869c313dbadd50a4bcc89d3912717cc5f8512af30326b716d2a3cc636ad
4
+ data.tar.gz: 5d8c0f7240e7b312e096afb75ab8d2f9b91a9f26284be9e90e680bc59615cb02
5
5
  SHA512:
6
- metadata.gz: 7010895f3d08993533b1a9b9cd6521ffe5e2e49a83bf3721938d9b1fa18dcf3510639b0b08747dc3c27a823c4562787566e345d50ff306f9a793e878411f16c8
7
- data.tar.gz: 85ddcc1ad9a17391ef4aa0c27e7d8f9e9e2a873c3acd89a8b67f42dd609198d2f4866a3e0d83857cc7e3b15028c5257e360867fb0c3dfe0487083d5eff2c2b1f
6
+ metadata.gz: 1d223aa03faeac6cda65c71fab594b2bebed430690758ba768b34002e50434acfd556629593909aad8e494e59c26a067abf0243dae0345b482f9f111065e46ff
7
+ data.tar.gz: db169a6db83b20c37e28bacf7e83975f89fa204e41ed8c75a58708a658b6ae3177f7235a32a54db2138d0a5f9f471a92f3e6934f00d222fa6b8310ba987e55e0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,52 @@
1
+ <a name="v2.94.0"></a>
2
+ ### v2.94.0 (2022-02-22)
3
+
4
+ #### Features
5
+
6
+ * add can-i-deploy endpoint for checking if the latest version for a branch can be deployed to a particular environment ([34b145e8](/../../commit/34b145e8))
7
+ * truncate tags, branches and versions in UI when they are super long (#513) ([94bbf915](/../../commit/94bbf915))
8
+
9
+ * **integration dashboard**
10
+ * add copy buttons next to the branch, tag and environment labels ([5b86ac88](/../../commit/5b86ac88))
11
+
12
+ #### Bug Fixes
13
+
14
+ * Improve Matrix request performance (#537) ([123f8629](/../../commit/123f8629))
15
+ * Eagerly load pact publication fields (#536) ([c3f6993b](/../../commit/c3f6993b))
16
+
17
+ * **hal-browser**
18
+ * properties accordion should be collapsed by default (#544) ([19466121](/../../commit/19466121))
19
+
20
+ <a name="v2.93.4"></a>
21
+ ### v2.93.4 (2022-02-21)
22
+
23
+ #### Bug Fixes
24
+
25
+ * **matrix page**
26
+ * set correct base URL for links when a path is specified in the base URL ([8305456b](/../../commit/8305456b))
27
+
28
+ * handle DateTimes that come back from Sqlite as Strings ([1312a049](/../../commit/1312a049))
29
+
30
+ <a name="v2.93.3"></a>
31
+ ### v2.93.3 (2022-02-02)
32
+
33
+ #### Bug Fixes
34
+
35
+ * ensure webhook_certificates setting is honoured in webhook ([7933a526](/../../commit/7933a526))
36
+ * ensure disable_ssl_verification setting is honoured in webhook ([08bc758c](/../../commit/08bc758c))
37
+ * ensure webhook_certificates setting is honoured in webhook ([8a720cdb](/../../commit/8a720cdb))
38
+ * ensure disable_ssl_verification setting is honoured in webhook ([0728b3d7](/../../commit/0728b3d7))
39
+
40
+ * **hal-browser**
41
+ * fixing vulnerability by upgrading HAL browser dependencies ([a6b06f66](/../../commit/a6b06f66))
42
+
43
+ <a name="v2.93.2"></a>
44
+ ### v2.93.2 (2021-12-23)
45
+
46
+ #### Bug Fixes
47
+
48
+ * Improve SortContent performance on large contracts (#538) ([1914c01f](/../../commit/1914c01f))
49
+
1
50
  <a name="v2.93.1"></a>
2
51
  ### v2.93.1 (2021-12-21)
3
52
 
@@ -23,7 +23,7 @@ module PactBroker
23
23
  end
24
24
 
25
25
  def postgres?
26
- adapter == "postgres"
26
+ adapter =~ /postgres/
27
27
  end
28
28
 
29
29
  def adapter
data/lib/db.rb CHANGED
@@ -71,7 +71,7 @@ module DB
71
71
  end
72
72
 
73
73
  def self.postgres?
74
- !!(PACT_BROKER_DB.adapter_scheme.to_s == "postgres")
74
+ !!(PACT_BROKER_DB.adapter_scheme.to_s =~ /postgres/)
75
75
  end
76
76
 
77
77
  PACT_BROKER_DB ||= connection_for_env ENV.fetch("RACK_ENV")
@@ -2,8 +2,16 @@ module PactBroker
2
2
  module Api
3
3
  module Decorators
4
4
  module FormatDateTime
5
+ # Keep this in sync with Sequel.datetime_class.
6
+ # Needs to be upgraded from DateTime to Time as Time is deprecated
7
+ DATE_TIME_CLASS = DateTime
8
+
5
9
  def self.call(date_time)
6
- date_time.to_time.utc.to_datetime.xmlschema if date_time
10
+ if date_time.is_a?(String)
11
+ DATE_TIME_CLASS.strptime(date_time).to_time.utc.to_datetime.xmlschema
12
+ elsif date_time
13
+ date_time.to_time.utc.to_datetime.xmlschema if date_time
14
+ end
7
15
  end
8
16
 
9
17
  def format_date_time(date_time)
@@ -0,0 +1,50 @@
1
+ require "pact_broker/api/resources/matrix"
2
+ require "pact_broker/matrix/can_i_deploy_query_schema"
3
+ require "pact_broker/matrix/parse_can_i_deploy_query"
4
+
5
+ module PactBroker
6
+ module Api
7
+ module Resources
8
+ class CanIDeployPacticipantVersionByBranchToEnvironment < Matrix
9
+ def resource_exists?
10
+ !!(version && environment)
11
+ end
12
+
13
+ def malformed_request?
14
+ false
15
+ end
16
+
17
+ def policy_name
18
+ :'matrix::can_i_deploy'
19
+ end
20
+
21
+ private
22
+
23
+ def selectors
24
+ @selectors ||= [
25
+ PactBroker::Matrix::UnresolvedSelector.new(
26
+ pacticipant_name: pacticipant_name,
27
+ latest: true,
28
+ branch: identifier_from_path[:branch_name]
29
+ )
30
+ ]
31
+ end
32
+
33
+ def options
34
+ @options ||= {
35
+ latestby: "cvp",
36
+ environment_name: identifier_from_path[:environment_name]
37
+ }
38
+ end
39
+
40
+ def version
41
+ @version ||= version_service.find_latest_by_pacticipant_name_and_branch_name(identifier_from_path[:pacticipant_name], identifier_from_path[:branch_name])
42
+ end
43
+
44
+ def environment
45
+ @environment ||= environment_service.find_by_name(identifier_from_path[:environment_name])
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -5,7 +5,7 @@ require "pact_broker/matrix/parse_can_i_deploy_query"
5
5
  module PactBroker
6
6
  module Api
7
7
  module Resources
8
- class CanIDeployPacticipantVersion < Matrix
8
+ class CanIDeployPacticipantVersionByTagToTag < Matrix
9
9
  def resource_exists?
10
10
  !!version
11
11
  end
@@ -14,26 +14,29 @@ module PactBroker
14
14
  :'matrix::can_i_deploy'
15
15
  end
16
16
 
17
+ def malformed_request?
18
+ false
19
+ end
20
+
17
21
  private
18
22
 
19
23
  def selectors
20
- @selectors ||= begin
21
- [
22
- PactBroker::Matrix::UnresolvedSelector.new(
23
- pacticipant_name: pacticipant_name,
24
- latest: true,
25
- tag: identifier_from_path[:tag]
26
- )
27
- ]
28
- end
24
+ @selectors ||= [
25
+ PactBroker::Matrix::UnresolvedSelector.new(
26
+ pacticipant_name: pacticipant_name,
27
+ latest: true,
28
+ tag: identifier_from_path[:tag],
29
+ )
30
+ ]
31
+
29
32
  end
30
33
 
31
34
  def options
32
35
  @options ||= {
33
- latestby: "cvp",
34
- latest: true,
35
- tag: identifier_from_path[:to]
36
- }
36
+ latestby: "cvp",
37
+ latest: true,
38
+ tag: identifier_from_path[:to]
39
+ }
37
40
  end
38
41
 
39
42
  def version
@@ -81,15 +81,19 @@ module PactBroker
81
81
  add ["pacticipants"], Api::Resources::Pacticipants, {resource_name: "pacticipants"}
82
82
  add ["pacticipants", "label", :label_name], PactBroker::Api::Resources::PacticipantsForLabel, {resource_name: "pacticipants_for_label"}
83
83
  add ["pacticipants", :pacticipant_name], Api::Resources::Pacticipant, {resource_name: "pacticipant"}
84
+ add ["pacticipants", :pacticipant_name, "labels", :label_name], Api::Resources::Label, {resource_name: "pacticipant_label"}
85
+
86
+ # Versions
84
87
  add ["pacticipants", :pacticipant_name, "versions"], Api::Resources::Versions, {resource_name: "pacticipant_versions"}
85
88
  add ["pacticipants", :pacticipant_name, "versions", :pacticipant_version_number], Api::Resources::Version, {resource_name: "pacticipant_version"}
86
89
  add ["pacticipants", :pacticipant_name, "latest-version", :tag], Api::Resources::LatestVersion, {resource_name: "latest_tagged_pacticipant_version"}
87
- add ["pacticipants", :pacticipant_name, "latest-version", :tag, "can-i-deploy", "to", :to], Api::Resources::CanIDeployPacticipantVersion, { resource_name: "can_i_deploy_latest_tagged_version" }
88
- add ["pacticipants", :pacticipant_name, "latest-version", :tag, "can-i-deploy", "to", :to, "badge"], Api::Resources::CanIDeployBadge, { resource_name: "can_i_deploy_badge" }
90
+ add ["pacticipants", :pacticipant_name, "latest-version", :tag, "can-i-deploy", "to", :to], Api::Resources::CanIDeployPacticipantVersionByTagToTag, { resource_name: "can_i_deploy_latest_tagged_version_to_tag" }
91
+ add ["pacticipants", :pacticipant_name, "latest-version", :tag, "can-i-deploy", "to", :to, "badge"], Api::Resources::CanIDeployBadge, { resource_name: "can_i_deploy_latest_tagged_version_to_tag_badge" }
89
92
  add ["pacticipants", :pacticipant_name, "latest-version"], Api::Resources::LatestVersion, {resource_name: "latest_pacticipant_version"}
90
93
  add ["pacticipants", :pacticipant_name, "versions", :pacticipant_version_number, "tags", :tag_name], Api::Resources::Tag, {resource_name: "pacticipant_version_tag"}
91
- add ["pacticipants", :pacticipant_name, "labels", :label_name], Api::Resources::Label, {resource_name: "pacticipant_label"}
92
94
  add ["pacticipants", :pacticipant_name, "branches", :branch_name, "versions", :version_number], Api::Resources::BranchVersion, { resource_name: "branch_version" }
95
+ add ["pacticipants", :pacticipant_name, "branches", :branch_name, "latest-version", "can-i-deploy", "to-environment", :environment_name], Api::Resources::CanIDeployPacticipantVersionByBranchToEnvironment, { resource_name: "can_i_deploy_latest_branch_version_to_environment" }
96
+ #add ["pacticipants", :pacticipant_name, "branches", :branch_name, "latest-version", "can-i-deploy", "to-environment", :environment_name, "badge"], Api::Resources::CanIDeployPacticipantVersionByBranchToEnvironment, { resource_name: "can_i_deploy_latest_branch_version_to_environment_badge" }
93
97
 
94
98
  # Webhooks
95
99
  add ["webhooks", "provider", :provider_name, "consumer", :consumer_name ], Api::Resources::PacticipantWebhooks, {resource_name: "pacticipant_webhooks"}
@@ -132,7 +132,7 @@ module PactBroker
132
132
  with_cache uri do
133
133
  request = Net::HTTP::Get.new(uri)
134
134
  options = {read_timeout: 3, open_timeout: 1, ssl_timeout: 1, continue_timeout: 1}
135
- options.merge! PactBroker::BuildHttpOptions.call(uri)
135
+ options.merge! PactBroker::BuildHttpOptions.call(uri, disable_ssl_verification: PactBroker.configuration.disable_ssl_verification)
136
136
 
137
137
  Net::HTTP.start(uri.hostname, uri.port, :ENV, options) do |http|
138
138
  http.request request
@@ -4,14 +4,14 @@ module PactBroker
4
4
  class BuildHttpOptions
5
5
  extend PactBroker::Services
6
6
 
7
- def self.call uri
7
+ def self.call uri, disable_ssl_verification: false, cert_store: nil
8
8
  uri = URI(uri)
9
9
  options = {}
10
-
10
+
11
11
  if uri.scheme == "https"
12
12
  options[:use_ssl] = true
13
- options[:cert_store] = cert_store
14
- if disable_ssl_verification?
13
+ options[:cert_store] = cert_store if cert_store
14
+ if disable_ssl_verification
15
15
  options[:verify_mode] = OpenSSL::SSL::VERIFY_NONE
16
16
  else
17
17
  options[:verify_mode] = OpenSSL::SSL::VERIFY_PEER
@@ -19,14 +19,6 @@ module PactBroker
19
19
  end
20
20
  options
21
21
  end
22
-
23
- def self.disable_ssl_verification?
24
- PactBroker.configuration.disable_ssl_verification
25
- end
26
-
27
- def self.cert_store
28
- certificate_service.cert_store
29
- end
30
22
  end
31
23
  end
32
24
 
@@ -15,7 +15,7 @@ module PactBroker
15
15
  cert_store.set_default_paths
16
16
  find_all_certificates.each do | certificate |
17
17
  begin
18
- logger.debug("Loading certificate #{certificate.subject} in to cert store")
18
+ logger.debug("Loading certificate for subject #{certificate.subject} and issuer #{certificate.issuer} in to cert store")
19
19
  cert_store.add_cert(certificate)
20
20
  rescue StandardError => e
21
21
  logger.warn("Error adding certificate object #{certificate} to store", e)
@@ -42,7 +42,7 @@ module PactBroker
42
42
  end
43
43
 
44
44
  def certificates_from_config
45
- PactBroker.configuration.webhook_certificates.select{| c| c[:content] || c[:path] }.collect do | certificate_config, i |
45
+ PactBroker.configuration.webhook_certificates.select{| c| c[:content] || c[:path] }.collect.with_index do | certificate_config, i |
46
46
  load_certificate_config(certificate_config, i)
47
47
  end.flatten.compact
48
48
  end
@@ -54,7 +54,7 @@ module PactBroker
54
54
  begin
55
55
  OpenSSL::X509::Certificate.new(c)
56
56
  rescue StandardError => e
57
- logger.warn("Error creating certificate object from webhook_certificate at index #{i} with description #{certificate_config[:description]}", e)
57
+ logger.warn("Error creating certificate object from webhook_certificates at index #{i} with description #{certificate_config[:description]}", e)
58
58
  nil
59
59
  end
60
60
  end
@@ -72,7 +72,7 @@ module PactBroker
72
72
  end
73
73
 
74
74
  def postgres?
75
- database_credentials[:adapter] == "postgres"
75
+ database_credentials[:adapter] =~ /postgres/
76
76
  end
77
77
  private :postgres?
78
78
 
@@ -4,7 +4,6 @@ module PactBroker
4
4
  extend self
5
5
 
6
6
  # Ripped from actionview/lib/action_view/helpers/date_helper.rb
7
-
8
7
  def local_date_in_words datetime
9
8
  datetime.to_time.localtime.to_datetime.strftime("%a %d %b %Y, %l:%M%P %:z").gsub(" ", " ")
10
9
  end
@@ -31,9 +30,6 @@ module PactBroker
31
30
  distance_in_minutes = ((to_time - from_time)/60.0).round
32
31
  distance_in_seconds = (to_time - from_time).round
33
32
 
34
- # require 'pry'; pry(binding);
35
-
36
- # locale = I18n.with_options :locale => options[:locale], :scope => options[:scope]
37
33
  locale = Locale.new(:locale => options[:locale], :scope => options[:scope])
38
34
  case distance_in_minutes
39
35
  when 0..1
@@ -41,7 +41,7 @@ module PactBroker
41
41
  end
42
42
 
43
43
  def consumer
44
- consumer_version.pacticipant
44
+ @consumer || consumer_version.pacticipant
45
45
  end
46
46
 
47
47
  def consumer_version_tag_names
@@ -241,6 +241,13 @@ module PactBroker
241
241
  end
242
242
  # rubocop: enable Metrics/CyclomaticComplexity
243
243
 
244
+ def pacticipants_set
245
+ from_self(alias: :v)
246
+ .select_group(Sequel[:v][:pacticipant_id])
247
+ .collect(&:pacticipant_id)
248
+ .to_set
249
+ end
250
+
244
251
  # private
245
252
 
246
253
  def calculate_max_version_order_and_join_back_to_versions(query, selector)
@@ -50,7 +50,7 @@ module PactBroker
50
50
  def execute pact, verification, event_context, options
51
51
  logger.info "Executing #{self} event_context=#{event_context}"
52
52
  template_params = template_parameters(pact, verification, event_context, options)
53
- webhook_request = request.build(template_params, options.fetch(:user_agent))
53
+ webhook_request = request.build(template_params, options.slice(:user_agent, :disable_ssl_verification, :cert_store))
54
54
  http_response, error = execute_request(webhook_request)
55
55
  success = success?(http_response, options)
56
56
  http_request = webhook_request.http_request
@@ -18,7 +18,7 @@ module PactBroker
18
18
 
19
19
  HEADERS_TO_REDACT = [/authorization/i, /token/i]
20
20
 
21
- attr_accessor :method, :url, :headers, :body, :username, :password, :uuid, :user_agent
21
+ attr_accessor :method, :url, :headers, :body, :username, :password, :uuid, :user_agent, :disable_ssl_verification, :cert_store
22
22
 
23
23
  # Reform gets confused by the :method method, as :method is a standard
24
24
  # Ruby method.
@@ -47,7 +47,7 @@ module PactBroker
47
47
  end
48
48
 
49
49
  def execute
50
- options = PactBroker::BuildHttpOptions.call(uri).merge(read_timeout: 15, open_timeout: 15)
50
+ options = PactBroker::BuildHttpOptions.call(uri, disable_ssl_verification: disable_ssl_verification, cert_store: cert_store).merge(read_timeout: 15, open_timeout: 15)
51
51
  req = http_request
52
52
  Net::HTTP.start(uri.hostname, uri.port, :ENV, options) do |http|
53
53
  http.request req
@@ -124,6 +124,9 @@ en:
124
124
  datetime:
125
125
  distance_in_words:
126
126
  half_a_minute: "half a minute"
127
+ less_than_x_minutes:
128
+ one: "less than 1 minute"
129
+ other: "less than %{count} minutes"
127
130
  less_than_x_seconds:
128
131
  one: "less than 1 second"
129
132
  other: "less than %{count} seconds"
@@ -124,15 +124,17 @@ module PactBroker
124
124
  end
125
125
 
126
126
  def eager_all_the_things
127
- eager(:consumer)
128
- .eager(:provider)
129
- .eager(consumer_version: [{ current_deployed_versions: :environment }, { current_supported_released_versions: :environment }, { branch_versions: :branch_head }])
130
- .eager(provider_version: [{ current_deployed_versions: :environment }, { current_supported_released_versions: :environment }, { branch_versions: :branch_head }])
131
- .eager(:verification)
132
- .eager(:pact_publication)
133
- .eager(:pact_version)
134
- .eager(:consumer_version_tags)
135
- .eager(:provider_version_tags)
127
+ eager(
128
+ :consumer,
129
+ :provider,
130
+ :verification,
131
+ :pact_publication,
132
+ :pact_version,
133
+ consumer_version: { current_deployed_versions: :environment, current_supported_released_versions: :environment, branch_versions: [:branch_head, :version, branch: :pacticipant] },
134
+ provider_version: { current_deployed_versions: :environment, current_supported_released_versions: :environment, branch_versions: [:branch_head, :version, branch: :pacticipant] },
135
+ consumer_version_tags: { version: :pacticipant },
136
+ provider_version_tags: { version: :pacticipant }
137
+ )
136
138
  end
137
139
 
138
140
  def default_scope
@@ -127,20 +127,19 @@ module PactBroker
127
127
  def integrations_where_specified_selector_is_provider(resolved_specified_selectors, options)
128
128
  integrations_involving_specified_providers = PactBroker::Integrations::Integration
129
129
  .where(provider_id: resolved_specified_selectors.collect(&:pacticipant_id))
130
- .eager(:consumer)
130
+ .eager(:consumer, :provider)
131
131
  .all
132
132
 
133
133
  destination_selector = PactBroker::Matrix::UnresolvedSelector.new(options.slice(:latest, :tag, :branch, :environment_name).compact)
134
+ required = PactBroker::Domain::Version.for_selector(destination_selector).pacticipants_set
134
135
 
135
136
  integrations_involving_specified_providers.collect do | integration |
136
- required = PactBroker::Domain::Version.where(pacticipant: integration.consumer).for_selector(destination_selector).any?
137
-
138
137
  Integration.from_hash(
139
138
  consumer_id: integration.consumer.id,
140
139
  consumer_name: integration.consumer.name,
141
140
  provider_id: integration.provider.id,
142
141
  provider_name: integration.provider.name,
143
- required: required
142
+ required: required.member?(integration.consumer.id)
144
143
  )
145
144
  end
146
145
  end
@@ -221,8 +220,10 @@ module PactBroker
221
220
 
222
221
  # Find the version number for selectors with the latest and/or tag specified
223
222
  def resolve_versions_and_add_ids(unresolved_selectors, selector_type, resolved_ignore_selectors = [])
223
+ names = unresolved_selectors.collect(&:pacticipant_name)
224
+ pacticipants = PactBroker::Domain::Pacticipant.where(name: names).to_a.group_by(&:name).transform_values(&:first)
224
225
  unresolved_selectors.collect do | unresolved_selector |
225
- pacticipant = PactBroker::Domain::Pacticipant.find(name: unresolved_selector.pacticipant_name)
226
+ pacticipant = pacticipants[unresolved_selector.pacticipant_name]
226
227
  if pacticipant
227
228
  versions = find_versions_for_selector(unresolved_selector)
228
229
  build_resolved_selectors(pacticipant, versions, unresolved_selector, selector_type, resolved_ignore_selectors)
@@ -9,6 +9,7 @@ module PactBroker
9
9
  merge!(params)
10
10
  end
11
11
 
12
+ # TODO rename branch to branch_name
12
13
  def self.from_hash(hash)
13
14
  new(hash.symbolize_keys.snakecase_keys.slice(:pacticipant_name, :pacticipant_version_number, :latest, :tag, :branch, :environment_name))
14
15
  end
@@ -18,7 +18,7 @@ module PactBroker
18
18
  withMainBranchSetCount: PactBroker::Domain::Pacticipant.with_main_branch_set.count
19
19
  },
20
20
  integrations: {
21
- count: PactBroker::Integrations::Integration.count
21
+ count: PactBroker::Pacts::PactPublication.select(:consumer_id, :provider_id).distinct.count
22
22
  },
23
23
  pactPublications: {
24
24
  count: PactBroker::Pacts::PactPublication.count,
@@ -19,6 +19,13 @@ module PactBroker
19
19
  include PactBroker::Repositories::Helpers
20
20
  include PactBroker::Repositories::Scopes
21
21
 
22
+ PUBLICATION_ASSOCIATIONS_FOR_EAGER_LOAD = [
23
+ :provider,
24
+ :consumer,
25
+ :consumer_version,
26
+ pact_version: :latest_verification
27
+ ]
28
+
22
29
  def find(provider_name, consumer_version_selectors)
23
30
  selected_pacts = find_pacts_by_selector(provider_name, consumer_version_selectors)
24
31
  selected_pacts = selected_pacts + find_pacts_for_fallback_tags(selected_pacts, provider_name, consumer_version_selectors)
@@ -104,7 +111,7 @@ module PactBroker
104
111
 
105
112
  specified_selectors_or_defaults(consumer_version_selectors, provider).flat_map do | selector |
106
113
  query = scope_for(PactPublication).for_provider_and_consumer_version_selector(provider, selector)
107
- query.all.collect do | pact_publication |
114
+ query.eager(*PUBLICATION_ASSOCIATIONS_FOR_EAGER_LOAD).all.collect do | pact_publication |
108
115
  create_selected_pact(pact_publication, selector)
109
116
  end
110
117
  end
@@ -265,7 +272,12 @@ module PactBroker
265
272
  log_pact_publications("Ignoring pacts successfully verified by another provider branch when not WIP", verified_by_other_branch)
266
273
  end
267
274
 
268
- PactPublication.subtract(pact_publications_query.all, specified_explicitly.all, verified_by_this_branch.all, verified_by_other_branch.all)
275
+ PactPublication.subtract(
276
+ pact_publications_query.eager(*PUBLICATION_ASSOCIATIONS_FOR_EAGER_LOAD).all,
277
+ specified_explicitly.all,
278
+ verified_by_this_branch.all,
279
+ verified_by_other_branch.all
280
+ )
269
281
  end
270
282
 
271
283
  def remove_non_wip_for_tag(pact_publications_query, provider, tag, specified_pact_version_shas)
@@ -279,7 +291,11 @@ module PactBroker
279
291
  log_pact_publications("Ignoring pacts successfully verified by another provider tag when not WIP", verified_by_another_tag)
280
292
  end
281
293
 
282
- PactPublication.subtract(pact_publications_query.all, specified_explicitly.all, verified_by_this_tag.all, verified_by_another_tag.all)
294
+ PactPublication.subtract(
295
+ pact_publications_query.eager(*PUBLICATION_ASSOCIATIONS_FOR_EAGER_LOAD).all,
296
+ specified_explicitly.all,
297
+ verified_by_this_tag.all,
298
+ verified_by_another_tag.all)
283
299
  end
284
300
 
285
301
  def collect_consumer_name_and_version_number(pact_publications_query)
@@ -283,8 +283,6 @@ module PactBroker
283
283
 
284
284
  # rubocop: disable Metrics/CyclomaticComplexity
285
285
  def <=> other
286
- # elsif consumer || other.consumer
287
- # consumer_comparison(other)
288
286
  if overall_latest? || other.overall_latest?
289
287
  overall_latest_comparison(other)
290
288
  elsif latest_for_branch? || other.latest_for_branch?
@@ -297,6 +295,8 @@ module PactBroker
297
295
  currently_deployed_comparison(other)
298
296
  elsif currently_supported? || other.currently_supported?
299
297
  currently_supported_comparison(other)
298
+ elsif consumer || other.consumer
299
+ consumer_comparison(other)
300
300
  else
301
301
  0
302
302
  end
@@ -358,8 +358,8 @@ module PactBroker
358
358
  end
359
359
 
360
360
  def consumer_comparison(other)
361
- if consumer == other.consumer
362
- 0
361
+ if consumer && other.consumer
362
+ consumer <=> other.consumer
363
363
  else
364
364
  consumer ? -1 : 1
365
365
  end
@@ -43,7 +43,7 @@ module PactBroker
43
43
  end
44
44
 
45
45
  def delete params
46
- logger.info "Deleting pact version with params #{params}"
46
+ logger.info "Deleting pact version", payload: params
47
47
  pacts = pact_repository.find_all_revisions(params[:consumer_name], params[:consumer_version_number], params[:provider_name])
48
48
  webhook_service.delete_all_webhook_related_objects_by_pact_publication_ids(pacts.collect(&:id))
49
49
  pact_repository.delete(params)
@@ -156,7 +156,7 @@ module PactBroker
156
156
 
157
157
  # Overwriting an existing pact with the same consumer/provider/consumer version number
158
158
  def create_pact_revision params, existing_pact
159
- logger.info "Updating existing pact publication", payload: params.reject{ |k, _v| k == :json_content }
159
+ logger.info "Updating existing pact publication", payload: params.without(:json_content)
160
160
  logger.debug "Content #{params[:json_content]}"
161
161
  pact_version_sha = generate_sha(params[:json_content])
162
162
  json_content = add_interaction_ids(params[:json_content])
@@ -185,7 +185,7 @@ module PactBroker
185
185
 
186
186
  # When no publication for the given consumer/provider/consumer version number exists
187
187
  def create_pact params, version, provider
188
- logger.info "Creating new pact publication with params #{params.reject{ |k, _v| k == :json_content}}"
188
+ logger.info "Creating new pact publication", payload: params.without(:json_content)
189
189
  logger.debug "Content #{params[:json_content]}"
190
190
  pact_version_sha = generate_sha(params[:json_content])
191
191
  json_content = add_interaction_ids(params[:json_content])
@@ -34,7 +34,7 @@ module PactBroker
34
34
  # You never can tell what people will do...
35
35
  if probably_array.is_a?(Array)
36
36
  array_with_ordered_hashes = order_hash_keys(probably_array)
37
- array_with_ordered_hashes.sort{ |a, b| a.to_json <=> b.to_json }
37
+ array_with_ordered_hashes.sort_by(&:to_json)
38
38
  else
39
39
  probably_array
40
40
  end
@@ -36,7 +36,7 @@ module PactBroker
36
36
  end
37
37
 
38
38
  def postgres?
39
- Sequel::Model.db.adapter_scheme.to_s == "postgres"
39
+ Sequel::Model.db.adapter_scheme.to_s =~ /postgres/
40
40
  end
41
41
 
42
42
  def select_all_qualified
@@ -55,6 +55,15 @@ module PactBroker
55
55
 
56
56
  str
57
57
  end
58
+
59
+ # Adopt from https://stackoverflow.com/questions/1451384/how-can-i-center-truncate-a-string
60
+ def ellipsisize(minimum_length: 20, edge_length: 10)
61
+ return self if self.length < minimum_length || self.length <= edge_length * 2
62
+
63
+ edge = "." * edge_length
64
+ mid_length = self.length - edge_length * 2
65
+ gsub(/(#{edge}).{#{mid_length},}(#{edge})/, '\1...\2')
66
+ end
58
67
  end
59
68
  end
60
69
  end