Skip to content

Commit

Permalink
feat: sort tags on index and matrix pages and APIs by creation date
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Feb 1, 2021
1 parent f82ba1b commit 9159071
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/pact_broker/api/decorators/matrix_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def consumer_hash(line, consumer, consumer_version, base_url)
end

def tags(tags, base_url)
tags.collect do | tag |
tags.sort_by(&:created_at).collect do | tag |
{
name: tag.name,
latest: tag.latest?,
Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/index/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ 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?) : []
options[:tags] && latest_verification ? latest_verification.provider_version.tags_with_latest_flag.select(&:latest?).sort_by(&:created_at) : []
)
end.sort

Expand Down Expand Up @@ -134,7 +134,7 @@ def self.find_index_items_for_api(consumer_name: nil, provider_name: nil, **igno
[],
[],
pact_publication.head_pact_tags.sort_by(&:created_at).collect(&:name),
pact_publication.latest_verification ? pact_publication.latest_verification.provider_version.tags_with_latest_flag.select(&:latest?) : []
pact_publication.latest_verification ? pact_publication.latest_verification.provider_version.tags_with_latest_flag.select(&:latest?).sort_by(&:created_at) : []
)
end.sort
end
Expand Down
4 changes: 4 additions & 0 deletions lib/pact_broker/ui/view_models/matrix_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,28 @@ def provider_version_order
def latest_consumer_version_tags
@line.consumer_version_tags
.select(&:latest)
.sort_by(&:created_at)
.collect{ | tag | MatrixTag.new(tag.to_hash.merge(pacticipant_name: consumer_name, version_number: consumer_version_number)) }
end

def other_consumer_version_tags
@line.consumer_version_tags
.reject(&:latest)
.sort_by(&:created_at)
.collect{ | tag | MatrixTag.new(tag.to_hash.merge(pacticipant_name: consumer_name, version_number: consumer_version_number)) }
end

def latest_provider_version_tags
@line.provider_version_tags
.select(&:latest)
.sort_by(&:created_at)
.collect{ | tag | MatrixTag.new(tag.to_hash.merge(pacticipant_name: provider_name, version_number: provider_version_number)) }
end

def other_provider_version_tags
@line.provider_version_tags
.reject(&:latest)
.sort_by(&:created_at)
.collect{ | tag | MatrixTag.new(tag.to_hash.merge(pacticipant_name: provider_name, version_number: provider_version_number)) }
end

Expand Down
4 changes: 2 additions & 2 deletions spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ module Decorators

let(:consumer_version_tags) do
[
double("tag", name: "prod", latest?: true, version: consumer_version)
double("tag", name: "prod", latest?: true, version: consumer_version, created_at: DateTime.now )
]
end

let(:provider_version) { double("provider version", number: "4.5.6", pacticipant: double("provider", name: "Provider")) }

let(:provider_version_tags) do
[
double("tag", name: "master", latest?: false, version: provider_version)
double("tag", name: "master", latest?: false, version: provider_version, created_at: DateTime.now)
]
end

Expand Down

0 comments on commit 9159071

Please sign in to comment.