Skip to content

Commit

Permalink
feat: sort consumer version tags by date in dashboard response
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Feb 1, 2021
1 parent 361a969 commit f82ba1b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
17 changes: 16 additions & 1 deletion db/ddl_statements/head_pact_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ def head_pact_tags_v1(connection)
Sequel[:lp][:consumer_id] => Sequel[:o][:consumer_id],
Sequel[:lp][:provider_id] => Sequel[:o][:provider_id],
Sequel[:cv][:order] => Sequel[:o][:latest_consumer_version_order]
}, { table_alias: :o})
}, { table_alias: :o })
.select(Sequel[:o][:tag_name].as(:name), Sequel[:lp][:pact_publication_id])
end

def head_pact_tags_v2(connection)
connection.from(Sequel.as(:latest_pact_publication_ids_for_consumer_versions, :lp))
.join(:versions,{ Sequel[:lp][:consumer_version_id] => Sequel[:cv][:id]}, { table_alias: :cv })
.join(:latest_tagged_pact_consumer_version_orders, {
Sequel[:lp][:consumer_id] => Sequel[:o][:consumer_id],
Sequel[:lp][:provider_id] => Sequel[:o][:provider_id],
Sequel[:cv][:order] => Sequel[:o][:latest_consumer_version_order]
}, { table_alias: :o } )
.join(:tags, {
Sequel[:tags][:version_id] => Sequel[:cv][:id],
Sequel[:tags][:name] => Sequel[:o][:tag_name]
})
.select(Sequel[:o][:tag_name].as(:name), Sequel[:lp][:pact_publication_id], Sequel[:tags][:created_at])
end
11 changes: 11 additions & 0 deletions db/migrations/20210202_add_created_at_to_head_pact_tags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require_relative '../ddl_statements'

Sequel.migration do
up do
create_or_replace_view(:head_pact_tags, head_pact_tags_v2(self))
end

down do
create_or_replace_view(:head_pact_tags, head_pact_tags_v1(self))
end
end
8 changes: 4 additions & 4 deletions lib/pact_broker/index/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def self.find_index_items options = {}
latest_verification,
webhook ? [webhook]: [],
pact_publication.integration.latest_triggered_webhooks,
consumer_version_tags(pact_publication, options[:tags]),
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?) : []
)
end.sort
Expand All @@ -98,9 +98,9 @@ def self.latest_verification_for_pseudo_branch(pact_publication, is_overall_late

def self.consumer_version_tags(pact_publication, tags_option)
if tags_option == true
pact_publication.head_pact_tags.collect(&:name)
pact_publication.head_pact_tags
elsif tags_option.is_a?(Array)
pact_publication.head_pact_tags.collect(&:name) & tags_option
pact_publication.head_pact_tags.select { |tag| tags_option.include?(tag.name) }
else
[]
end
Expand Down Expand Up @@ -133,7 +133,7 @@ def self.find_index_items_for_api(consumer_name: nil, provider_name: nil, **igno
pact_publication.latest_verification,
[],
[],
pact_publication.head_pact_tags.collect(&:name),
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?) : []
)
end.sort
Expand Down

0 comments on commit f82ba1b

Please sign in to comment.