pact_broker 2.94.0 → 2.95.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15cc9869c313dbadd50a4bcc89d3912717cc5f8512af30326b716d2a3cc636ad
4
- data.tar.gz: 5d8c0f7240e7b312e096afb75ab8d2f9b91a9f26284be9e90e680bc59615cb02
3
+ metadata.gz: e077e361037618a0d58670de46b25753d8755cb1e21ef58e9f73a8fe5705cd7f
4
+ data.tar.gz: 0e64d6fee6eb4cf36f69dea5bf94c432c088c93984ca51783e68f20b7b2e3130
5
5
  SHA512:
6
- metadata.gz: 1d223aa03faeac6cda65c71fab594b2bebed430690758ba768b34002e50434acfd556629593909aad8e494e59c26a067abf0243dae0345b482f9f111065e46ff
7
- data.tar.gz: db169a6db83b20c37e28bacf7e83975f89fa204e41ed8c75a58708a658b6ae3177f7235a32a54db2138d0a5f9f471a92f3e6934f00d222fa6b8310ba987e55e0
6
+ metadata.gz: 8c7bbae3ff3736576977f15aaef79a3d6635667de76b994a83c8c4613ce7fa9999808af70838014f7b5d7c26e7ffbda5da5e5813b1394dd6c4557fe597c9a11f
7
+ data.tar.gz: 4783820b31a355a9c2bf9a36151cc0730dba2a1424a1c68b8da39ac1f658cec3334b18c406b58d1b211cb0a5f3cc72b14a619066ca9d0c2daca828720f144d08
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ <a name="v2.95.0"></a>
2
+ ### v2.95.0 (2022-03-16)
3
+
4
+ #### Features
5
+
6
+ * add relation for can-i-deploy branch to environment badge ([6ece8e93](/../../commit/6ece8e93))
7
+ * add badge url for 'can I deploy latest version of branch to envionment' endpoint ([086b8c10](/../../commit/086b8c10))
8
+
9
+ #### Bug Fixes
10
+
11
+ * **pacts for verification**
12
+ * do not de-duplicate pacts with the same content but different consumers ([ae3bb541](/../../commit/ae3bb541))
13
+
1
14
  <a name="v2.94.0"></a>
2
15
  ### v2.94.0 (2022-02-22)
3
16
 
