pact_broker 2.63.0 → 2.64.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: 61338a93bd65ffa3ec70f4fdfd9b509a0d5c0608dce8cea3f779e3ac22151412
4
- data.tar.gz: 99819023ba051657020d314fe6d3005a04660d70467a57c5b5369a08a5525e2a
3
+ metadata.gz: 3fee7d96bde4fc04adb41fe041a124e81c9b371336f9308f92c918a2fb4ca914
4
+ data.tar.gz: 3706e5b3a8fbf6db31c748658a1b0f22713f872889757844c9506250b2cefa54
5
5
  SHA512:
6
- metadata.gz: 7da446c51346413782377eb409c2d3159fcb322147d675324126243bfb8b115ff042d210b3cf25ee46ebe73093611e4de85db03f243c5ffb06299239d6aff637
7
- data.tar.gz: 6b191f39b782bf811d58e15d149fa5e786227e6a86d93c0f8888a6134b992d6f60ad58ff2b2b6cf84ba612b72368cf569471b9214b85f7ce173e18872e89ddec
6
+ metadata.gz: d1a1046845fb3832062d675ebfa1d49e0fa62ac6ea8acb8edb6c706b53e66888b72a243bc16e94842b89b4b349adf3ac22c3f35f043a75538f9dea7f3d28122a
7
+ data.tar.gz: fdad352fd207e05717eb127ec0ad0c35de8465b4dfed9a6cdcf862bc5d6f169bf15975a932c8cd355716b90ba3291552fadc35aab1768710179f330592fd5166
@@ -1,3 +1,12 @@
1
+ <a name="v2.64.0"></a>
2
+ ### v2.64.0 (2020-09-25)
3
+
4
+ #### Features
5
+
6
+ * add API endpoint for can-i-deploy for latest tagged pacticipant version ([88fdc60a](/../../commit/88fdc60a))
7
+ * render matrix UI page for can-i-deploy endpoint ([463e9cfd](/../../commit/463e9cfd))
8
+ * change text on can-i-deploy badge ([f9e183e9](/../../commit/f9e183e9))
9
+
1
10
  <a name="v2.63.0"></a>
2
11
  ### v2.63.0 (2020-09-25)
3
12
 
@@ -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], Api::Resources::CanIDeployPacticipantVersion, { resource_name: "can_i_deploy_latest_tagged_version" }
74
75
  add ['pacticipants', :pacticipant_name, 'latest-version', :tag, 'can-i-deploy', 'to', :to, 'badge'], Api::Resources::CanIDeployBadge, { resource_name: "can_i_deploy_badge" }
75
76
  add ['pacticipants', :pacticipant_name, 'latest-version'], Api::Resources::Version, {resource_name: "latest_pacticipant_version"}
76
77
  add ['pacticipants', :pacticipant_name, 'versions', :pacticipant_version_number, 'tags', :tag_name], Api::Resources::Tag, {resource_name: "pacticipant_version_tag"}
@@ -204,8 +204,12 @@ module PactBroker
204
204
  pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/labels/{label}"
205
205
  end
206
206
 
207
+ def templated_can_i_deploy_url pacticipant_name, base_url = ""
208
+ pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/latest-version/{tag}/can-i-deploy/to/{environmentTag}"
209
+ end
210
+
207
211
  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"
212
+ templated_can_i_deploy_url(pacticipant_name, base_url) + "/badge"
209
213
  end
210
214
 
211
215
  def label_url label, base_url
@@ -46,7 +46,7 @@ module PactBroker
46
46
  begin
47
47
  if pacticipant
48
48
  if version
49
- badge_service.can_i_deploy_badge_url(pacticipant_name, identifier_from_path[:tag], identifier_from_path[:to], label, results.deployable?)
49
+ badge_service.can_i_deploy_badge_url(identifier_from_path[:tag], identifier_from_path[:to], label, results.deployable?)
50
50
  else
51
51
  badge_service.error_badge_url("version", "not found")
52
52
  end
