pact_broker 2.62.0 → 2.63.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: 0d90410ba82c9f6ee8681073d1a9435660abf73045fa4ea08658294512771106
4
- data.tar.gz: ff2c697fa385d574c26225ebf3aa6bb93276a749bfc6851685dc17728aa18fb0
3
+ metadata.gz: 61338a93bd65ffa3ec70f4fdfd9b509a0d5c0608dce8cea3f779e3ac22151412
4
+ data.tar.gz: 99819023ba051657020d314fe6d3005a04660d70467a57c5b5369a08a5525e2a
5
5
  SHA512:
6
- metadata.gz: 95c87ab86bd54c472362e678a8fd6307637ad34059beb390baf59fa33456014ed47bd725940fe792ffd7151c80201baf9c063d670b7ed4c857708c22e60e352a
7
- data.tar.gz: 3c101564948c497f80d286eccfd70cc92734c5a94b280825bd437c3a6ab4141caf7e98fefb6594b230d0021bba732c44704e9338df081c630d752f0bbb3140cc
6
+ metadata.gz: 7da446c51346413782377eb409c2d3159fcb322147d675324126243bfb8b115ff042d210b3cf25ee46ebe73093611e4de85db03f243c5ffb06299239d6aff637
7
+ data.tar.gz: 6b191f39b782bf811d58e15d149fa5e786227e6a86d93c0f8888a6134b992d6f60ad58ff2b2b6cf84ba612b72368cf569471b9214b85f7ce173e18872e89ddec
@@ -1,3 +1,11 @@
1
+ <a name="v2.63.0"></a>
2
+ ### v2.63.0 (2020-09-25)
3
+
4
+ #### Features
5
+
6
+ * allow label of can-i-deploy badge to be customised by setting the label query parameter ([ed544f94](/../../commit/ed544f94))
7
+ * add badges for can-i-deploy ([887a9ca3](/../../commit/887a9ca3))
8
+
1
9
  <a name="v2.62.0"></a>
2
10
  ### v2.62.0 (2020-09-23)
3
11
 
@@ -71,6 +71,7 @@ module PactBroker
71
71
  add ['pacticipants', :pacticipant_name, 'versions'], Api::Resources::Versions, {resource_name: "pacticipant_versions"}
72
72
  add ['pacticipants', :pacticipant_name, 'versions', :pacticipant_version_number], Api::Resources::Version, {resource_name: "pacticipant_version"}
73
73
  add ['pacticipants', :pacticipant_name, 'latest-version', :tag], Api::Resources::Version, {resource_name: "latest_tagged_pacticipant_version"}
74
+ add ['pacticipants', :pacticipant_name, 'latest-version', :tag, 'can-i-deploy', 'to', :to, 'badge'], Api::Resources::CanIDeployBadge, { resource_name: "can_i_deploy_badge" }
74
75
  add ['pacticipants', :pacticipant_name, 'latest-version'], Api::Resources::Version, {resource_name: "latest_pacticipant_version"}
75
76
  add ['pacticipants', :pacticipant_name, 'versions', :pacticipant_version_number, 'tags', :tag_name], Api::Resources::Tag, {resource_name: "pacticipant_version_tag"}
76
77
  add ['pacticipants', :pacticipant_name, 'labels', :label_name], Api::Resources::Label, {resource_name: "pacticipant_label"}
@@ -58,6 +58,22 @@ module PactBroker
58
58
  }
59
59
  end
60
60
 
61
+ link :'pb:can-i-deploy-badge' do | options |
62
+ {
63
+ title: "Can I Deploy #{represented.name} badge",
64
+ href: templated_can_i_deploy_badge_url(represented.name, options[:base_url]),
65
+ templated: true
66
+ }
67
+ end
68
+
69
+ curies do | options |
70
+ [{
71
+ name: :pb,
72
+ href: options[:base_url] + '/doc/{rel}?context=pacticipant',
73
+ templated: true
74
+ }]
75
+ end
76
+
61
77
  def to_hash options
62
78
  h = super
63
79
  dasherized = DasherizedVersionDecorator.new(represented).to_hash(options)
@@ -197,11 +197,15 @@ module PactBroker
197
197
  end
198
198
 
199
199
  def templated_tag_url_for_pacticipant pacticipant_name, base_url = ""
200
- pacticipant_url_from_params({pacticipant_name: pacticipant_name}, base_url) + "/versions/{version}/tags/{tag}"
200
+ pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/versions/{version}/tags/{tag}"
201
201
  end
202
202
 