data/README.md CHANGED
@@ -140,15 +140,14 @@ You can use the [Pact Broker Docker image][docker] or [Terraform on AWS][terrafo
140
140
  #### Rolling your own
141
141
 
142
142
  * Are you sure you don't just want to use the [Pact Broker Docker image][docker]? No Docker at your company yet? Ah well, keep reading.
143
- * Create a PostgreSQL (recommended) or MySQL (not _as_ recommended because of @bethesque's personal prejudices, but still fully supported) database.
144
- * To ensure you're on a supported version of the database that you choose, check the [travis.yml][travisyml] file to see which versions we're currently running our tests against.
145
- * If you're using PostgreSQL (did we mention this was _recommended!_) you'll find the database creation script in the [example/config.ru](https://github.com/pact-foundation/pact_broker/blob/master/example/config.ru).
146
- * Install ruby 2.4 or later and the latest version of bundler (if you've come this far, I'm assuming you know how to do both of these. Did I mention there was a [Docker][docker] image?)
143
+ * Create a PostgreSQL database.
144
+ * To ensure you're on a supported version of the database that you choose, check the [travis.yml][travisyml] file to see which versions we're currently running our tests against.
145
+ * MySQL was supported for the native Ruby application until around 2021, but the official `pactfoundation/pact-broker` Docker image does not support it. New features will not be optimised for MySQL, and some new features may not even be supported on it (eg. the database clean feature).
146
+ * You'll find a sample database creation script in the [example/config.ru](https://github.com/pact-foundation/pact_broker/blob/master/example/config.ru).
147
+ * Install ruby 2.7 or later and the latest version of bundler (if you've come this far, I'm assuming you know how to do both of these. Did I mention there was a [Docker][docker] image?)
147
148
  * Copy the [pact\_broker](https://github.com/DiUS/pact_broker-docker/tree/master/pact_broker) directory from the Pact Broker Docker project. This will have the recommended settings for database connections, logging, basic auth etc. Note that the Docker image uses Phusion Passenger as the web application server in front of the Pact Broker Ruby application, which is the recommended set up.
148
- * Modify the config.ru and Gemfile as desired (eg. choose database driver gem, set your database credentials. Use the "pg" gem if using Postgres and the "mysql2" gem if using MySQL)
149
- * example Sequel configuration for postgres `{adapter: "postgres", database: "pact_broker", username: 'pact_broker', password: 'pact_broker', :encoding => 'utf8'}`
150
- * example Sequel configuration for mysql `{adapter: "mysql2", database: "pact_broker", username: 'pact_broker', password: 'pact_broker', :encoding => 'utf8'}`
151
- `
149
+ * Modify the config.ru and Gemfile as desired (eg. choose database driver gem, set your database credentials. Use the "pg" gem for Postgres)
150
+ * example Sequel configuration for postgres `{ adapter: "postgres", database: "pact_broker", username: 'pact_broker', password: 'pact_broker', :encoding => 'utf8' }`
152
151
  * Please ensure you use `encoding: 'utf8'` in your Sequel options to avoid encoding issues.
153
152
  * For production usage, use a web application server like [Phusion Passenger](https://www.phusionpassenger.com) or [Nginx](http://nginx.org/) to serve the Pact Broker application. You'll need to read up on the documentation for these yourself as it is beyond the scope of this documentation. See the [wiki][reverse-proxy-docs] for instructions on using a reverse proxy with SSL.
154
153
  * Ensure the environment variable `RACK_ENV` is set to `production`.
@@ -0,0 +1,14 @@
1
+ require_relative "migration_helper"
2
+ include PactBroker::MigrationHelper
3
+
4
+ Sequel.migration do
5
+ up do
6
+ if mysql?
7
+ run("ALTER TABLE verifications CHANGE consumer_version_selector_hashes consumer_version_selector_hashes mediumtext")
8
+ end
9
+ end
10
+
11
+ down do
12
+
13
+ end
14
+ end
@@ -38,11 +38,7 @@ module PactBroker
38
38
  ]
39
39
 
40
40
  if enable_public_badge_access
41
- rules.concat([
42
- [PUBLIC, READ_METHODS, PACT_BADGE_PATH],
43
- [PUBLIC, READ_METHODS, MATRIX_BADGE_PATH],
44
- [PUBLIC, READ_METHODS, CAN_I_DEPLOY_BADGE_PATH]
45
- ])
41
+ rules.concat(BADGE_PATHS.collect { | badge_path | [PUBLIC, READ_METHODS, badge_path] })
46
42
  end
47
43
 
48
44
  if allow_public_access_to_heartbeat
@@ -8,7 +8,7 @@ module PactBroker
8
8
 
9
9
  def self.call(date_time)
10
10
  if date_time.is_a?(String)
11
- DATE_TIME_CLASS.strptime(date_time).to_time.utc.to_datetime.xmlschema
11
+ Sequel.string_to_datetime(date_time).to_time.utc.to_datetime.xmlschema
12
12
  elsif date_time
13
13
  date_time.to_time.utc.to_datetime.xmlschema if date_time
14
14
  end
@@ -90,6 +90,14 @@ module PactBroker
90
90
  }
91
91
  end
92
92
 
93
+ link :'pb:can-i-deploy-branch-to-environment-badge' do | options |
94
+ {
95
+ title: "Can I Deploy #{represented.name} from branch to environment badge",
96
+ href: templated_can_i_deploy_branch_to_environment_badge_url(represented.name, options[:base_url]),
97
+ templated: true
98
+ }
99
+ end
100
+
93
101
  curies do | options |
94
102
  [{
95
103
  name: :pb,
@@ -255,6 +255,10 @@ module PactBroker
255
255
  templated_can_i_deploy_url(pacticipant_name, base_url) + "/badge"
256
256
  end
257
257
 
258
+ def templated_can_i_deploy_branch_to_environment_badge_url pacticipant_name, base_url = ""
259
+ pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/branches/{branch}/latest-version/can-i-deploy/to-environment/{environment}/badge"
260
+ end
261
+
258
262
  def label_url label, base_url
259
263
  "#{labels_url(label.pacticipant, base_url)}/#{url_encode(label.name)}"
260
264
  end
@@ -3,9 +3,12 @@ module PactBroker
3
3
  module Paths
4
4
  PACT_BADGE_PATH = %r{^/pacts/provider/[^/]+/consumer/.*/badge(?:\.[A-Za-z]+)?$}.freeze
5
5
  MATRIX_BADGE_PATH = %r{^/matrix/provider/[^/]+/latest/[^/]+/consumer/[^/]+/latest/[^/]+/badge(?:\.[A-Za-z]+)?$}.freeze
6
- CAN_I_DEPLOY_BADGE_PATH = %r{^/pacticipants/[^/]+/latest-version/[^/]+/can-i-deploy/to/[^/]+/badge(?:\.[A-Za-z]+)?$}.freeze
6
+ CAN_I_DEPLOY_TAG_BADGE_PATH = %r{^/pacticipants/[^/]+/latest-version/[^/]+/can-i-deploy/to/[^/]+/badge(?:\.[A-Za-z]+)?$}.freeze
7
+ CAN_I_DEPLOY_BRANCH_ENV_BADGE_PATH = %r{^/pacticipants/[^/]+/branches/[^/]+/latest-version/can-i-deploy/to-environment/[^/]+/badge(?:\.[A-Za-z]+)?$}.freeze
7
8
  VERIFICATION_RESULTS = %r{^/pacts/provider/[^/]+/consumer/[^/]+/pact-version/[^/]+/verification-results/[^/]+}
8
9
 
10
+ BADGE_PATHS = [PACT_BADGE_PATH, MATRIX_BADGE_PATH, CAN_I_DEPLOY_TAG_BADGE_PATH, CAN_I_DEPLOY_BRANCH_ENV_BADGE_PATH]
11
+
9
12
  extend self
10
13
 
11
14
  def is_verification_results_path?(path)
@@ -14,7 +17,7 @@ module PactBroker
14
17
 
15
18
  def is_badge_path?(path)
16
19
  # Optimise by checking include? first - regexp slow
17
- path.include?("/badge") && (path =~ PACT_BADGE_PATH || path =~ MATRIX_BADGE_PATH || path =~ CAN_I_DEPLOY_BADGE_PATH)
20
+ path.include?("/badge") && BADGE_PATHS.any?{ | regex | path =~ regex }
18
21
  end
19
22
  end
20
23
  end
@@ -1,37 +1,22 @@
1
1
  require "pact_broker/api/resources/base_resource"
2
2
  require "pact_broker/verifications/pseudo_branch_status"
3
3
  require "pact_broker/configuration"
4
+ require "pact_broker/api/resources/badge_methods"
4
5
 
5
6
  module PactBroker
6
7
  module Api
7
8
  module Resources
8
9
  class Badge < BaseResource
9
-
10
- def allowed_methods
11
- ["GET", "OPTIONS"]
12
- end
13
-
14
- def content_types_provided
15
- [["image/svg+xml", :to_svg]]
16
- end
10
+ include BadgeMethods
17
11
 
18
12
  def resource_exists?
19
13
  !badge_service.can_provide_badge_using_redirect?
20
14
  end
21
15
 
22
- # Only called if resource_exists? returns false
23
- def previously_existed?
24
- true
25
- end
26
-
27
16
  def is_authorized?(authorization_header)
28
17
  super || PactBroker.configuration.enable_public_badge_access
29
18
  end
30
19
 
31
- def forbidden?
32
- false
33
- end
34
-
35
20
  def to_svg
36
21
  response.headers["Cache-Control"] = "no-cache"
37
22
  comment + badge_service.pact_verification_badge(pact, label, initials, pseudo_branch_verification_status, tags)
@@ -42,10 +27,6 @@ module PactBroker
42
27
  badge_service.pact_verification_badge_url(pact, label, initials, pseudo_branch_verification_status, tags)
43
28
  end
44
29
 
45
- def policy_name
46
- :'badges::badge'
47
- end
48
-
49
30
  private
50
31
 
51
32
  def pact
@@ -61,10 +42,6 @@ module PactBroker
61
42
  @pseudo_branch_verification_status ||= PactBroker::Verifications::PseudoBranchStatus.new(pact, latest_verification).to_sym
62
43
  end
63
44
 
64
- def label
65
- request.query["label"]
66
- end
67
-
68
45
  def initials
69
46
  request.query["initials"] == "true"
70
47
  end
@@ -0,0 +1,57 @@
1
+ module PactBroker
2
+ module Api
3
+ module Resources
4
+ module BadgeMethods
5
+ def allowed_methods
6
+ ["GET", "OPTIONS"]
7
+ end
8
+
9
+ def content_types_provided
10
+ [["image/svg+xml", :to_svg]]
11
+ end
12
+
13
+ def resource_exists?
14
+ false
15
+ end
16
+
17
+ # Only called if resource_exists? returns false
18
+ def previously_existed?
19
+ true
20
+ end
21
+
22
+ def forbidden?
23
+ false
24
+ end
25
+
26
+ def is_authorized?(authorization_header)
27
+ super || PactBroker.configuration.enable_public_badge_access
28
+ end
29
+
30
+ def policy_name
31
+ :'badges::badge'
32
+ end
33
+
34
+ def moved_temporarily?
35
+ response.headers["Cache-Control"] = "no-cache"
36
+ begin
37
+ badge_url
38
+ rescue StandardError => e
39
+ # Want to render a badge, even if there's an error
40
+ badge_service.error_badge_url("error", ErrorResponseBodyGenerator.display_message(e, "reference: #{PactBroker::Errors.generate_error_reference}"))
41
+ end
42
+ end
43
+
44
+ def badge_url
45
+ raise NotImplementedError
46
+ end
47
+
48
+ private
49
+
50
+ def label
51
+ lab = request.query["label"]
52
+ lab && !lab.empty? ? lab : nil
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,21 +1,30 @@
1
1
  require "pact_broker/api/resources/matrix"
2
2
  require "pact_broker/matrix/can_i_deploy_query_schema"
3
3
  require "pact_broker/matrix/parse_can_i_deploy_query"
4
+ require "pact_broker/api/decorators/matrix_decorator"
5
+ require "pact_broker/api/decorators/matrix_text_decorator"
4
6
 
5
7
  module PactBroker
6
8
  module Api
7
9
  module Resources
8
- class CanIDeployPacticipantVersionByBranchToEnvironment < Matrix
9
- def resource_exists?
10
- !!(version && environment)
10
+ class CanIDeployPacticipantVersionByBranchToEnvironment < BaseResource
11
+ def allowed_methods
12
+ ["GET", "OPTIONS"]
11
13
  end
12
14
 
13
- def malformed_request?
14
- false
15
+ def content_types_provided
16
+ [
17
+ ["application/hal+json", :to_json],
18
+ ["text/plain", :to_text]
19
+ ]
20
+ end
21
+
22
+ def resource_exists?
23
+ !!(version && environment)
15
24
  end
16
25
 
17
26
  def policy_name
18
- :'matrix::can_i_deploy'
27
+ :'versions::version'
19
28
  end
20
29
 
21
30
  private
@@ -37,6 +46,14 @@ module PactBroker
37
46
  }
38
47
  end
39
48
 
49
+ def to_json
50
+ decorator_class(:matrix_decorator).new(results).to_json(decorator_options)
51
+ end
52
+
53
+ def results
54
+ @results ||= matrix_service.can_i_deploy(selectors, options)
55
+ end
56
+
40
57
  def version
41
58
  @version ||= version_service.find_latest_by_pacticipant_name_and_branch_name(identifier_from_path[:pacticipant_name], identifier_from_path[:branch_name])
42
59
  end
@@ -0,0 +1,29 @@
1
+ require "pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment"
2
+
3
+ module PactBroker
4
+ module Api
5
+ module Resources
6
+ class CanIDeployPacticipantVersionByBranchToEnvironmentBadge < CanIDeployPacticipantVersionByBranchToEnvironment
7
+ include BadgeMethods
8
+
9
+ private
10
+
11
+ def badge_url
12
+ if pacticipant && version && environment
13
+ badge_service.can_i_deploy_badge_url(identifier_from_path[:branch_name], identifier_from_path[:environment_name], label, results.deployable?)
14
+ elsif pacticipant.nil?
15
+ badge_service.error_badge_url("pacticipant", "not found")
16
+ elsif version.nil?
17
+ if branch_service.find_branch(identifier_from_path.slice(:pacticipant_name, :branch_name)).nil?
18
+ badge_service.error_badge_url("branch", "not found")
19
+ else
20
+ badge_service.error_badge_url("version", "not found")
21
+ end
22
+ else
23
+ badge_service.error_badge_url("environment", "not found")
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -11,7 +11,7 @@ module PactBroker
11
11
  end
12
12
 
13
13
  def policy_name
14
- :'matrix::can_i_deploy'
14
+ :'versions::version'
15
15
  end
16
16
 
17
17
  def malformed_request?
@@ -0,0 +1,25 @@
1
+ require "pact_broker/matrix/can_i_deploy_query_schema"
2
+ require "pact_broker/matrix/parse_can_i_deploy_query"
3
+ require "pact_broker/api/resources/badge_methods"
4
+
5
+ module PactBroker
6
+ module Api
7
+ module Resources
8
+ class CanIDeployPacticipantVersionByTagToTagBadge < CanIDeployPacticipantVersionByTagToTag
9
+ include BadgeMethods
10
+
11
+ def badge_url
12
+ if pacticipant
13
+ if version
14
+ badge_service.can_i_deploy_badge_url(identifier_from_path[:tag], identifier_from_path[:to], label, results.deployable?)
15
+ else
16
+ badge_service.error_badge_url("version", "not found")
17
+ end
18
+ else
19
+ badge_service.error_badge_url("pacticipant", "not found")
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -88,12 +88,12 @@ module PactBroker
88
88
  add ["pacticipants", :pacticipant_name, "versions", :pacticipant_version_number], Api::Resources::Version, {resource_name: "pacticipant_version"}
89
89
  add ["pacticipants", :pacticipant_name, "latest-version", :tag], Api::Resources::LatestVersion, {resource_name: "latest_tagged_pacticipant_version"}
90
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" }
91
+ add ["pacticipants", :pacticipant_name, "latest-version", :tag, "can-i-deploy", "to", :to, "badge"], Api::Resources::CanIDeployPacticipantVersionByTagToTagBadge, { resource_name: "can_i_deploy_latest_tagged_version_to_tag_badge" }
92
92
  add ["pacticipants", :pacticipant_name, "latest-version"], Api::Resources::LatestVersion, {resource_name: "latest_pacticipant_version"}
93
93
  add ["pacticipants", :pacticipant_name, "versions", :pacticipant_version_number, "tags", :tag_name], Api::Resources::Tag, {resource_name: "pacticipant_version_tag"}
94
94
  add ["pacticipants", :pacticipant_name, "branches", :branch_name, "versions", :version_number], Api::Resources::BranchVersion, { resource_name: "branch_version" }
95
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" }
96
+ add ["pacticipants", :pacticipant_name, "branches", :branch_name, "latest-version", "can-i-deploy", "to-environment", :environment_name, "badge"], Api::Resources::CanIDeployPacticipantVersionByBranchToEnvironmentBadge, { resource_name: "can_i_deploy_latest_branch_version_to_environment_badge" }
97
97
 
98
98
  # Webhooks
99
99
  add ["webhooks", "provider", :provider_name, "consumer", :consumer_name ], Api::Resources::PacticipantWebhooks, {resource_name: "pacticipant_webhooks"}
@@ -1,11 +1,8 @@
1
1
  require "pact_broker/domain/group"
2
2
 
3
3
  module PactBroker
4
-
5
4
  module Pacticipants
6
-
7
5
  class FindPotentialDuplicatePacticipantNames
8
-
9
6
  attr_reader :new_name, :existing_names
10
7
 
11
8
  def initialize new_name, existing_names
@@ -40,4 +37,4 @@ module PactBroker
40
37
  end
41
38
  end
42
39
  end
43
- end
40
+ end
@@ -29,7 +29,7 @@ module PactBroker
29
29
 
30
30
  def self.deduplicate(verifiable_pacts)
31
31
  verifiable_pacts
32
- .group_by { | verifiable_pact | verifiable_pact.pact_version_sha }
32
+ .group_by { | verifiable_pact | [verifiable_pact.consumer_name, verifiable_pact.pact_version_sha] }
33
33
  .values
34
34
  .collect { | verifiable_pact | verifiable_pact.reduce(&:+) }
35
35
  end
@@ -51,6 +51,10 @@ module PactBroker
51
51
  raise PactBroker::Error.new("Can't merge two verifiable pacts with different provider_branch")
52
52
  end
53
53
 
54
+ if consumer_name != other.consumer_name
55
+ raise PactBroker::Error.new("Can't merge two verifiable pacts with different consumer names")
56
+ end
57
+
54
58
  latest_pact = [self, other].sort_by(&:consumer_version_order).last.__getobj__()
55
59
 
56
60
  VerifiablePact.new(
@@ -16,7 +16,7 @@ module PactBroker
16
16
  include PactBroker::UI::Helpers::MatrixHelper
17
17
 
18
18
  get "/:pacticipant_name/latest-version/:tag/can-i-deploy/to/:environment_tag" do
19
- # selector and options must be in sync with lib/pact_broker/api/resources/can_i_deploy_badge.rb
19
+ # selector and options must be in sync with lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_tag_to_tag_badge.rb
20
20
  selectors = [ PactBroker::Matrix::UnresolvedSelector.new(pacticipant_name: params[:pacticipant_name], latest: true, tag: params[:tag]) ]
21
21
  options = { latestby: "cvp", limit: 100, tag: params[:to] }
22
22
  result = matrix_service.find(selectors, options)
@@ -1,3 +1,3 @@
1
1
  module PactBroker
2
- VERSION = "2.94.0"
2
+ VERSION = "2.95.0"
3
3
  end
@@ -8,6 +8,10 @@ module PactBroker
8
8
  plugin :insert_ignore, identifying_columns: [:name, :pacticipant_id]
9
9
 
10
10
  associate(:many_to_one, :pacticipant, :class => "PactBroker::Domain::Pacticipant", :key => :pacticipant_id, :primary_key => :id)
11
+
12
+ dataset_module do
13
+ include PactBroker::Repositories::Helpers
14
+ end
11
15
  end
12
16
  end
13
17
  end
@@ -19,6 +19,16 @@ module PactBroker
19
19
  version = version_repository.find_by_pacticipant_id_and_number_or_create(pacticipant.id, version_number)
20
20
  branch_version_repository.add_branch(version, branch_name)
21
21
  end
22
+
23
+ def self.find_branch(pacticipant_name:, branch_name:)
24
+ Branch
25
+ .select_all_qualified
26
+ .join(:pacticipants, { Sequel[:branches][:pacticipant_id] => Sequel[:pacticipants][:id] }) do
27
+ PactBroker::Repositories::Helpers.name_like(Sequel[:pacticipants][:name], pacticipant_name)
28
+ end
29
+ .where(Sequel[:branches][:name] => branch_name)
30
+ .single_record
31
+ end
22
32
  end
23
33
  end
24
34
  end
@@ -3,6 +3,28 @@ require "webmachine/adapters/rack_mapped"
3
3
  module Webmachine
4
4
  class DescribeRoutes
5
5
 
6
+ Route = Struct.new(
7
+ :path,
8
+ :resource_class,
9
+ :resource_name,
10
+ :resource_class_location,
11
+ :allowed_methods,
12
+ :policy_class,
13
+ keyword_init: true) do
14
+
15
+ def [](key)
16
+ if respond_to?(key)
17
+ send(key)
18
+ else
19
+ nil
20
+ end
21
+ end
22
+
23
+ def path_include?(component)
24
+ path.include?(component)
25
+ end
26
+ end
27
+
6
28
  def self.call(webmachine_applications, search_term: nil)
7
29
  path_mappings = webmachine_applications.flat_map { | webmachine_application | paths_to_resource_class_mappings(webmachine_application) }
8
30
 
@@ -16,12 +38,12 @@ module Webmachine
16
38
  def self.paths_to_resource_class_mappings(webmachine_application)
17
39
  webmachine_application.routes.collect do | route |
18
40
  resource_path_absolute = Pathname.new(source_location_for(route.resource))
19
- {
41
+ Route.new({
20
42
  path: "/" + route.path_spec.collect{ |part| part.is_a?(Symbol) ? ":#{part}" : part }.join("/"),
21
43
  resource_class: route.resource,
22
44
  resource_name: route.instance_variable_get(:@bindings)[:resource_name],
23
45
  resource_class_location: resource_path_absolute.relative_path_from(Pathname.pwd).to_s
24
- }.merge(info_from_resource_instance(route))
46
+ }.merge(info_from_resource_instance(route)))
25
47
  end
26
48
  end
27
49
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.94.0
4
+ version: 2.95.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bethany Skurrie
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-02-21 00:00:00.000000000 Z
13
+ date: 2022-03-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -589,6 +589,7 @@ files:
589
589
  - db/migrations/20211104_switch_integrations_and_temp_integrations.rb
590
590
  - db/migrations/20211120_create_pact_version_provider_tag_successful_verifications.rb
591
591
  - db/migrations/20211121_migrate_pact_version_provider_tag_successful_verifications_data.rb
592
+ - db/migrations/20220303_increase_consumer_version_selector_hashes_column_size.rb
592
593
  - db/migrations/migration_helper.rb
593
594
  - docs/CONFIGURATION.md
594
595
  - docs/api/WEBHOOKS.md
@@ -697,12 +698,14 @@ files:
697
698
  - lib/pact_broker/api/resources/authentication.rb
698
699
  - lib/pact_broker/api/resources/authorization.rb
699
700
  - lib/pact_broker/api/resources/badge.rb
701
+ - lib/pact_broker/api/resources/badge_methods.rb
700
702
  - lib/pact_broker/api/resources/base_resource.rb
701
703
  - lib/pact_broker/api/resources/branch_version.rb
702
704
  - lib/pact_broker/api/resources/can_i_deploy.rb
703
- - lib/pact_broker/api/resources/can_i_deploy_badge.rb
704
705
  - lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment.rb
706
+ - lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment_badge.rb
705
707
  - lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_tag_to_tag.rb
708
+ - lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_tag_to_tag_badge.rb
706
709
  - lib/pact_broker/api/resources/clean.rb
707
710
  - lib/pact_broker/api/resources/currently_deployed_versions_for_environment.rb
708
711
  - lib/pact_broker/api/resources/currently_supported_versions_for_environment.rb
@@ -1226,7 +1229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1226
1229
  - !ruby/object:Gem::Version
1227
1230
  version: '0'
1228
1231
  requirements: []
1229
- rubygems_version: 3.3.7
1232
+ rubygems_version: 3.3.9
1230
1233
  signing_key:
1231
1234
  specification_version: 4
1232
1235
  summary: See description
@@ -1,85 +0,0 @@
1
- require "pact_broker/matrix/can_i_deploy_query_schema"
2
- require "pact_broker/matrix/parse_can_i_deploy_query"
3
-
4
- module PactBroker
5
- module Api
6
- module Resources
7
- class CanIDeployBadge < BaseResource
8
- def initialize
9
- super
10
- selector = PactBroker::Matrix::UnresolvedSelector.new(pacticipant_name: pacticipant_name, latest: true, tag: identifier_from_path[:tag])
11
- @options = {
12
- latestby: "cvp",
13
- latest: true,
14
- tag: identifier_from_path[:to]
15
- }
16
- @selectors = [selector]
17
- end
18
-
19
- def allowed_methods
20
- ["GET", "OPTIONS"]
21
- end
22
-
23
- def content_types_provided
24
- [["image/svg+xml", :to_svg]]
25
- end
26
-
27
- def resource_exists?
28
- false
29
- end
30
-
31
- # Only called if resource_exists? returns false
32
- def previously_existed?
33
- true
34
- end
35
-
36
- def is_authorized?(authorization_header)
37
- super || PactBroker.configuration.enable_public_badge_access
38
- end
39
-
40
- def forbidden?
41
- false
42
- end
43
-
44
- def moved_temporarily?
45
- response.headers["Cache-Control"] = "no-cache"
46
- begin
47
- if pacticipant
48
- if version
49
- badge_service.can_i_deploy_badge_url(identifier_from_path[:tag], identifier_from_path[:to], label, results.deployable?)
50
- else
51
- badge_service.error_badge_url("version", "not found")
52
- end
53
- else
54
- badge_service.error_badge_url(selectors.first.pacticipant_name, "not found")
55
- end
56
- rescue StandardError => e
57
- # Want to render a badge, even if there's an error
58
- badge_service.error_badge_url("error", ErrorResponseBodyGenerator.display_message(e, "reference: #{PactBroker::Errors.generate_error_reference}"))
59
- end
60
- end
61
-
62
- def policy_name
63
- :'badges::badge'
64
- end
65
-
66
- private
67
-
68
- attr_reader :selectors, :options
69
-
70
- def results
71
- @results ||= matrix_service.can_i_deploy(selectors, options)
72
- end
73
-
74
- def version
75
- @version ||= version_service.find_by_pacticipant_name_and_latest_tag(identifier_from_path[:pacticipant_name], identifier_from_path[:tag])
76
- end
77
-
78
- def label
79
- lab = request.query["label"]
80
- lab && !lab.empty? ? lab : nil
81
- end
82
- end
83
- end
84
- end
85
- end