@@ -0,0 +1,40 @@
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 CanIDeployPacticipantVersion < Matrix
9
+ def initialize
10
+ super
11
+ selector = PactBroker::Matrix::UnresolvedSelector.new(pacticipant_name: pacticipant_name, latest: true, tag: identifier_from_path[:tag])
12
+ @options = {
13
+ latestby: 'cvp',
14
+ latest: true,
15
+ tag: identifier_from_path[:to]
16
+ }
17
+ @selectors = [selector]
18
+ end
19
+
20
+ def resource_exists?
21
+ !!version
22
+ end
23
+
24
+ def policy_name
25
+ :'matrix::can_i_deploy'
26
+ end
27
+
28
+ private
29
+
30
+ def version
31
+ @version ||= version_service.find_by_pacticipant_name_and_latest_tag(identifier_from_path[:pacticipant_name], identifier_from_path[:tag])
32
+ end
33
+
34
+ def results
35
+ @results ||= matrix_service.find(selectors, options)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -33,9 +33,9 @@ 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"
36
+ def can_i_deploy_badge_url(tag, environment_tag, label, deployable)
37
+ title = label || "can-i-deploy"
38
+ status = "#{tag} to #{environment_tag}"
39
39
  color = deployable ? "brightgreen" : "red"
40
40
  build_shield_io_uri(title, status, color)
41
41
  end
@@ -1,6 +1,7 @@
1
1
  require 'pact_broker/ui/controllers/index'
2
2
  require 'pact_broker/ui/controllers/groups'
3
3
  require 'pact_broker/ui/controllers/matrix'
4
+ require 'pact_broker/ui/controllers/can_i_deploy'
4
5
  require 'pact_broker/ui/controllers/error_test'
5
6
  require 'pact_broker/doc/controllers/app'
6
7
 
@@ -41,6 +42,11 @@ module PactBroker
41
42
  run PactBroker::UI::Controllers::Matrix
42
43
  end
43
44
 
45
+ map "/pacticipants/" do
46
+ use PathInfoFixer
47
+ run PactBroker::UI::Controllers::CanIDeploy
48
+ end
49
+
44
50
  map "/test/error" do
45
51
  use PathInfoFixer
46
52
  run PactBroker::UI::Controllers::ErrorTest
@@ -0,0 +1,42 @@
1
+ require 'pact_broker/ui/controllers/base_controller'
2
+ require 'pact_broker/ui/view_models/matrix_lines'
3
+ require 'pact_broker/matrix/unresolved_selector'
4
+ require 'pact_broker/matrix/parse_query'
5
+ require 'pact_broker/logging'
6
+ require 'pact_broker/api/pact_broker_urls'
7
+ require 'pact_broker/ui/helpers/matrix_helper'
8
+ require 'haml'
9
+
10
+ module PactBroker
11
+ module UI
12
+ module Controllers
13
+ class CanIDeploy < Base
14
+
15
+ include PactBroker::Services
16
+ include PactBroker::UI::Helpers::MatrixHelper
17
+
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
20
+ selectors = [ PactBroker::Matrix::UnresolvedSelector.new(pacticipant_name: params[:pacticipant_name], latest: true, tag: params[:tag]) ]
21
+ options = { latestby: 'cvp', limit: 100, tag: params[:to] }
22
+ result = matrix_service.find(selectors, options)
23
+ lines = PactBroker::UI::ViewDomain::MatrixLines.new(result, base_url: base_url)
24
+ locals = {
25
+ lines: lines,
26
+ selectors: create_selector_objects(selectors),
27
+ options: create_options_model(options),
28
+ badge_url: badge_url,
29
+ base_url: base_url
30
+ }
31
+ haml :'matrix/show', { locals: locals, layout: :'layouts/main', escape_html: true }
32
+ end
33
+
34
+ def badge_url
35
+ u = URI(request.url)
36
+ u.path = u.path + "/badge"
37
+ u.to_s
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -4,7 +4,7 @@ require 'pact_broker/matrix/unresolved_selector'
4
4
  require 'pact_broker/matrix/parse_query'
5
5
  require 'pact_broker/logging'
6
6
  require 'pact_broker/api/pact_broker_urls'
7
-
7
+ require 'pact_broker/ui/helpers/matrix_helper'
8
8
  require 'haml'
9
9
 
10
10
  module PactBroker
@@ -13,13 +13,13 @@ module PactBroker
13
13
  class Matrix < Base
14
14
 
15
15
  include PactBroker::Services
16
+ include PactBroker::UI::Helpers::MatrixHelper
16
17
 
17
18
  get "/" do
18
19
  selectors = [OpenStruct.new, OpenStruct.new]
19
20
  options = { limit: 100, latestby: nil }
