Skip to content

Commit

Permalink
Feat/add environments to UI (#394)
Browse files Browse the repository at this point in the history
* feat(deployments): create endpoint for recording deployments

* test: update tests for version decorator and approvals

* feat: support specifying an environment when calling the can-i-deploy and matrix endpoints

* chore: made sure all db models are loaded

* feat: support marking previously deployed version as not currently deployed

* feat: add validation to ensure both tag and environment can't be used together to query the matrix

* chore: update key name

* chore: update deployed versions resource policy

* feat: distinguish between "the" version in an environment and "one of the versions" in an environment in the matrix explanation messages

* test: add tests to cover the 'multiple versions in an environment' use case

* feat: add environments to index and matrix pages

* style: reformatting
  • Loading branch information
bethesque authored Feb 24, 2021
1 parent 19ac1fc commit 20a5f42
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 10 deletions.
8 changes: 8 additions & 0 deletions lib/pact_broker/domain/index_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def consumer_version_branch
consumer_version.branch
end

def consumer_version_environment_names
consumer_version.current_deployed_versions.collect(&:environment).collect(&:name)
end

def latest_for_branch?
@latest_for_branch
end
Expand All @@ -90,6 +94,10 @@ def provider_version_branch
provider_version&.branch
end

def provider_version_environment_names
provider_version&.current_deployed_versions&.collect(&:environment)&.collect(&:name) || []
end

# these are the consumer tag names for which this pact publication
# is the latest with that tag
def tag_names
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/domain/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Version < Sequel::Model
one_to_many :pact_publications, order: :revision_number, class: "PactBroker::Pacts::PactPublication", key: :consumer_version_id
associate(:many_to_one, :pacticipant, :class => "PactBroker::Domain::Pacticipant", :key => :pacticipant_id, :primary_key => :id)
one_to_many :tags, :reciprocal => :version, order: :created_at
one_to_many :current_deployed_versions, class: "PactBroker::Deployments::DeployedVersion", key: :version_id, primary_key: :id do | ds |
one_to_many :current_deployed_versions, class: "PactBroker::Deployments::DeployedVersion", key: :version_id, primary_key: :id, order: [:created_at, :id] do | ds |
ds.currently_deployed
end

Expand Down
10 changes: 5 additions & 5 deletions lib/pact_broker/index/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def self.find_index_items options = {}
.eager(:provider)
.eager(:pact_version)
.eager(integration: [{latest_verification: :provider_version}, :latest_triggered_webhooks])
.eager(consumer_version: [:latest_version_for_branch, { tags: :head_tag }])
.eager(latest_verification: { provider_version: [:latest_version_for_branch, { tags: :head_tag } ] })
.eager(consumer_version: [{ current_deployed_versions: :environment }, :latest_version_for_branch, { tags: :head_tag }])
.eager(latest_verification: { provider_version: [{ current_deployed_versions: :environment }, :latest_version_for_branch, { tags: :head_tag } ] })
.eager(:head_pact_publications_for_tags)

index_items = pact_publications.all.collect do | pact_publication |
Expand Down Expand Up @@ -104,8 +104,8 @@ def self.find_index_items_for_api(consumer_name: nil, provider_name: nil, **igno
.eager(:consumer)
.eager(:provider)
.eager(:pact_version)
.eager(consumer_version: [:latest_version_for_branch, { tags: :head_tag }])
.eager(latest_verification: { provider_version: [:latest_version_for_branch, { tags: :head_tag }]})
.eager(consumer_version: [{ current_deployed_versions: :environment }, :latest_version_for_branch, { tags: :head_tag }])
.eager(latest_verification: { provider_version: [{ current_deployed_versions: :environment }, :latest_version_for_branch, { tags: :head_tag }]})
.eager(:head_pact_publications_for_tags)

pact_publications.all.collect do | pact_publication |
Expand Down Expand Up @@ -184,7 +184,7 @@ def self.latest_verifications_for_consumer_version_tags(options)
.all
elsif options[:tags] # server side rendered index page with tags=true
PactBroker::Verifications::LatestVerificationForConsumerVersionTag
.eager(:provider_version)
.eager(provider_version: { current_deployed_versions: :environment })
.all
else
nil # should not be used
Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/matrix/quick_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def order_by_pact_publication_created_at
def eager_all_the_things
eager(:consumer)
.eager(:provider)
.eager(:consumer_version)
.eager(:provider_version)
.eager(consumer_version: { current_deployed_versions: :environment })
.eager(provider_version: { current_deployed_versions: :environment })
.eager(:verification)
.eager(:pact_publication)
.eager(:pact_version)
Expand Down
8 changes: 7 additions & 1 deletion lib/pact_broker/pacts/pact_publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ def to_version_domain
end

def to_version_domain_lightweight
OpenStruct.new(number: consumer_version.number, pacticipant: consumer, order: consumer_version.order, branch: consumer_version.branch)
OpenStruct.new(
number: consumer_version.number,
pacticipant: consumer,
order: consumer_version.order,
branch: consumer_version.branch,
current_deployed_versions: consumer_version.associations[:current_deployed_versions]
)
end

private
Expand Down
8 changes: 7 additions & 1 deletion lib/pact_broker/ui/view_models/index_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ module ViewDomain
class IndexItem
extend Forwardable

delegate [:consumer_version_branch, :provider_version_branch, :latest_for_branch?] => :relationship
delegate [
:consumer_version_branch,
:provider_version_branch,
:latest_for_branch?,
:consumer_version_environment_names,
:provider_version_environment_names
] => :relationship


include PactBroker::Api::PactBrokerUrls
Expand Down
37 changes: 37 additions & 0 deletions lib/pact_broker/ui/view_models/matrix_deployed_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'pact_broker/api/pact_broker_urls'
require 'pact_broker/ui/helpers/url_helper'
require 'pact_broker/date_helper'

module PactBroker
module UI
module ViewDomain
class MatrixDeployedVersion
include PactBroker::Api::PactBrokerUrls

def initialize deployed_version
@deployed_version = deployed_version
end

def environment_name
deployed_version.environment.name
end

def tooltip
"Currently deployed to #{deployed_version.environment.display_name} (#{relative_date(deployed_version.created_at)})"
end

def url
hal_browser_url(deployed_version_url(deployed_version))
end

private

attr_reader :deployed_version

def relative_date date
DateHelper.distance_of_time_in_words(date, DateTime.now) + " ago"
end
end
end
end
end
13 changes: 13 additions & 0 deletions lib/pact_broker/ui/view_models/matrix_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'pact_broker/ui/helpers/url_helper'
require 'pact_broker/date_helper'
require 'pact_broker/ui/view_models/matrix_tag'
require 'pact_broker/ui/view_models/matrix_deployed_version'
require 'pact_broker/versions/abbreviate_number'
require 'pact_broker/messages'
require 'forwardable'
Expand Down Expand Up @@ -131,6 +132,18 @@ def other_consumer_version_tags
.collect{ | tag | MatrixTag.new(tag.to_hash.merge(pacticipant_name: consumer_name, version_number: consumer_version_number)) }
end

def consumer_deployed_versions
@line.consumer_version.current_deployed_versions.collect do | deployed_version |
MatrixDeployedVersion.new(deployed_version)
end
end

def provider_deployed_versions
(@line.provider_version&.current_deployed_versions || []).collect do | deployed_version |
MatrixDeployedVersion.new(deployed_version)
end
end

def latest_provider_version_tags
@line.provider_version_tags
.select(&:latest)
Expand Down
6 changes: 6 additions & 0 deletions lib/pact_broker/ui/views/index/show-with-tags.haml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
- branch_class = index_item.latest_for_branch? ? "tag badge badge-dark" : "tag badge badge-secondary"
%div{"class": branch_class}
= "[" + index_item.consumer_version_branch + "]"
- index_item.consumer_version_environment_names.each do | environment_name |
.tag.badge.badge-danger
= environment_name
- index_item.consumer_version_latest_tag_names.each do | tag_name |
.tag.badge.badge-primary
= tag_name
Expand All @@ -72,6 +75,9 @@
- branch_class = "tag badge badge-dark"
%div{"class": branch_class}
= "[" + index_item.provider_version_branch + "]"
- index_item.provider_version_environment_names.each do | environment_name |
.tag.badge.badge-danger
= environment_name
- index_item.provider_version_latest_tag_names.each do | tag_name |
.tag.badge.badge-primary
= tag_name
Expand Down
10 changes: 10 additions & 0 deletions lib/pact_broker/ui/views/matrix/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@
- branch_class = line.consumer_version_latest_for_branch? ? "tag badge badge-dark" : "tag badge badge-secondary"
%div{"class": branch_class}
= "[" + line.consumer_version_branch + "]"
- line.consumer_deployed_versions.each do | deployed_version |
.tag-parent{"title": deployed_version.tooltip, "data-toggle": "tooltip", "data-placement": "right"}
%a{href: deployed_version.url}
.tag.badge.badge-danger
= deployed_version.environment_name
- line.latest_consumer_version_tags.each do | tag |
.tag-parent{"title": tag.tooltip, "data-toggle": "tooltip", "data-placement": "right"}
%a{href: tag.url}
Expand Down Expand Up @@ -164,6 +169,11 @@
- branch_class = line.provider_version_latest_for_branch? ? "tag badge badge-dark" : "tag badge badge-secondary"
%div{"class": branch_class}
= "[" + line.provider_version_branch + "]"
- line.provider_deployed_versions.each do | deployed_version |
.tag-parent{"title": deployed_version.tooltip, "data-toggle": "tooltip", "data-placement": "right"}
%a{href: deployed_version.url}
.tag.badge.badge-danger
= deployed_version.environment_name
- line.latest_provider_version_tags.each do | tag |
.tag-parent{"title": tag.tooltip, "data-toggle": "tooltip", "data-placement": "right"}
%a{href: tag.url}
Expand Down

0 comments on commit 20a5f42

Please sign in to comment.