203
203
  def templated_label_url_for_pacticipant pacticipant_name, base_url = ""
204
- pacticipant_url_from_params({pacticipant_name: pacticipant_name}, base_url) + "/labels/{label}"
204
+ pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/labels/{label}"
205
+ end
206
+
207
+ def templated_can_i_deploy_badge_url pacticipant_name, base_url = ""
208
+ pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/latest-version/{tag}/can-i-deploy/to/{environmentTag}/badge"
205
209
  end
206
210
 
207
211
  def label_url label, base_url
@@ -0,0 +1,85 @@
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(pacticipant_name, 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", ErrorHandler.display_message(e, "reference: #{ErrorHandler.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.find(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
@@ -32,11 +32,11 @@ module PactBroker
32
32
  PactBroker.configuration.warning_error_classes.any? { |clazz| e.is_a?(clazz) }
33
33
  end
34
34
 
35
- def self.display_message(e, error_reference)
35
+ def self.display_message(e, obfuscated_message)
36
36
  if PactBroker.configuration.show_backtrace_in_error_response?
37
- e.message || obfuscated_error_message(error_reference)
37
+ e.message || obfuscated_message
38
38
  else
39
- reportable?(e) ? obfuscated_error_message(error_reference) : e.message
39
+ reportable?(e) ? obfuscated_message : e.message
40
40
  end
41
41
  end
42
42
 
@@ -47,7 +47,7 @@ module PactBroker
47
47
  def self.response_body_hash e, error_reference
48
48
  response_body = {
49
49
  error: {
50
- message: display_message(e, error_reference),
50
+ message: display_message(e, obfuscated_error_message(error_reference)),
51
51
  reference: error_reference
52
52
  }
53
53
  }
@@ -6,7 +6,6 @@ module PactBroker
6
6
  module Api
7
7
  module Resources
8
8
  class Version < BaseResource
9
-
10
9
  def content_types_provided
11
10
  [["application/hal+json", :to_json]]
12
11
  end
@@ -20,7 +19,7 @@ module PactBroker
20
19
  end
21
20
 
22
21
  def to_json
23
- Decorators::VersionDecorator.new(version).to_json(user_options: {base_url: base_url})
22
+ Decorators::VersionDecorator.new(version).to_json(decorator_options)
24
23
  end
25
24
 
26
25
  def delete_resource
@@ -35,12 +34,12 @@ module PactBroker
35
34
  private
36
35
 
37
36
  def version
38
- if path_info[:tag]
39
- @version ||= version_service.find_by_pacticipant_name_and_latest_tag(path_info[:pacticipant_name], path_info[:tag])
40
- elsif path_info[:pacticipant_version_number]
41
- @version ||= version_service.find_by_pacticipant_name_and_number path_info
37
+ if identifier_from_path[:tag]
38
+ @version ||= version_service.find_by_pacticipant_name_and_latest_tag(identifier_from_path[:pacticipant_name], identifier_from_path[:tag])
39
+ elsif identifier_from_path[:pacticipant_version_number]
40
+ @version ||= version_service.find_by_pacticipant_name_and_number(identifier_from_path)
42
41
  else
43
- @version ||= version_service.find_latest_by_pacticpant_name path_info
42
+ @version ||= version_service.find_latest_by_pacticpant_name(identifier_from_path)
44
43
  end
45
44
  end
46
45
  end
@@ -33,6 +33,17 @@ module PactBroker
33
33
  build_shield_io_uri(title, status, color)
34
34
  end
35
35
 
36
+ def can_i_deploy_badge_url(pacticipant_name, tag, environment_tag, label, deployable)
37
+ title = label || "Can I deploy #{tag} #{pacticipant_name} to #{environment_tag}?"
38
+ status = deployable ? "yes" : "no"
39
+ color = deployable ? "brightgreen" : "red"
40
+ build_shield_io_uri(title, status, color)
41
+ end
42
+
43
+ def error_badge_url(left_text, right_text)
44
+ build_shield_io_uri(left_text, right_text, "lightgrey")
45
+ end
46
+
36
47
  def clear_cache
37
48
  CACHE.clear
38
49
  end
@@ -0,0 +1,9 @@
1
+ # Can I Deploy Badge
2
+
3
+ Allowed methods: `GET`
4
+
5
+ Path: `/pacticipants/{pacticipant}/latest-version/{tag}/can-i-deploy/to/{environmentTag}/badge`
6
+
7
+ Returns a status badge that can be displayed in a README file that indicates whether the specified version of a pacticipant can be deployed to the specified environment.
8
+
9
+ To set a custom label for the badge, set the `label` query parameter. eg `?label=my+custom+label+here`.
@@ -1,3 +1,3 @@
1
1
  module PactBroker
2
- VERSION = '2.62.0'
2
+ VERSION = '2.63.0'
3
3
  end
@@ -0,0 +1,13 @@
1
+ RSpec.describe "can i deploy badge" do
2
+ before do
3
+ td.create_pact_with_hierarchy("Foo", "1.2.3", "Bar")
4
+ .create_consumer_version_tag("main")
5
+ end
6
+
7
+ subject { get("/pacticipants/Foo/latest-version/main/can-i-deploy/to/prod/badge", nil, { 'HTTP_ACCEPT' => 'image/svg+xml'}) }
8
+
9
+ it "returns a redirect response" do
10
+ expect(subject.status).to eq 307
11
+ expect(subject.headers['Location']).to start_with "https://img.shields.io/badge"
12
+ end
13
+ end
@@ -24,7 +24,7 @@ describe "get latest matrix badge with tags" do
24
24
  # In the full app, the .svg extension is turned into an Accept header
25
25
  # by ConvertFileExtensionToAcceptHeader
26
26
 
27
- subject { get path, nil, {'HTTP_ACCEPT' => "image/svg+xml"}; last_response }
27
+ subject { get(path, nil, {'HTTP_ACCEPT' => "image/svg+xml"}) }
28
28
 
29
29
  it "returns a 200 status" do
30
30
  expect(subject.status).to eq 200
@@ -0,0 +1,80 @@
1
+ require 'pact_broker/api/resources/can_i_deploy_badge'
2
+
3
+ module PactBroker
4
+ module Api
5
+ module Resources
6
+ describe CanIDeployBadge do
7
+ before do
8
+ allow_any_instance_of(described_class).to receive(:badge_service).and_return(badge_service)
9
+ allow_any_instance_of(described_class).to receive(:matrix_service).and_return(matrix_service)
10
+ allow_any_instance_of(described_class).to receive(:pacticipant_service).and_return(pacticipant_service)
11
+ allow_any_instance_of(described_class).to receive(:version_service).and_return(version_service)
12
+ allow(badge_service).to receive(:can_i_deploy_badge_url).and_return("http://badge")
13
+ allow(badge_service).to receive(:error_badge_url).and_return("http://error")
14
+ allow(matrix_service).to receive(:find).and_return(results)
15
+ allow(pacticipant_service).to receive(:find_pacticipant_by_name).and_return(pacticipant)
16
+ allow(version_service).to receive(:find_by_pacticipant_name_and_latest_tag).and_return(version)
17
+ allow(PactBroker.configuration).to receive(:show_backtrace_in_error_response?).and_return(false)
18
+ allow(ErrorHandler).to receive(:generate_error_reference).and_return("abcd")
19
+ end
20
+
21
+ let(:pacticipant_service) { class_double("PactBroker::Pacticipant::Service").as_stubbed_const }
22
+ let(:badge_service) { class_double("PactBroker::Badges::Service").as_stubbed_const }
23
+ let(:matrix_service) { class_double("PactBroker::Matrix::Service").as_stubbed_const }
24
+ let(:version_service) { class_double("PactBroker::Version::Service").as_stubbed_const }
25
+ let(:results) { double('results', deployable?: true) }
26
+ let(:pacticipant) { double('pacticipant') }
27
+ let(:version) { double('version') }
28
+
29
+ let(:path) { "/pacticipants/Foo/latest-version/main/can-i-deploy/to/prod/badge"}
30
+
31
+ subject { get(path) }
32
+
33
+ context "when the pacticipant exists" do
34
+ it "returns a redirect to the badge" do
35
+ expect(badge_service).to receive(:can_i_deploy_badge_url).with("Foo", "main", "prod", nil, true)
36
+ expect(subject.status).to eq 307
37
+ end
38
+ end
39
+
40
+ context "when the pacticipant does not exist" do
41
+ let(:pacticipant) { nil }
42
+
43
+ it "returns a redirect to a 'not found' badge" do
44
+ expect(badge_service).to receive(:error_badge_url).with("Foo", "not found")
45
+ expect(subject.status).to eq 307
46
+ end
47
+ end
48
+
49
+ context "when the version does not exist" do
50
+ let(:version) { nil }
51
+
52
+ it "returns a redirect to a 'not found' badge" do
53
+ expect(badge_service).to receive(:error_badge_url).with("version", "not found")
54
+ expect(subject.status).to eq 307
55
+ end
56
+ end
57
+
58
+ context "with a custom label" do
59
+ subject { get(path, label: "some custom label") }
60
+
61
+ it "returns a redirect to a badge with a custom label" do
62
+ expect(badge_service).to receive(:can_i_deploy_badge_url).with("Foo", "main", "prod", "some custom label", true)
63
+ subject
64
+ end
65
+ end
66
+
67
+ context "when there is an error" do
68
+ before do
69
+ allow(matrix_service).to receive(:find).and_raise("foo error")
70
+ end
71
+
72
+ it "returns a redirect to a badge with an error message" do
73
+ expect(badge_service).to receive(:error_badge_url).with("error", "reference: abcd")
74
+ expect(subject.status).to eq 307
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
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.62.0
4
+ version: 2.63.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: 2020-09-24 00:00:00.000000000 Z
13
+ date: 2020-09-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -642,6 +642,7 @@ files:
642
642
  - lib/pact_broker/api/resources/badge.rb
643
643
  - lib/pact_broker/api/resources/base_resource.rb
644
644
  - lib/pact_broker/api/resources/can_i_deploy.rb
645
+ - lib/pact_broker/api/resources/can_i_deploy_badge.rb
645
646
  - lib/pact_broker/api/resources/dashboard.rb
646
647
  - lib/pact_broker/api/resources/default_base_resource.rb
647
648
  - lib/pact_broker/api/resources/error_handler.rb
@@ -761,6 +762,7 @@ files:
761
762
  - lib/pact_broker/doc/views/pact/publish-verification-results.markdown
762
763
  - lib/pact_broker/doc/views/pact/tag-prod-version.markdown
763
764
  - lib/pact_broker/doc/views/pact/tag-version.markdown
765
+ - lib/pact_broker/doc/views/pacticipant/can-i-deploy-badge.markdown
764
766
  - lib/pact_broker/doc/views/pending-provider-pacts.markdown
765
767
  - lib/pact_broker/doc/views/provider-pacts-for-verification.markdown
766
768
  - lib/pact_broker/doc/views/provider.markdown
@@ -1052,6 +1054,7 @@ files:
1052
1054
  - spec/features/edit_webhook_spec.rb
1053
1055
  - spec/features/execute_unsaved_webhook_spec.rb
1054
1056
  - spec/features/execute_webhook_spec.rb
1057
+ - spec/features/get_can_i_deploy_badge_spec.rb
1055
1058
  - spec/features/get_dashboard_spec.rb
1056
1059
  - spec/features/get_diff_spec.rb
1057
1060
  - spec/features/get_integrations_dot_file_spec.rb
@@ -1166,6 +1169,7 @@ files:
1166
1169
  - spec/lib/pact_broker/api/renderers/integrations_dot_renderer_spec.rb
1167
1170
  - spec/lib/pact_broker/api/resources/all_webhooks_spec.rb
1168
1171
  - spec/lib/pact_broker/api/resources/badge_spec.rb
1172
+ - spec/lib/pact_broker/api/resources/can_i_deploy_badge_spec.rb
1169
1173
  - spec/lib/pact_broker/api/resources/dashboard_spec.rb
1170
1174
  - spec/lib/pact_broker/api/resources/default_base_resource_spec.rb
1171
1175
  - spec/lib/pact_broker/api/resources/error_handler_spec.rb
@@ -1438,6 +1442,7 @@ test_files:
1438
1442
  - spec/features/edit_webhook_spec.rb
1439
1443
  - spec/features/execute_unsaved_webhook_spec.rb
1440
1444
  - spec/features/execute_webhook_spec.rb
1445
+ - spec/features/get_can_i_deploy_badge_spec.rb
1441
1446
  - spec/features/get_dashboard_spec.rb
1442
1447
  - spec/features/get_diff_spec.rb
1443
1448
  - spec/features/get_integrations_dot_file_spec.rb
@@ -1552,6 +1557,7 @@ test_files:
1552
1557
  - spec/lib/pact_broker/api/renderers/integrations_dot_renderer_spec.rb
1553
1558
  - spec/lib/pact_broker/api/resources/all_webhooks_spec.rb
1554
1559
  - spec/lib/pact_broker/api/resources/badge_spec.rb
1560
+ - spec/lib/pact_broker/api/resources/can_i_deploy_badge_spec.rb
1555
1561
  - spec/lib/pact_broker/api/resources/dashboard_spec.rb
1556
1562
  - spec/lib/pact_broker/api/resources/default_base_resource_spec.rb
1557
1563
  - spec/lib/pact_broker/api/resources/error_handler_spec.rb