20
21
  locals = {
21
22
  lines: [],
22
- title: "The Matrix",
23
23
  selectors: create_selector_objects(selectors),
24
24
  options: create_options_model(options),
25
25
  base_url: base_url
@@ -33,7 +33,7 @@ module PactBroker
33
33
  if errors.empty?
34
34
  lines = matrix_service.find(selectors, options)
35
35
  locals[:lines] = PactBroker::UI::ViewDomain::MatrixLines.new(lines)
36
- locals[:badge_url] = matrix_badge_url(selectors, lines)
36
+ locals[:badge_url] = matrix_badge_url(selectors, lines, base_url)
37
37
  else
38
38
  locals[:errors] = errors
39
39
  end
@@ -52,7 +52,6 @@ module PactBroker
52
52
  lines = PactBroker::UI::ViewDomain::MatrixLines.new(lines, base_url: base_url)
53
53
  locals = {
54
54
  lines: lines,
55
- title: "The Matrix",
56
55
  consumer_name: params[:consumer_name],
57
56
  provider_name: params[:provider_name],
58
57
  selectors: create_selector_objects(selectors),
@@ -62,36 +61,6 @@ module PactBroker
62
61
  }
63
62
  haml :'matrix/show', { locals: locals, layout: :'layouts/main', escape_html: true }
64
63
  end
65
-
66
- def create_selector_objects(selector_hashes)
67
- selector_hashes.collect do | selector_hash |
68
- o = OpenStruct.new(selector_hash)
69
- o.specify_latest_tag = o.tag && o.latest ? 'checked' : nil
70
- o.specify_all_tagged = o.tag && !o.latest ? 'checked' : nil
71
- o.specify_latest = o.latest ? 'checked' : nil
72
- o.specify_version = o.pacticipant_version_number ? 'checked' : nil
73
- o.specify_all_versions = !(o.tag || o.pacticipant_version_number) ? 'checked' : nil
74
- o
75
- end
76
- end
77
-
78
- def create_options_model(options)
79
- o = OpenStruct.new(options)
80
- o.cvpv_checked = o.latestby == 'cvpv' ? 'checked' : nil
81
- o.cvp_checked = o.latestby == 'cvp' ? 'checked' : nil
82
- o.all_rows_checked = o.latestby.nil? ? 'checked' : nil
83
- o
84
- end
85
-
86
- def matrix_badge_url(selectors, lines)
87
- if lines.any? && selectors.size == 2 && selectors.all?{ | selector| selector.latest_for_pacticipant_and_tag? }
88
- consumer_selector = selectors.find{ | selector| selector.pacticipant_name == lines.first.consumer_name }
89
- provider_selector = selectors.find{ | selector| selector.pacticipant_name == lines.first.provider_name }
90
- if consumer_selector && provider_selector
91
- PactBroker::Api::PactBrokerUrls.matrix_badge_url_for_selectors(consumer_selector, provider_selector, base_url)
92
- end
93
- end
94
- end
95
64
  end
96
65
  end
97
66
  end
@@ -0,0 +1,40 @@
1
+ module PactBroker
2
+ module UI
3
+ module Helpers
4
+ module MatrixHelper
5
+
6
+ extend self
7
+
8
+ def create_selector_objects(selector_hashes)
9
+ selector_hashes.collect do | selector_hash |
10
+ o = OpenStruct.new(selector_hash)
11
+ o.specify_latest_tag = o.tag && o.latest ? 'checked' : nil
12
+ o.specify_all_tagged = o.tag && !o.latest ? 'checked' : nil
13
+ o.specify_latest = o.latest ? 'checked' : nil
14
+ o.specify_version = o.pacticipant_version_number ? 'checked' : nil
15
+ o.specify_all_versions = !(o.tag || o.pacticipant_version_number) ? 'checked' : nil
16
+ o
17
+ end
18
+ end
19
+
20
+ def create_options_model(options)
21
+ o = OpenStruct.new(options)
22
+ o.cvpv_checked = o.latestby == 'cvpv' ? 'checked' : nil
23
+ o.cvp_checked = o.latestby == 'cvp' ? 'checked' : nil
24
+ o.all_rows_checked = o.latestby.nil? ? 'checked' : nil
25
+ o
26
+ end
27
+
28
+ def matrix_badge_url(selectors, lines, base_url)
29
+ if lines.any? && selectors.size == 2 && selectors.all?{ | selector| selector.latest_for_pacticipant_and_tag? }
30
+ consumer_selector = selectors.find{ | selector| selector.pacticipant_name == lines.first.consumer_name }
31
+ provider_selector = selectors.find{ | selector| selector.pacticipant_name == lines.first.provider_name }
32
+ if consumer_selector && provider_selector
33
+ PactBroker::Api::PactBrokerUrls.matrix_badge_url_for_selectors(consumer_selector, provider_selector, base_url)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -13,7 +13,7 @@
13
13
  %a{href: "#{base_url}/"}
14
14
  Home
15
15
  %h1.page-header
16
- = title
16
+ The Matrix
17
17
  - if defined?(badge_url) && badge_url
18
18
  %img{src: badge_url, class: 'pact_badge' }
19
19
 
@@ -1,3 +1,3 @@
1
1
  module PactBroker
2
- VERSION = '2.63.0'
2
+ VERSION = '2.64.0'
3
3
  end
@@ -32,7 +32,7 @@ module PactBroker
32
32
 
33
33
  context "when the pacticipant exists" do
34
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)
35
+ expect(badge_service).to receive(:can_i_deploy_badge_url).with("main", "prod", nil, true)
36
36
  expect(subject.status).to eq 307
