pact_broker 2.51.0 → 2.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/db/migrations/20200318_add_created_at_to_latest_pact_publications.rb +9 -0
- data/db/migrations/20200319_add_created_at_to_latest_verifications.rb +9 -0
- data/lib/pact_broker/api/contracts/dry_validation_predicates.rb +4 -0
- data/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema.rb +26 -1
- data/lib/pact_broker/api/contracts/verifiable_pacts_query_schema.rb +2 -0
- data/lib/pact_broker/api/decorators/matrix_text_decorator.rb +1 -1
- data/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator.rb +1 -0
- data/lib/pact_broker/api/pact_broker_urls.rb +11 -0
- data/lib/pact_broker/api/renderers/html_pact_renderer.rb +1 -1
- data/lib/pact_broker/db/data_migrations/set_created_at_for_latest_pact_publications.rb +25 -0
- data/lib/pact_broker/db/data_migrations/set_created_at_for_latest_verifications.rb +24 -0
- data/lib/pact_broker/db/migrate_data.rb +2 -0
- data/lib/pact_broker/matrix/every_row.rb +11 -5
- data/lib/pact_broker/matrix/parse_query.rb +6 -0
- data/lib/pact_broker/matrix/query_builder.rb +28 -16
- data/lib/pact_broker/matrix/query_results_with_deployment_status_summary.rb +15 -4
- data/lib/pact_broker/matrix/quick_row.rb +49 -65
- data/lib/pact_broker/matrix/repository.rb +2 -12
- data/lib/pact_broker/matrix/resolved_selector.rb +1 -1
- data/lib/pact_broker/matrix/service.rb +1 -1
- data/lib/pact_broker/pacts/pact_publication.rb +8 -0
- data/lib/pact_broker/pacts/repository.rb +10 -11
- data/lib/pact_broker/pacts/selector.rb +21 -0
- data/lib/pact_broker/pacts/verifiable_pact_messages.rb +5 -1
- data/lib/pact_broker/test/test_data_builder.rb +6 -0
- data/lib/pact_broker/ui/view_models/matrix_line.rb +8 -0
- data/lib/pact_broker/ui/views/matrix/show.haml +4 -4
- data/lib/pact_broker/verifications/repository.rb +2 -1
- data/lib/pact_broker/version.rb +1 -1
- data/lib/rack/pact_broker/request_target.rb +1 -1
- data/pact_broker.gemspec +1 -1
- data/public/javascripts/matrix.js +20 -8
- data/script/docker/db-restore.sh +1 -1
- data/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_spec.rb +43 -2
- data/spec/lib/pact_broker/api/contracts/verifiable_pacts_query_schema_spec.rb +13 -0
- data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +11 -2
- data/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +2 -1
- data/spec/lib/pact_broker/matrix/every_row_spec.rb +0 -10
- data/spec/lib/pact_broker/matrix/quick_row_spec.rb +11 -11
- data/spec/lib/pact_broker/matrix/repository_dependency_spec.rb +1 -1
- data/spec/lib/pact_broker/matrix/repository_spec.rb +9 -9
- data/spec/lib/pact_broker/pacts/repository_find_for_verification_spec.rb +43 -1
- data/spec/lib/pact_broker/pacts/repository_spec.rb +9 -0
- data/spec/lib/pact_broker/pacts/selector_spec.rb +5 -2
- data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +6 -0
- data/spec/lib/pact_broker/verifications/repository_spec.rb +21 -0
- metadata +10 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ac697acb622b83117ef653787076248bc6fc112a610b8534384483ee7bbec90
|
4
|
+
data.tar.gz: '09def84c04412f624739e75e5762452a5f16f8d01837b00b7728bc287c659a91'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e7b3b8000991f4b4989ec1674d75c2b512605c8a7cc066ab101e8644163bfd2bba4a3a9d102e455e59c14649fbc250080b5d1498a46ac303663fbfc778b19c9
|
7
|
+
data.tar.gz: a5d00393a9237d10a27ea28b4cb4896b452957185db1ecee8a7ac6b0ef91c99dcf899024fa5ecd7949ee0fafab0128afd63a9e2f8146dbeabb22f6f01f4934c6
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
<a name="v2.52.0"></a>
|
2
|
+
### v2.52.0 (2020-03-25)
|
3
|
+
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* **pact ui**
|
8
|
+
* update matrix URL to specify the latest provider version ([23b02c80](/../../commit/23b02c80))
|
9
|
+
|
10
|
+
* **matrix ui**
|
11
|
+
* highlight rows with the same consumer/provider/consumer version/provider version ([99b36d50](/../../commit/99b36d50))
|
12
|
+
|
13
|
+
* **matrix**
|
14
|
+
* speed up query for UI by reducing the number of joins and removing unncessary criteria (#332) ([9e5ea8be](/../../commit/9e5ea8be))
|
15
|
+
|
16
|
+
* **pacts for verification**
|
17
|
+
* add validation to only allow consumer to be specified for 'all' versions for a tag ([b39ad193](/../../commit/b39ad193))
|
18
|
+
* update inclusion messages to specify consumer name when selecting all pacts for a given consumer ([fdff0c58](/../../commit/fdff0c58))
|
19
|
+
* support finding all pacts with a given tag for a specified consumer ([749e708d](/../../commit/749e708d))
|
20
|
+
|
21
|
+
|
22
|
+
#### Bug Fixes
|
23
|
+
|
24
|
+
* ensure requests for text/plain go to the API rather than the UI ([1cf28009](/../../commit/1cf28009))
|
25
|
+
|
26
|
+
|
1
27
|
<a name="v2.51.0"></a>
|
2
28
|
### v2.51.0 (2020-03-11)
|
3
29
|
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
change do
|
3
|
+
# TODO
|
4
|
+
# alter_table(:latest_verification_id_for_pact_version_and_provider_version) do
|
5
|
+
# set_column_not_null(:created_at)
|
6
|
+
# end
|
7
|
+
add_column(:latest_verification_id_for_pact_version_and_provider_version, :created_at, DateTime)
|
8
|
+
end
|
9
|
+
end
|
@@ -13,6 +13,7 @@ module PactBroker
|
|
13
13
|
SCHEMA = Dry::Validation.Schema do
|
14
14
|
configure do
|
15
15
|
predicates(DryValidationPredicates)
|
16
|
+
config.messages_file = File.expand_path("../../../locale/en.yml", __FILE__)
|
16
17
|
end
|
17
18
|
optional(:providerVersionTags).maybe(:array?)
|
18
19
|
optional(:consumerVersionSelectors).each do
|
@@ -26,6 +27,7 @@ module PactBroker
|
|
26
27
|
required(:tag).filled(:str?)
|
27
28
|
optional(:latest).filled(included_in?: [true, false])
|
28
29
|
optional(:fallbackTag).filled(:str?)
|
30
|
+
optional(:consumer).filled(:str?, :not_blank?)
|
29
31
|
|
30
32
|
# rule(fallbackTagMustBeForLatest: [:fallbackTag, :latest]) do | fallback_tag, latest |
|
31
33
|
# fallback_tag.filled?.then(latest.eql?(true))
|
@@ -37,7 +39,30 @@ module PactBroker
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def self.call(params)
|
40
|
-
|
42
|
+
symbolized_params = params&.symbolize_keys
|
43
|
+
results = select_first_message(flatten_indexed_messages(SCHEMA.call(symbolized_params).messages(full: true)))
|
44
|
+
add_cross_field_validation_errors(symbolized_params, results)
|
45
|
+
results
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.add_cross_field_validation_errors(params, results)
|
49
|
+
# This is a ducking joke. Need to get rid of dry-validation
|
50
|
+
if params[:consumerVersionSelectors].is_a?(Array)
|
51
|
+
errors = []
|
52
|
+
params[:consumerVersionSelectors].each_with_index do | selector, index |
|
53
|
+
if selector[:fallbackTag] && !selector[:latest]
|
54
|
+
errors << "fallbackTag can only be set if latest is true (at index #{index})"
|
55
|
+
end
|
56
|
+
|
57
|
+
if selector[:consumer] && selector[:latest]
|
58
|
+
errors << "specifying a consumer with latest == true is not yet supported (at index #{index})"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
if errors.any?
|
62
|
+
results[:consumerVersionSelectors] ||= []
|
63
|
+
results[:consumerVersionSelectors].concat(errors)
|
64
|
+
end
|
65
|
+
end
|
41
66
|
end
|
42
67
|
end
|
43
68
|
end
|
@@ -12,6 +12,7 @@ module PactBroker
|
|
12
12
|
SCHEMA = Dry::Validation.Schema do
|
13
13
|
configure do
|
14
14
|
predicates(DryValidationPredicates)
|
15
|
+
config.messages_file = File.expand_path("../../../locale/en.yml", __FILE__)
|
15
16
|
end
|
16
17
|
optional(:provider_version_tags).maybe(:array?)
|
17
18
|
optional(:consumer_version_selectors).each do
|
@@ -19,6 +20,7 @@ module PactBroker
|
|
19
20
|
required(:tag).filled(:str?)
|
20
21
|
optional(:latest).filled(included_in?: ["true", "false"])
|
21
22
|
optional(:fallback_tag).filled(:str?)
|
23
|
+
optional(:consumer).filled(:str?, :not_blank?)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
optional(:include_pending_status).filled(included_in?: ["true", "false"])
|
@@ -17,7 +17,7 @@ module PactBroker
|
|
17
17
|
def to_text(options)
|
18
18
|
json_decorator = PactBroker::Api::Decorators::MatrixDecorator.new(lines)
|
19
19
|
data = lines.collect do | line |
|
20
|
-
Line.new(line
|
20
|
+
Line.new(line.consumer_name, line.consumer_version_number, line.pact_revision_number, line.provider_name, line.provider_version_number, line.verification_number, line.success)
|
21
21
|
end
|
22
22
|
printer = TablePrint::Printer.new(data)
|
23
23
|
printer.table_print + "\n\nDeployable: #{json_decorator.deployable.inspect}\nReason: #{json_decorator.reason}\n"
|
@@ -261,6 +261,17 @@ module PactBroker
|
|
261
261
|
"#{base_url}/matrix?#{Rack::Utils.build_nested_query(query)}"
|
262
262
|
end
|
263
263
|
|
264
|
+
def matrix_for_pact_url(pact, base_url = '')
|
265
|
+
query = {
|
266
|
+
q: [
|
267
|
+
{ pacticipant: pact.consumer_name, version: pact.consumer_version_number },
|
268
|
+
{ pacticipant: pact.provider_name, latest: true }
|
269
|
+
],
|
270
|
+
latestby: 'cvpv'
|
271
|
+
}
|
272
|
+
"#{base_url}/matrix?#{Rack::Utils.build_nested_query(query)}"
|
273
|
+
end
|
274
|
+
|
264
275
|
def matrix_url_from_params params, base_url = ''
|
265
276
|
matrix_url(params.fetch(:consumer_name), params.fetch(:provider_name), base_url)
|
266
277
|
end
|
@@ -137,7 +137,7 @@ module PactBroker
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def matrix_url
|
140
|
-
PactBroker::Api::PactBrokerUrls.
|
140
|
+
PactBroker::Api::PactBrokerUrls.matrix_for_pact_url(@pact, base_url)
|
141
141
|
end
|
142
142
|
|
143
143
|
def latest_pact_url
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'pact_broker/db/data_migrations/helpers'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module DB
|
5
|
+
module DataMigrations
|
6
|
+
class SetCreatedAtForLatestPactPublications
|
7
|
+
def self.call connection
|
8
|
+
# pact ordering goes by creation date of the consumer version
|
9
|
+
connection[:latest_pact_publication_ids_for_consumer_versions]
|
10
|
+
query = "UPDATE latest_pact_publication_ids_for_consumer_versions
|
11
|
+
SET created_at = (SELECT created_at
|
12
|
+
FROM versions
|
13
|
+
WHERE id = latest_pact_publication_ids_for_consumer_versions.consumer_version_id)
|
14
|
+
WHERE created_at IS NULL"
|
15
|
+
connection.run(query)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.columns_exist?(connection)
|
19
|
+
column_exists?(connection, :latest_pact_publication_ids_for_consumer_versions, :created_at) &&
|
20
|
+
column_exists?(connection, :pact_publications, :created_at)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'pact_broker/db/data_migrations/helpers'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module DB
|
5
|
+
module DataMigrations
|
6
|
+
class SetCreatedAtForLatestVerifications
|
7
|
+
def self.call connection
|
8
|
+
connection[:latest_verification_id_for_pact_version_and_provider_version]
|
9
|
+
query = "UPDATE latest_verification_id_for_pact_version_and_provider_version
|
10
|
+
SET created_at = (SELECT created_at
|
11
|
+
FROM verifications
|
12
|
+
WHERE id = latest_verification_id_for_pact_version_and_provider_version.verification_id)
|
13
|
+
WHERE created_at is null"
|
14
|
+
connection.run(query)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.columns_exist?(connection)
|
18
|
+
column_exists?(connection, :latest_verification_id_for_pact_version_and_provider_version, :created_at) &&
|
19
|
+
column_exists?(connection, :verifications, :created_at)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -19,6 +19,8 @@ module PactBroker
|
|
19
19
|
DataMigrations::SetLatestVersionSequenceValue.call(database_connection)
|
20
20
|
DataMigrations::SetWebhooksEnabled.call(database_connection)
|
21
21
|
DataMigrations::DeleteDeprecatedWebhookExecutions.call(database_connection)
|
22
|
+
DataMigrations::SetCreatedAtForLatestPactPublications.call(database_connection)
|
23
|
+
DataMigrations::SetCreatedAtForLatestVerifications.call(database_connection)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -8,16 +8,22 @@ module PactBroker
|
|
8
8
|
P_V_JOIN = { Sequel[:p][:pact_version_id] => Sequel[:v][:pact_version_id] }
|
9
9
|
|
10
10
|
PACT_COLUMNS = [
|
11
|
+
Sequel[:p][:consumer_id],
|
12
|
+
Sequel[:p][:provider_id],
|
13
|
+
Sequel[:p][:consumer_version_id],
|
11
14
|
Sequel[:p][:id].as(:pact_publication_id),
|
12
15
|
Sequel[:p][:pact_version_id],
|
13
|
-
Sequel[:p][:revision_number].as(:pact_revision_number)
|
16
|
+
Sequel[:p][:revision_number].as(:pact_revision_number),
|
17
|
+
Sequel[:p][:created_at].as(:consumer_version_created_at),
|
18
|
+
Sequel[:p][:id].as(:pact_order)
|
14
19
|
]
|
15
20
|
VERIFICATION_COLUMNS = [
|
16
|
-
Sequel[:v][:id].as(:verification_id)
|
21
|
+
Sequel[:v][:id].as(:verification_id),
|
22
|
+
Sequel[:v][:provider_version_id],
|
23
|
+
Sequel[:v][:created_at].as(:provider_version_created_at)
|
17
24
|
]
|
18
25
|
|
19
|
-
ALL_COLUMNS =
|
20
|
-
PROVIDER_COLUMNS + PROVIDER_VERSION_COLUMNS + VERIFICATION_COLUMNS
|
26
|
+
ALL_COLUMNS = PACT_COLUMNS + VERIFICATION_COLUMNS
|
21
27
|
|
22
28
|
SELECT_ALL_COLUMN_ARGS = [:select_all_columns] + ALL_COLUMNS
|
23
29
|
dataset_module do
|
@@ -29,7 +35,7 @@ module PactBroker
|
|
29
35
|
|
30
36
|
def verifications_for(query_ids)
|
31
37
|
db[:verifications]
|
32
|
-
.select(:id, :pact_version_id, :provider_id, :provider_version_id)
|
38
|
+
.select(:id, :pact_version_id, :provider_id, :provider_version_id, :created_at)
|
33
39
|
.where {
|
34
40
|
Sequel.&(
|
35
41
|
QueryBuilder.consumer_in_pacticipant_ids(query_ids),
|
@@ -26,11 +26,17 @@ module PactBroker
|
|
26
26
|
if params.key?('latestby') && params['latestby'] != ''
|
27
27
|
options[:latestby] = params['latestby']
|
28
28
|
end
|
29
|
+
|
30
|
+
if params.key?('days') && params['days'] != ''
|
31
|
+
options[:days] = params['days'].to_i
|
32
|
+
end
|
33
|
+
|
29
34
|
if params.key?('limit') && params['limit'] != ''
|
30
35
|
options[:limit] = params['limit']
|
31
36
|
else
|
32
37
|
options[:limit] = "100"
|
33
38
|
end
|
39
|
+
|
34
40
|
if params.key?('latest') && params['latest'] != ''
|
35
41
|
options[:latest] = params['latest'] == 'true'
|
36
42
|
end
|
@@ -1,24 +1,36 @@
|
|
1
1
|
module PactBroker
|
2
2
|
module Matrix
|
3
3
|
class QueryBuilder
|
4
|
-
def self.provider_or_provider_version_matches(query_ids,
|
5
|
-
Sequel.|(*provider_or_provider_version_criteria(query_ids,
|
4
|
+
def self.provider_or_provider_version_matches(query_ids, provider_version_qualifier = nil, provider_qualifier = nil)
|
5
|
+
Sequel.|(*provider_or_provider_version_criteria(query_ids, provider_version_qualifier, provider_qualifier))
|
6
6
|
end
|
7
7
|
|
8
|
-
def self.
|
9
|
-
|
10
|
-
|
11
|
-
ors << {
|
12
|
-
qualify(:p, :provider_id) => query_ids.all_pacticipant_ids,
|
13
|
-
qualify(qualifier, :provider_version_id) => nil
|
8
|
+
def self.provider_matches(query_ids, qualifier)
|
9
|
+
{
|
10
|
+
qualify(qualifier, :provider_id) => query_ids.pacticipant_ids,
|
14
11
|
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.provider_or_provider_version_matches_or_pact_unverified(query_ids, provider_version_qualifier = nil, provider_qualifier = nil)
|
15
|
+
ors = provider_or_provider_version_criteria(query_ids, provider_version_qualifier, provider_qualifier)
|
16
|
+
|
17
|
+
# If we have specified any versions, then we need to add an
|
18
|
+
# "OR (provider matches these IDs and provider version is null)"
|
19
|
+
# so that we get a line with blank verification details.
|
20
|
+
if query_ids.pacticipant_version_ids.any?
|
21
|
+
ors << {
|
22
|
+
qualify(provider_qualifier, :provider_id) => query_ids.all_pacticipant_ids,
|
23
|
+
qualify(provider_version_qualifier, :provider_version_id) => nil
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
15
27
|
Sequel.|(*ors)
|
16
28
|
end
|
17
29
|
|
18
|
-
def self.provider_or_provider_version_criteria(query_ids,
|
30
|
+
def self.provider_or_provider_version_criteria(query_ids, provider_version_qualifier = nil, provider_qualifier = nil)
|
19
31
|
ors = []
|
20
|
-
ors << { qualify(
|
21
|
-
ors << { qualify(
|
32
|
+
ors << { qualify(provider_version_qualifier, :provider_version_id) => query_ids.pacticipant_version_ids } if query_ids.pacticipant_version_ids.any?
|
33
|
+
ors << { qualify(provider_qualifier, :provider_id) => query_ids.pacticipant_ids } if query_ids.pacticipant_ids.any?
|
22
34
|
ors
|
23
35
|
end
|
24
36
|
|
@@ -50,16 +62,16 @@ module PactBroker
|
|
50
62
|
end
|
51
63
|
|
52
64
|
# QueryIds is built from a single selector, so there is only one pacticipant_id or pacticipant_version_id
|
53
|
-
def self.consumer_or_consumer_version_or_provider_or_provider_or_provider_version_match(query_ids)
|
65
|
+
def self.consumer_or_consumer_version_or_provider_or_provider_or_provider_version_match(query_ids, pacts_qualifier = :p, verifications_qualifier = :v)
|
54
66
|
ors = if query_ids.pacticipant_version_id
|
55
67
|
[
|
56
|
-
{ Sequel[
|
57
|
-
{ Sequel[
|
68
|
+
{ Sequel[pacts_qualifier][:consumer_version_id] => query_ids.pacticipant_version_id },
|
69
|
+
{ Sequel[verifications_qualifier][:provider_version_id] => query_ids.pacticipant_version_id }
|
58
70
|
]
|
59
71
|
else
|
60
72
|
[
|
61
|
-
{ Sequel[
|
62
|
-
{ Sequel[
|
73
|
+
{ Sequel[pacts_qualifier][:consumer_id] => query_ids.pacticipant_id },
|
74
|
+
{ Sequel[pacts_qualifier][:provider_id] => query_ids.pacticipant_id }
|
63
75
|
]
|
64
76
|
end
|
65
77
|
|
@@ -2,13 +2,24 @@ require 'pact_broker/matrix/query_results'
|
|
2
2
|
|
3
3
|
module PactBroker
|
4
4
|
module Matrix
|
5
|
-
class QueryResultsWithDeploymentStatusSummary
|
6
|
-
|
5
|
+
class QueryResultsWithDeploymentStatusSummary
|
6
|
+
extend Forwardable
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
attr_reader :query_results, :deployment_status_summary
|
9
|
+
|
10
|
+
delegate [:selectors, :options, :resolved_selectors, :integrations] => :query_results
|
11
|
+
delegate (Array.instance_methods - Object.instance_methods) => :rows
|
12
|
+
delegate [:deployable?] => :deployment_status_summary
|
13
|
+
|
14
|
+
|
15
|
+
def initialize query_results, deployment_status_summary
|
16
|
+
@query_results = query_results
|
10
17
|
@deployment_status_summary = deployment_status_summary
|
11
18
|
end
|
19
|
+
|
20
|
+
def rows
|
21
|
+
query_results.rows
|
22
|
+
end
|
12
23
|
end
|
13
24
|
end
|
14
25
|
end
|
@@ -31,39 +31,23 @@ module PactBroker
|
|
31
31
|
CONSUMER_VERSION_JOIN = { Sequel[:p][:consumer_version_id] => Sequel[:cv][:id] }
|
32
32
|
PROVIDER_VERSION_JOIN = { Sequel[:v][:provider_version_id] => Sequel[:pv][:id] }
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
# Columns
|
37
|
-
CONSUMER_COLUMNS = [
|
34
|
+
PACT_COLUMNS = [
|
38
35
|
Sequel[:p][:consumer_id],
|
39
|
-
Sequel[:consumers][:name].as(:consumer_name)
|
40
|
-
]
|
41
|
-
PROVIDER_COLUMNS = [
|
42
36
|
Sequel[:p][:provider_id],
|
43
|
-
Sequel[:providers][:name].as(:provider_name)
|
44
|
-
]
|
45
|
-
CONSUMER_VERSION_COLUMNS = [
|
46
37
|
Sequel[:p][:consumer_version_id],
|
47
|
-
Sequel[:cv][:number].as(:consumer_version_number),
|
48
|
-
Sequel[:cv][:order].as(:consumer_version_order)
|
49
|
-
]
|
50
|
-
PROVIDER_VERSION_COLUMNS = [
|
51
|
-
Sequel[:v][:provider_version_id],
|
52
|
-
Sequel[:pv][:number].as(:provider_version_number),
|
53
|
-
Sequel[:pv][:order].as(:provider_version_order)
|
54
|
-
]
|
55
|
-
PACT_COLUMNS = [
|
56
38
|
Sequel[:p][:pact_publication_id],
|
57
|
-
Sequel[:p][:pact_version_id]
|
39
|
+
Sequel[:p][:pact_version_id],
|
40
|
+
Sequel[:p][:created_at].as(:consumer_version_created_at),
|
41
|
+
Sequel[:p][:pact_publication_id].as(:pact_order)
|
58
42
|
]
|
59
43
|
VERIFICATION_COLUMNS = [
|
60
|
-
Sequel[:v][:
|
44
|
+
Sequel[:v][:provider_version_id],
|
45
|
+
Sequel[:v][:verification_id],
|
46
|
+
Sequel[:v][:created_at].as(:provider_version_created_at)
|
61
47
|
]
|
62
|
-
LAST_ACTION_DATE = Sequel.lit("CASE WHEN (
|
63
|
-
|
64
|
-
ALL_COLUMNS = [LAST_ACTION_DATE] + CONSUMER_COLUMNS + CONSUMER_VERSION_COLUMNS + PACT_COLUMNS +
|
65
|
-
PROVIDER_COLUMNS + PROVIDER_VERSION_COLUMNS + VERIFICATION_COLUMNS
|
48
|
+
LAST_ACTION_DATE = Sequel.lit("CASE WHEN (provider_version_created_at IS NOT NULL AND provider_version_created_at > consumer_version_created_at) THEN provider_version_created_at ELSE consumer_version_created_at END").as(:last_action_date)
|
66
49
|
|
50
|
+
ALL_COLUMNS = PACT_COLUMNS + VERIFICATION_COLUMNS
|
67
51
|
|
68
52
|
|
69
53
|
# cachable select arguments
|
@@ -90,14 +74,15 @@ module PactBroker
|
|
90
74
|
query = if selectors.size == 1
|
91
75
|
pacticipant_ids_matching_one_selector_optimised(selectors)
|
92
76
|
else
|
77
|
+
query = select_pacticipant_ids.distinct
|
93
78
|
if infer_integrations
|
94
|
-
|
95
|
-
.distinct
|
96
|
-
.matching_any_of_multiple_selectors(selectors)
|
79
|
+
query.matching_any_of_multiple_selectors(selectors)
|
97
80
|
else
|
98
|
-
|
99
|
-
.
|
100
|
-
|
81
|
+
if selectors.all?(&:only_pacticipant_name_specified?)
|
82
|
+
query.matching_multiple_selectors_without_joining_verifications(selectors)
|
83
|
+
else
|
84
|
+
query.matching_multiple_selectors_joining_verifications(selectors)
|
85
|
+
end
|
101
86
|
end
|
102
87
|
end
|
103
88
|
|
@@ -116,22 +101,16 @@ module PactBroker
|
|
116
101
|
if selectors.size == 1
|
117
102
|
matching_one_selector(selectors)
|
118
103
|
else
|
119
|
-
|
104
|
+
matching_multiple_selectors_joining_verifications(selectors)
|
120
105
|
end
|
121
106
|
end
|
122
107
|
|
123
|
-
def
|
124
|
-
from_self.
|
125
|
-
order(
|
126
|
-
Sequel.asc(:consumer_name),
|
127
|
-
Sequel.desc(:consumer_version_order),
|
128
|
-
Sequel.asc(:provider_name),
|
129
|
-
Sequel.desc(:provider_version_order),
|
130
|
-
Sequel.desc(:verification_id))
|
108
|
+
def order_by_last_action_date
|
109
|
+
from_self(alias: :unordered_rows).select(LAST_ACTION_DATE, Sequel[:unordered_rows].* ).order(Sequel.desc(:last_action_date), Sequel.desc(:pact_order), Sequel.desc(:verification_id))
|
131
110
|
end
|
132
111
|
|
133
|
-
def
|
134
|
-
order(Sequel.desc(
|
112
|
+
def order_by_pact_publication_created_at
|
113
|
+
order(Sequel.desc(:consumer_version_created_at), Sequel.desc(:pact_order))
|
135
114
|
end
|
136
115
|
|
137
116
|
def eager_all_the_things
|
@@ -147,7 +126,7 @@ module PactBroker
|
|
147
126
|
end
|
148
127
|
|
149
128
|
def default_scope
|
150
|
-
select_all_columns.join_verifications.
|
129
|
+
select_all_columns.join_verifications.from_self
|
151
130
|
end
|
152
131
|
|
153
132
|
# PRIVATE METHODS
|
@@ -156,9 +135,8 @@ module PactBroker
|
|
156
135
|
# what integrations exist
|
157
136
|
def matching_one_selector(selectors)
|
158
137
|
join_verifications
|
159
|
-
.join_pacticipants_and_pacticipant_versions
|
160
138
|
.where {
|
161
|
-
QueryBuilder.consumer_or_consumer_version_or_provider_or_provider_or_provider_version_match(QueryIds.from_selectors(selectors))
|
139
|
+
QueryBuilder.consumer_or_consumer_version_or_provider_or_provider_or_provider_version_match(QueryIds.from_selectors(selectors), :p, :v)
|
162
140
|
}
|
163
141
|
end
|
164
142
|
|
@@ -181,7 +159,7 @@ module PactBroker
|
|
181
159
|
.distinct
|
182
160
|
.inner_join_verifications
|
183
161
|
.where {
|
184
|
-
QueryBuilder.provider_or_provider_version_matches(query_ids, :v)
|
162
|
+
QueryBuilder.provider_or_provider_version_matches(query_ids, :v, :v)
|
185
163
|
}
|
186
164
|
end
|
187
165
|
|
@@ -194,28 +172,41 @@ module PactBroker
|
|
194
172
|
# Instead, we need to filter the verifications dataset down to only the ones specified in the selectors first,
|
195
173
|
# and THEN join them to the pacts, so that we get a row for the pact with null provider version
|
196
174
|
# and verification fields.
|
197
|
-
|
175
|
+
|
176
|
+
def matching_multiple_selectors_joining_verifications(selectors)
|
198
177
|
query_ids = QueryIds.from_selectors(selectors)
|
199
178
|
join_verifications_for(query_ids)
|
200
|
-
.join_pacticipants_and_pacticipant_versions
|
201
179
|
.where {
|
202
180
|
Sequel.&(
|
203
181
|
QueryBuilder.consumer_or_consumer_version_matches(query_ids, :p),
|
204
|
-
QueryBuilder.provider_or_provider_version_matches_or_pact_unverified(query_ids, :v),
|
182
|
+
QueryBuilder.provider_or_provider_version_matches_or_pact_unverified(query_ids, :v, :p),
|
205
183
|
QueryBuilder.either_consumer_or_provider_was_specified_in_query(query_ids, :p)
|
206
184
|
)
|
207
185
|
}
|
208
186
|
end
|
209
187
|
|
188
|
+
def matching_multiple_selectors_without_joining_verifications(selectors)
|
189
|
+
# There are no versions specified in these selectors, so we can do the whole
|
190
|
+
# query based on the consumer/provider IDs, which we have in the pact_publication
|
191
|
+
# table without having to do a join.
|
192
|
+
query_ids = QueryIds.from_selectors(selectors)
|
193
|
+
where {
|
194
|
+
Sequel.&(
|
195
|
+
QueryBuilder.consumer_or_consumer_version_matches(query_ids, :p),
|
196
|
+
QueryBuilder.provider_matches(query_ids, :p),
|
197
|
+
QueryBuilder.either_consumer_or_provider_was_specified_in_query(query_ids, :p)
|
198
|
+
)
|
199
|
+
}
|
200
|
+
end
|
201
|
+
|
210
202
|
def matching_any_of_multiple_selectors(selectors)
|
211
203
|
query_ids = QueryIds.from_selectors(selectors)
|
212
204
|
join_verifications_for(query_ids)
|
213
|
-
.join_pacticipants_and_pacticipant_versions
|
214
205
|
.where {
|
215
206
|
Sequel.&(
|
216
207
|
Sequel.|(
|
217
208
|
QueryBuilder.consumer_or_consumer_version_matches(query_ids, :p),
|
218
|
-
QueryBuilder.provider_or_provider_version_matches_or_pact_unverified(query_ids, :v),
|
209
|
+
QueryBuilder.provider_or_provider_version_matches_or_pact_unverified(query_ids, :v, :p),
|
219
210
|
),
|
220
211
|
QueryBuilder.either_consumer_or_provider_was_specified_in_query(query_ids, :p)
|
221
212
|
)
|
@@ -228,7 +219,7 @@ module PactBroker
|
|
228
219
|
|
229
220
|
def verifications_for(query_ids)
|
230
221
|
db[LV]
|
231
|
-
.select(:verification_id, :provider_version_id, :pact_version_id, :provider_id)
|
222
|
+
.select(:verification_id, :provider_version_id, :pact_version_id, :provider_id, :created_at)
|
232
223
|
.where {
|
233
224
|
Sequel.&(
|
234
225
|
QueryBuilder.consumer_in_pacticipant_ids(query_ids),
|
@@ -237,13 +228,6 @@ module PactBroker
|
|
237
228
|
}
|
238
229
|
end
|
239
230
|
|
240
|
-
def join_pacticipants_and_pacticipant_versions
|
241
|
-
join_consumers
|
242
|
-
.join_providers
|
243
|
-
.join_consumer_versions
|
244
|
-
.join_provider_versions
|
245
|
-
end
|
246
|
-
|
247
231
|
def join_consumers qualifier = :p, table_alias = :consumers
|
248
232
|
join(
|
249
233
|
:pacticipants,
|
@@ -360,27 +344,27 @@ module PactBroker
|
|
360
344
|
end
|
361
345
|
|
362
346
|
def consumer_name
|
363
|
-
|
347
|
+
consumer.name
|
364
348
|
end
|
365
349
|
|
366
350
|
def consumer_version_number
|
367
|
-
|
351
|
+
consumer_version.number
|
368
352
|
end
|
369
353
|
|
370
354
|
def consumer_version_order
|
371
|
-
|
355
|
+
consumer_version.order
|
372
356
|
end
|
373
357
|
|
374
358
|
def provider_name
|
375
|
-
|
359
|
+
provider.name
|
376
360
|
end
|
377
361
|
|
378
362
|
def provider_version_number
|
379
|
-
|
363
|
+
provider_version&.number
|
380
364
|
end
|
381
365
|
|
382
366
|
def provider_version_order
|
383
|
-
|
367
|
+
provider_version&.order
|
384
368
|
end
|
385
369
|
|
386
370
|
def last_action_date
|