diff --git a/lib/pact_broker/domain/index_item.rb b/lib/pact_broker/domain/index_item.rb index 77f35a029..d50b6e774 100644 --- a/lib/pact_broker/domain/index_item.rb +++ b/lib/pact_broker/domain/index_item.rb @@ -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 @@ -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 diff --git a/lib/pact_broker/domain/version.rb b/lib/pact_broker/domain/version.rb index 0d9b71de7..579cacdba 100644 --- a/lib/pact_broker/domain/version.rb +++ b/lib/pact_broker/domain/version.rb @@ -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 diff --git a/lib/pact_broker/index/service.rb b/lib/pact_broker/index/service.rb index 9883be0e4..84c64f9fd 100644 --- a/lib/pact_broker/index/service.rb +++ b/lib/pact_broker/index/service.rb @@ -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 | @@ -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 | @@ -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 diff --git a/lib/pact_broker/matrix/quick_row.rb b/lib/pact_broker/matrix/quick_row.rb index 2910f4e75..d52ae7416 100644 --- a/lib/pact_broker/matrix/quick_row.rb +++ b/lib/pact_broker/matrix/quick_row.rb @@ -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) diff --git a/lib/pact_broker/pacts/pact_publication.rb b/lib/pact_broker/pacts/pact_publication.rb index d4cc6c162..552c89bd2 100644 --- a/lib/pact_broker/pacts/pact_publication.rb +++ b/lib/pact_broker/pacts/pact_publication.rb @@ -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 diff --git a/lib/pact_broker/ui/view_models/index_item.rb b/lib/pact_broker/ui/view_models/index_item.rb index 35da6c731..75ddea8ac 100644 --- a/lib/pact_broker/ui/view_models/index_item.rb +++ b/lib/pact_broker/ui/view_models/index_item.rb @@ -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 diff --git a/lib/pact_broker/ui/view_models/matrix_deployed_version.rb b/lib/pact_broker/ui/view_models/matrix_deployed_version.rb new file mode 100644 index 000000000..e7b6ebd55 --- /dev/null +++ b/lib/pact_broker/ui/view_models/matrix_deployed_version.rb @@ -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 diff --git a/lib/pact_broker/ui/view_models/matrix_line.rb b/lib/pact_broker/ui/view_models/matrix_line.rb index 18048618f..fcb9f36e4 100644 --- a/lib/pact_broker/ui/view_models/matrix_line.rb +++ b/lib/pact_broker/ui/view_models/matrix_line.rb @@ -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' @@ -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) diff --git a/lib/pact_broker/ui/views/index/show-with-tags.haml b/lib/pact_broker/ui/views/index/show-with-tags.haml index 8be708681..575ad3014 100644 --- a/lib/pact_broker/ui/views/index/show-with-tags.haml +++ b/lib/pact_broker/ui/views/index/show-with-tags.haml @@ -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 @@ -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 diff --git a/lib/pact_broker/ui/views/matrix/show.haml b/lib/pact_broker/ui/views/matrix/show.haml index 47b745d0f..006dd926e 100644 --- a/lib/pact_broker/ui/views/matrix/show.haml +++ b/lib/pact_broker/ui/views/matrix/show.haml @@ -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} @@ -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}