37
37
  end
38
38
  end
@@ -59,7 +59,7 @@ module PactBroker
59
59
  subject { get(path, label: "some custom label") }
60
60
 
61
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)
62
+ expect(badge_service).to receive(:can_i_deploy_badge_url).with("main", "prod", "some custom label", true)
63
63
  subject
64
64
  end
65
65
  end
@@ -0,0 +1,31 @@
1
+ require 'pact_broker/api/resources/can_i_deploy_pacticipant_version'
2
+ require 'pact_broker/matrix/service'
3
+
4
+ module PactBroker
5
+ module Api
6
+ module Resources
7
+ describe CanIDeployPacticipantVersion do
8
+ include_context "stubbed services"
9
+
10
+ before do
11
+ allow(PactBroker::Matrix::Service).to receive(:find).and_return([])
12
+ allow(pacticipant_service).to receive(:find_pacticipant_by_name).and_return(pacticipant)
13
+ allow(version_service).to receive(:find_by_pacticipant_name_and_latest_tag).and_return(version)
14
+ allow(PactBroker::Api::Decorators::MatrixDecorator).to receive(:new).and_return(decorator)
15
+ end
16
+
17
+ let(:pacticipant) { double('pacticipant') }
18
+ let(:version) { double('version') }
19
+ let(:path) { "/pacticipants/Foo/latest-version/main/can-i-deploy/to/prod" }
20
+ let(:json_response_body) { JSON.parse(subject.body, symbolize_names: true) }
21
+ let(:decorator) { double('decorator', to_json: 'response_body') }
22
+ let(:selectors) { double('selectors') }
23
+ let(:options) { double('options') }
24
+
25
+ subject { get(path, nil, 'Content-Type' => 'application/hal+json') }
26
+
27
+ it { is_expected.to be_a_hal_json_success_response }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -29,6 +29,12 @@ module PactBroker
29
29
  allow(Service).to receive(:logger).and_return(logger)
30
30
  end
31
31
 
32
+ describe "can_i_deploy_badge_url" do
33
+ subject { Service.can_i_deploy_badge_url("main", "prod", nil, true) }
34
+
35
+ it { is_expected.to eq URI("https://img.shields.io/badge/can--i--deploy-main%20to%20prod-brightgreen.svg") }
36
+ end
37
+
32
38
  describe "pact_verification_badge_url" do
33
39
  context "with the pact is nil" do
34
40
  let(:pact) { nil }
@@ -0,0 +1,26 @@
1
+ require 'pact_broker/ui/controllers/can_i_deploy'
2
+
3
+ module PactBroker
4
+ module UI
5
+ module Controllers
6
+ describe CanIDeploy do
7
+
8
+ let(:app) { CanIDeploy }
9
+
10
+ describe "GET" do
11
+ before do
12
+ TestDataBuilder.new
13
+ .create_pact_with_hierarchy("Foo", "1", "Bar")
14
+ .create_consumer_version_tag("main")
15
+ end
16
+
17
+ subject { get("/Foo/latest-version/main/can-i-deploy/to/prod") }
18
+
19
+ it "renders the matrix page" do
20
+ expect(subject.body).to include "The Matrix"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ 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.63.0
4
+ version: 2.64.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bethany Skurrie
@@ -643,6 +643,7 @@ files:
643
643
  - lib/pact_broker/api/resources/base_resource.rb
