-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: render matrix UI page for can-i-deploy endpoint
- Loading branch information
Showing
6 changed files
with
118 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'pact_broker/ui/controllers/base_controller' | ||
require 'pact_broker/ui/view_models/matrix_lines' | ||
require 'pact_broker/matrix/unresolved_selector' | ||
require 'pact_broker/matrix/parse_query' | ||
require 'pact_broker/logging' | ||
require 'pact_broker/api/pact_broker_urls' | ||
require 'pact_broker/ui/helpers/matrix_helper' | ||
require 'haml' | ||
|
||
module PactBroker | ||
module UI | ||
module Controllers | ||
class CanIDeploy < Base | ||
|
||
include PactBroker::Services | ||
include PactBroker::UI::Helpers::MatrixHelper | ||
|
||
get "/:pacticipant_name/latest-version/:tag/can-i-deploy/to/:environment_tag" do | ||
# selector and options must be in sync with lib/pact_broker/api/resources/can_i_deploy_badge.rb | ||
selectors = [ PactBroker::Matrix::UnresolvedSelector.new(pacticipant_name: params[:pacticipant_name], latest: true, tag: params[:tag]) ] | ||
options = { latestby: 'cvp', limit: 100, tag: params[:to] } | ||
result = matrix_service.find(selectors, options) | ||
lines = PactBroker::UI::ViewDomain::MatrixLines.new(result, base_url: base_url) | ||
locals = { | ||
lines: lines, | ||
selectors: create_selector_objects(selectors), | ||
options: create_options_model(options), | ||
badge_url: badge_url, | ||
base_url: base_url | ||
} | ||
haml :'matrix/show', { locals: locals, layout: :'layouts/main', escape_html: true } | ||
end | ||
|
||
def badge_url | ||
u = URI(request.url) | ||
u.path = u.path + "/badge" | ||
u.to_s | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module PactBroker | ||
module UI | ||
module Helpers | ||
module MatrixHelper | ||
|
||
extend self | ||
|
||
def create_selector_objects(selector_hashes) | ||
selector_hashes.collect do | selector_hash | | ||
o = OpenStruct.new(selector_hash) | ||
o.specify_latest_tag = o.tag && o.latest ? 'checked' : nil | ||
o.specify_all_tagged = o.tag && !o.latest ? 'checked' : nil | ||
o.specify_latest = o.latest ? 'checked' : nil | ||
o.specify_version = o.pacticipant_version_number ? 'checked' : nil | ||
o.specify_all_versions = !(o.tag || o.pacticipant_version_number) ? 'checked' : nil | ||
o | ||
end | ||
end | ||
|
||
def create_options_model(options) | ||
o = OpenStruct.new(options) | ||
o.cvpv_checked = o.latestby == 'cvpv' ? 'checked' : nil | ||
o.cvp_checked = o.latestby == 'cvp' ? 'checked' : nil | ||
o.all_rows_checked = o.latestby.nil? ? 'checked' : nil | ||
o | ||
end | ||
|
||
def matrix_badge_url(selectors, lines, base_url) | ||
if lines.any? && selectors.size == 2 && selectors.all?{ | selector| selector.latest_for_pacticipant_and_tag? } | ||
consumer_selector = selectors.find{ | selector| selector.pacticipant_name == lines.first.consumer_name } | ||
provider_selector = selectors.find{ | selector| selector.pacticipant_name == lines.first.provider_name } | ||
if consumer_selector && provider_selector | ||
PactBroker::Api::PactBrokerUrls.matrix_badge_url_for_selectors(consumer_selector, provider_selector, base_url) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'pact_broker/ui/controllers/can_i_deploy' | ||
|
||
module PactBroker | ||
module UI | ||
module Controllers | ||
describe CanIDeploy do | ||
|
||
let(:app) { CanIDeploy } | ||
|
||
describe "GET" do | ||
before do | ||
TestDataBuilder.new | ||
.create_pact_with_hierarchy("Foo", "1", "Bar") | ||
.create_consumer_version_tag("main") | ||
end | ||
|
||
subject { get("/Foo/latest-version/main/can-i-deploy/to/prod") } | ||
|
||
it "renders the matrix page" do | ||
expect(subject.body).to include "The Matrix" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |