Skip to content

Commit

Permalink
feat: display version branch on index and matrix pages
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Feb 5, 2021
1 parent 5884a04 commit 2057df7
Show file tree
Hide file tree
Showing 20 changed files with 218 additions and 40 deletions.
6 changes: 5 additions & 1 deletion lib/pact_broker/api/decorators/dashboard_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def consumer_hash(index_item, consumer, consumer_version, base_url)
name: index_item.consumer_name,
version: {
number: index_item.consumer_version_number,
branch: index_item.consumer_version_branch,
_links: {
self: {
href: version_url(base_url, index_item.consumer_version)
Expand All @@ -84,7 +85,10 @@ def provider_hash(index_item, provider, base_url)
}

if index_item.latest_verification
hash[:version] = { number: index_item.provider_version_number }
hash[:version] = {
number: index_item.provider_version_number,
branch: index_item.provider_version_branch
}
end

hash
Expand Down
2 changes: 2 additions & 0 deletions lib/pact_broker/api/decorators/matrix_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def consumer_hash(line, consumer, consumer_version, base_url)
name: line.consumer_name,
version: {
number: line.consumer_version_number,
branch: line.consumer_version_branch,
_links: {
self: {
href: version_url(base_url, consumer_version)
Expand Down Expand Up @@ -118,6 +119,7 @@ def provider_hash(line, provider, provider_version, base_url)
if !line.provider_version_number.nil?
hash[:version] = {
number: line.provider_version_number,
branch: line.provider_version_branch,
_links: {
self: {
href: version_url(base_url, provider_version)
Expand Down
22 changes: 18 additions & 4 deletions lib/pact_broker/domain/index_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class IndexItem
:latest_verification_latest_tags

# rubocop:disable Metrics/ParameterLists
def self.create(consumer, provider, latest_pact, latest, latest_verification, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [])
new(consumer, provider, latest_pact, latest, latest_verification, webhooks, triggered_webhooks, tags, latest_verification_latest_tags)
def self.create(consumer, provider, latest_pact, latest, latest_verification, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [], latest_for_branch = nil)
new(consumer, provider, latest_pact, latest, latest_verification, webhooks, triggered_webhooks, tags, latest_verification_latest_tags, latest_for_branch)
end
# rubocop:enable Metrics/ParameterLists

# rubocop:disable Metrics/ParameterLists
def initialize(consumer, provider, latest_pact = nil, latest = true, latest_verification = nil, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [])
def initialize(consumer, provider, latest_pact = nil, latest = true, latest_verification = nil, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [], latest_for_branch = nil)
@consumer = consumer
@provider = provider
@latest_pact = latest_pact
Expand All @@ -29,6 +29,7 @@ def initialize(consumer, provider, latest_pact = nil, latest = true, latest_veri
@triggered_webhooks = triggered_webhooks
@tags = tags
@latest_verification_latest_tags = latest_verification_latest_tags
@latest_for_branch = latest_for_branch
end
# rubocop:enable Metrics/ParameterLists

Expand All @@ -37,7 +38,8 @@ def eq? other
other.latest_pact == latest_pact &&
other.latest? == latest? &&
other.latest_verification == latest_verification &&
other.webhooks == webhooks
other.webhooks == webhooks &&
other.latest_for_branch? == latest_for_branch?
end

def == other
Expand Down Expand Up @@ -68,6 +70,14 @@ def consumer_version
@latest_pact.consumer_version
end

def consumer_version_branch
consumer_version.branch
end

def latest_for_branch?
@latest_for_branch
end

def provider_version
@latest_verification ? @latest_verification.provider_version : nil
end
Expand All @@ -76,6 +86,10 @@ def provider_version_number
@latest_verification ? @latest_verification.provider_version_number : nil
end

def provider_version_branch
provider_version&.branch
end

# these are the consumer tag names for which this pact publication
# is the latest with that tag
def tag_names
Expand Down
6 changes: 6 additions & 0 deletions lib/pact_broker/domain/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ def version_and_updated_date
def latest_pact_publication
pact_publications.last
end

def latest_for_branch?
return nil unless branch
self_order = self.order
Version.where(branch: branch, pacticipant_id: pacticipant_id).where { order > self_order }.empty?
end
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/pact_broker/index/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def self.find_index_items options = {}
webhook ? [webhook]: [],
pact_publication.integration.latest_triggered_webhooks,
consumer_version_tags(pact_publication, options[:tags]).sort_by(&:created_at).collect(&:name),
options[:tags] && latest_verification ? latest_verification.provider_version.tags_with_latest_flag.select(&:latest?).sort_by(&:created_at) : []
options[:tags] && latest_verification ? latest_verification.provider_version.tags_with_latest_flag.select(&:latest?).sort_by(&:created_at) : [],
pact_publication.latest_for_branch?
)
end.sort

Expand Down
8 changes: 8 additions & 0 deletions lib/pact_broker/matrix/quick_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ def consumer_version_number
consumer_version.number
end

def consumer_version_branch
consumer_version.branch
end

def consumer_version_order
consumer_version.order
end
Expand All @@ -363,6 +367,10 @@ def provider_version_number
provider_version&.number
end

def provider_version_branch
provider_version&.branch
end

def provider_version_order
provider_version&.order
end
Expand Down
17 changes: 15 additions & 2 deletions lib/pact_broker/pacts/pact_publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ def latest_verification
pact_version.latest_verification
end

def latest_for_branch?
return nil unless consumer_version.branch
self_order = self.consumer_version.order
versions_join = {
Sequel[:pact_publications][:consumer_version_id] => Sequel[:cv][:id]
}
PactPublication.where(consumer_id: consumer_id, provider_id: provider_id)
.join_consumer_versions(:cv, { Sequel[:cv][:branch] => consumer_version.branch} ) do
Sequel[:cv][:order] > self_order
end
.empty?
end

def to_domain
PactBroker::Domain::Pact.new(
id: id,
Expand Down Expand Up @@ -83,11 +96,11 @@ def to_domain_lightweight
end

def to_version_domain
OpenStruct.new(number: consumer_version.number, pacticipant: consumer, tags: consumer_version.tags, order: consumer_version.order)
OpenStruct.new(number: consumer_version.number, pacticipant: consumer, tags: consumer_version.tags, order: consumer_version.order, branch: consumer_version.branch)
end

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

private
Expand Down
7 changes: 5 additions & 2 deletions lib/pact_broker/pacts/pact_publication_dataset_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,11 @@ def remove_overridden_revisions
join(:latest_pact_publication_ids_for_consumer_versions, { Sequel[:lp][:pact_publication_id] => Sequel[:pact_publications][:id] }, { table_alias: :lp})
end

def join_consumer_versions(table_alias = :cv)
join(:versions, { Sequel[:pact_publications][:consumer_version_id] => Sequel[table_alias][:id] }, { table_alias: table_alias })
def join_consumer_versions(table_alias = :cv, extra_join_criteria = {}, &block)
versions_join = {
Sequel[:pact_publications][:consumer_version_id] => Sequel[table_alias][:id]
}.merge(extra_join_criteria)
join(:versions, versions_join, { table_alias: table_alias }, &block)
end

def join_consumer_version_tags(table_alias = :ct)
Expand Down
4 changes: 4 additions & 0 deletions lib/pact_broker/test/test_data_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ def find_pacticipant(name)
PactBroker::Domain::Pacticipant.where(name: name).single_record
end

def find_version(pacticipant_name, version_number)
PactBroker::Domain::Version.for(pacticipant_name, version_number)
end

def model_counter
@@model_counter ||= 0
@@model_counter += 1
Expand Down
9 changes: 9 additions & 0 deletions lib/pact_broker/ui/view_models/index_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
require 'pact_broker/date_helper'
require 'pact_broker/versions/abbreviate_number'
require 'pact_broker/configuration'
require 'forwardable'

module PactBroker
module UI
module ViewDomain
class IndexItem
extend Forwardable

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


include PactBroker::Api::PactBrokerUrls

Expand Down Expand Up @@ -186,6 +191,10 @@ def short_version_number version_number
def base_url
@options[:base_url]
end

private

attr_reader :relationship
end
end
end
Expand Down
32 changes: 32 additions & 0 deletions lib/pact_broker/ui/view_models/matrix_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
require 'pact_broker/ui/view_models/matrix_tag'
require 'pact_broker/versions/abbreviate_number'
require 'pact_broker/messages'
require 'forwardable'

module PactBroker
module UI
module ViewDomain
class MatrixLine
include PactBroker::Api::PactBrokerUrls
include PactBroker::Messages
extend Forwardable

delegate [:consumer_version_branch, :provider_version_branch] => :line

def initialize line, options = {}
@line = line
Expand Down Expand Up @@ -97,6 +101,22 @@ def provider_version_order
end
end

def consumer_version_branch_tooltip
branch_tooltip(consumer_name, consumer_version_branch, consumer_version_latest_for_branch?)
end

def consumer_version_latest_for_branch?
@line.consumer_version.latest_for_branch?
end

def provider_version_branch_tooltip
branch_tooltip(provider_name, provider_version_branch, provider_version_latest_for_branch?)
end

def provider_version_latest_for_branch?
@line.provider_version.latest_for_branch?
end

def latest_consumer_version_tags
@line.consumer_version_tags
.select(&:latest)
Expand Down Expand Up @@ -191,6 +211,18 @@ def pre_verified_message
def base_url
@options[:base_url]
end

private

attr_reader :line

def branch_tooltip(pacticipant_name, branch, latest)
if latest
"This is the latest version of #{pacticipant_name} from branch \"#{branch}\"."
else
"A more recent version of #{pacticipant_name} from branch \"#{branch}\" exists."
end
end
end
end
end
Expand Down
8 changes: 8 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 @@ -47,6 +47,10 @@
- if index_item.latest?
.tag.badge.badge-success
latest
- if index_item.consumer_version_branch
- 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_latest_tag_names.each do | tag_name |
.tag.badge.badge-primary
= tag_name
Expand All @@ -64,6 +68,10 @@
- if index_item.provider_version_number
%button.clippy.invisible{ title: "Copy to clipboard" }
%span.copy-icon
- if index_item.provider_version_branch
- branch_class = "tag badge badge-dark"
%div{"class": branch_class}
= "[" + index_item.provider_version_branch + "]"
- 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 @@ -118,6 +118,11 @@
- if line.display_consumer_version_number
%button.clippy.invisible{ title: "Copy to clipboard" }
%span.copy-icon
- if line.consumer_version_branch
.tag-parent{"title": line.consumer_version_branch_tooltip, "data-toggle": "tooltip", "data-placement": "right"}
- 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.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 @@ -145,6 +150,11 @@
- if line.display_provider_version_number
%button.clippy.invisible{ title: "Copy to clipboard" }
%span.copy-icon
- if line.provider_version_branch
.tag-parent{"title": line.provider_version_branch_tooltip, "data-toggle": "tooltip", "data-placement": "right"}
- 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.latest_provider_version_tags.each do | tag |
.tag-parent{"title": tag.tooltip, "data-toggle": "tooltip", "data-placement": "right"}
%a{href: tag.url}
Expand Down
23 changes: 22 additions & 1 deletion public/stylesheets/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,25 @@ span.warning-icon {
padding-bottom: 9px;
margin: 40px 0 20px;
border-bottom: 1px solid #eee;
}
}

span.copy-icon {
background-image: url('/images/copy.svg');
background-size: 16px 16px;
background-repeat: no-repeat;
display:block;
position: relative;
width: 16px;
height: 16px;
cursor: pointer;
}

span.copy-success-icon {
background-image: url('/images/check.svg');
background-size: 16px 16px;
background-repeat: no-repeat;
display:block;
position: relative;
width: 16px;
height: 16px;
}
21 changes: 0 additions & 21 deletions public/stylesheets/matrix.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,3 @@ img.pact_badge {
display: flex;
justify-content: flex-start;
}

span.copy-icon {
background-image: url('/images/copy.svg');
background-size: 16px 16px;
background-repeat: no-repeat;
display:block;
position: relative;
width: 16px;
height: 16px;
cursor: pointer;
}

span.copy-success-icon {
background-image: url('/images/check.svg');
background-size: 16px 16px;
background-repeat: no-repeat;
display:block;
position: relative;
width: 16px;
height: 16px;
}
Loading

0 comments on commit 2057df7

Please sign in to comment.