644
644
  - lib/pact_broker/api/resources/can_i_deploy.rb
645
645
  - lib/pact_broker/api/resources/can_i_deploy_badge.rb
646
+ - lib/pact_broker/api/resources/can_i_deploy_pacticipant_version.rb
646
647
  - lib/pact_broker/api/resources/dashboard.rb
647
648
  - lib/pact_broker/api/resources/default_base_resource.rb
648
649
  - lib/pact_broker/api/resources/error_handler.rb
@@ -869,11 +870,13 @@ files:
869
870
  - lib/pact_broker/ui.rb
870
871
  - lib/pact_broker/ui/app.rb
871
872
  - lib/pact_broker/ui/controllers/base_controller.rb
873
+ - lib/pact_broker/ui/controllers/can_i_deploy.rb
872
874
  - lib/pact_broker/ui/controllers/clusters.rb
873
875
  - lib/pact_broker/ui/controllers/error_test.rb
874
876
  - lib/pact_broker/ui/controllers/groups.rb
875
877
  - lib/pact_broker/ui/controllers/index.rb
876
878
  - lib/pact_broker/ui/controllers/matrix.rb
879
+ - lib/pact_broker/ui/helpers/matrix_helper.rb
877
880
  - lib/pact_broker/ui/helpers/url_helper.rb
878
881
  - lib/pact_broker/ui/view_models/clusters.rb
879
882
  - lib/pact_broker/ui/view_models/index_item.rb
@@ -1170,6 +1173,7 @@ files:
1170
1173
  - spec/lib/pact_broker/api/resources/all_webhooks_spec.rb
1171
1174
  - spec/lib/pact_broker/api/resources/badge_spec.rb
1172
1175
  - spec/lib/pact_broker/api/resources/can_i_deploy_badge_spec.rb
1176
+ - spec/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_spec.rb
1173
1177
  - spec/lib/pact_broker/api/resources/dashboard_spec.rb
1174
1178
  - spec/lib/pact_broker/api/resources/default_base_resource_spec.rb
1175
1179
  - spec/lib/pact_broker/api/resources/error_handler_spec.rb
@@ -1274,6 +1278,7 @@ files:
1274
1278
  - spec/lib/pact_broker/relationships/groupify_spec.rb
1275
1279
  - spec/lib/pact_broker/tags/repository_spec.rb
1276
1280
  - spec/lib/pact_broker/tags/service_spec.rb
1281
+ - spec/lib/pact_broker/ui/controllers/can_i_deploy_spec.rb
1277
1282
  - spec/lib/pact_broker/ui/controllers/clusters_spec.rb
1278
1283
  - spec/lib/pact_broker/ui/controllers/index_spec.rb
1279
1284
  - spec/lib/pact_broker/ui/view_models/index_item_spec.rb
@@ -1558,6 +1563,7 @@ test_files:
1558
1563
  - spec/lib/pact_broker/api/resources/all_webhooks_spec.rb
1559
1564
  - spec/lib/pact_broker/api/resources/badge_spec.rb
1560
1565
  - spec/lib/pact_broker/api/resources/can_i_deploy_badge_spec.rb
1566
+ - spec/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_spec.rb
1561
1567
  - spec/lib/pact_broker/api/resources/dashboard_spec.rb
1562
1568
  - spec/lib/pact_broker/api/resources/default_base_resource_spec.rb
1563
1569
  - spec/lib/pact_broker/api/resources/error_handler_spec.rb
@@ -1662,6 +1668,7 @@ test_files:
1662
1668
  - spec/lib/pact_broker/relationships/groupify_spec.rb
1663
1669
  - spec/lib/pact_broker/tags/repository_spec.rb
1664
1670
  - spec/lib/pact_broker/tags/service_spec.rb
1671
+ - spec/lib/pact_broker/ui/controllers/can_i_deploy_spec.rb
1665
1672
  - spec/lib/pact_broker/ui/controllers/clusters_spec.rb
1666
1673
  - spec/lib/pact_broker/ui/controllers/index_spec.rb
1667
1674
  - spec/lib/pact_broker/ui/view_models/index_item_spec.rb