pact_broker 2.58.0 → 2.59.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release_gem.yml +45 -0
- data/.travis.yml +5 -3
- data/CHANGELOG.md +37 -0
- data/DEVELOPER_SETUP.md +46 -16
- data/Dockerfile +23 -2
- data/Gemfile +29 -2
- data/config.ru +32 -12
- data/config/database.yml +7 -0
- data/docker-compose-dev-postgres.yml +35 -0
- data/docker-compose-test.yml +100 -0
- data/lib/pact_broker/api/decorators/decorator_context.rb +1 -1
- data/lib/pact_broker/api/decorators/version_decorator.rb +2 -0
- data/lib/pact_broker/api/pact_broker_urls.rb +4 -4
- data/lib/pact_broker/api/paths.rb +15 -0
- data/lib/pact_broker/api/renderers/html_pact_renderer.rb +26 -8
- data/lib/pact_broker/api/resources/all_webhooks.rb +12 -3
- data/lib/pact_broker/api/resources/badge.rb +4 -0
- data/lib/pact_broker/api/resources/base_resource.rb +2 -174
- data/lib/pact_broker/api/resources/can_i_deploy.rb +8 -0
- data/lib/pact_broker/api/resources/dashboard.rb +4 -0
- data/lib/pact_broker/api/resources/default_base_resource.rb +211 -0
- data/lib/pact_broker/api/resources/error_handler.rb +3 -5
- data/lib/pact_broker/api/resources/group.rb +7 -11
- data/lib/pact_broker/api/resources/index.rb +4 -0
- data/lib/pact_broker/api/resources/integration.rb +12 -0
- data/lib/pact_broker/api/resources/integrations.rb +9 -1
- data/lib/pact_broker/api/resources/label.rb +16 -6
- data/lib/pact_broker/api/resources/latest_pact.rb +8 -0
- data/lib/pact_broker/api/resources/latest_pacts.rb +9 -4
- data/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb +16 -2
- data/lib/pact_broker/api/resources/matrix.rb +2 -2
- data/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb +1 -1
- data/lib/pact_broker/api/resources/pact.rb +8 -0
- data/lib/pact_broker/api/resources/pact_content_diff.rb +1 -2
- data/lib/pact_broker/api/resources/pact_triggered_webhooks.rb +1 -7
- data/lib/pact_broker/api/resources/pact_versions.rb +1 -3
- data/lib/pact_broker/api/resources/pact_webhooks.rb +2 -5
- data/lib/pact_broker/api/resources/pact_webhooks_status.rb +1 -17
- data/lib/pact_broker/api/resources/pacticipant.rb +11 -14
- data/lib/pact_broker/api/resources/pacticipants.rb +15 -1
- data/lib/pact_broker/api/resources/pacticipants_for_label.rb +1 -1
- data/lib/pact_broker/api/resources/previous_distinct_pact_version.rb +8 -1
- data/lib/pact_broker/api/resources/provider_pacts.rb +9 -1
- data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +1 -1
- data/lib/pact_broker/api/resources/tag.rb +5 -1
- data/lib/pact_broker/api/resources/tagged_pact_versions.rb +1 -2
- data/lib/pact_broker/api/resources/triggered_webhook_logs.rb +4 -0
- data/lib/pact_broker/api/resources/verification.rb +7 -3
- data/lib/pact_broker/api/resources/verification_triggered_webhooks.rb +5 -1
- data/lib/pact_broker/api/resources/verifications.rb +7 -3
- data/lib/pact_broker/api/resources/version.rb +4 -1
- data/lib/pact_broker/api/resources/versions.rb +1 -3
- data/lib/pact_broker/api/resources/webhook.rb +6 -2
- data/lib/pact_broker/api/resources/webhook_execution.rb +4 -0
- data/lib/pact_broker/api/resources/webhooks.rb +3 -18
- data/lib/pact_broker/app.rb +1 -0
- data/lib/pact_broker/badges/service.rb +3 -2
- data/lib/pact_broker/configuration.rb +21 -2
- data/lib/pact_broker/db/clean.rb +0 -6
- data/lib/pact_broker/doc/views/layouts/main.haml +1 -1
- data/lib/pact_broker/domain/pacticipant.rb +7 -2
- data/lib/pact_broker/domain/version.rb +3 -0
- data/lib/pact_broker/groups/service.rb +1 -1
- data/lib/pact_broker/index/service.rb +9 -43
- data/lib/pact_broker/matrix/deployment_status_summary.rb +1 -1
- data/lib/pact_broker/pacticipants/repository.rb +2 -2
- data/lib/pact_broker/pacts/content.rb +2 -1
- data/lib/pact_broker/pacts/latest_pact_publication_id_for_consumer_version.rb +2 -5
- data/lib/pact_broker/pacts/pact_publication.rb +11 -9
- data/lib/pact_broker/pacts/pact_version.rb +3 -4
- data/lib/pact_broker/pacts/repository.rb +53 -39
- data/lib/pact_broker/pacts/verifiable_pact.rb +8 -0
- data/lib/pact_broker/policies.rb +53 -0
- data/lib/pact_broker/repositories/helpers.rb +3 -20
- data/lib/pact_broker/test/test_data_builder.rb +4 -4
- data/lib/pact_broker/ui/controllers/clusters.rb +1 -1
- data/lib/pact_broker/ui/controllers/groups.rb +2 -2
- data/lib/pact_broker/ui/controllers/index.rb +1 -3
- data/lib/pact_broker/ui/controllers/matrix.rb +2 -2
- data/lib/pact_broker/ui/views/groups/show.html.erb +3 -3
- data/lib/pact_broker/ui/views/index/show-with-tags.haml +10 -10
- data/lib/pact_broker/ui/views/index/show.haml +6 -6
- data/lib/pact_broker/ui/views/layouts/main.haml +1 -1
- data/lib/pact_broker/ui/views/matrix/show.haml +4 -5
- data/lib/pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version.rb +3 -5
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/repository.rb +2 -4
- data/lib/rack/pact_broker/request_target.rb +6 -1
- data/lib/sequel/plugins/insert_ignore.rb +69 -0
- data/lib/sequel/plugins/upsert.rb +103 -0
- data/pact_broker.gemspec +22 -41
- data/public/javascripts/pact.js +6 -2
- data/script/docker/db-execute-sql-file.sh +2 -0
- data/script/issues/consumer-version-selectors-docs/issue-text.txt +11 -0
- data/script/issues/consumer-version-selectors-docs/issues.txt +6 -0
- data/script/issues/consumer-version-selectors-docs/raise-issue-in-client-repos.sh +10 -0
- data/script/prod/redact-data.sql +1 -0
- data/script/release-via-github-action.sh +7 -0
- data/script/seed.rb +5 -7
- data/script/trigger-release.sh +30 -0
- data/spec/features/get_versions_spec.rb +1 -6
- data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +4 -0
- data/spec/lib/pact_broker/api/pact_broker_urls_spec.rb +2 -2
- data/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +24 -6
- data/spec/lib/pact_broker/api/resources/all_webhooks_spec.rb +1 -1
- data/spec/lib/pact_broker/api/resources/default_base_resource_spec.rb +158 -0
- data/spec/lib/pact_broker/api/resources/error_handler_spec.rb +18 -1
- data/spec/lib/pact_broker/api/resources/tag_spec.rb +2 -2
- data/spec/lib/pact_broker/api/resources/webhook_spec.rb +1 -1
- data/spec/lib/pact_broker/api/resources/webhooks_spec.rb +1 -1
- data/spec/lib/pact_broker/badges/service_spec.rb +6 -6
- data/spec/lib/pact_broker/db/clean_old_spec.rb +125 -0
- data/spec/lib/pact_broker/db/clean_spec.rb +45 -11
- data/spec/lib/pact_broker/index/service_spec.rb +2 -3
- data/spec/lib/pact_broker/pacts/content_spec.rb +8 -0
- data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb +36 -0
- data/spec/lib/pact_broker/versions/repository_spec.rb +8 -0
- data/spec/lib/rack/pact_broker/request_target_spec.rb +7 -0
- data/spec/lib/sequel/plugins/insert_ignore_spec.rb +82 -0
- data/spec/lib/sequel/plugins/upsert_spec.rb +125 -0
- data/spec/spec_helper.rb +1 -0
- data/tasks/audit.rake +6 -2
- data/tasks/development.rake +2 -2
- metadata +46 -284
- data/spec/lib/pact_broker/api/resources/base_resource_spec.rb +0 -78
@@ -7,6 +7,7 @@ module PactBroker
|
|
7
7
|
module Domain
|
8
8
|
class Version < Sequel::Model
|
9
9
|
plugin :timestamps, update_on_create: true
|
10
|
+
plugin :insert_ignore, identifying_columns: [:pacticipant_id, :number]
|
10
11
|
|
11
12
|
set_primary_key :id
|
12
13
|
one_to_many :pact_publications, order: :revision_number, class: "PactBroker::Pacts::PactPublication", key: :consumer_version_id
|
@@ -86,7 +87,9 @@ module PactBroker
|
|
86
87
|
end
|
87
88
|
|
88
89
|
def after_create
|
90
|
+
super
|
89
91
|
OrderVersions.(self)
|
92
|
+
refresh
|
90
93
|
end
|
91
94
|
|
92
95
|
def before_destroy
|
@@ -28,51 +28,17 @@ module PactBroker
|
|
28
28
|
# and the Pactflow UI. It really needs to be broken into to separate methods, as it's getting too messy
|
29
29
|
# supporting both
|
30
30
|
|
31
|
-
def self.
|
32
|
-
|
33
|
-
find_index_items_optimised(options)
|
34
|
-
else
|
35
|
-
find_index_items_original(options)
|
36
|
-
end
|
31
|
+
def self.pact_publication_scope
|
32
|
+
PactBroker.policy_scope!(PactBroker::Pacts::PactPublication)
|
37
33
|
end
|
38
34
|
|
39
|
-
def self.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
.eager(:webhooks)
|
44
|
-
|
45
|
-
if !options[:tags]
|
46
|
-
# server side rendered index page without tags
|
47
|
-
rows = rows.where(consumer_version_tag_name: nil)
|
48
|
-
else
|
49
|
-
# server side rendered index page with tags=true or tags[]=a&tags=[]b
|
50
|
-
if options[:tags].is_a?(Array)
|
51
|
-
rows = rows.where(consumer_version_tag_name: options[:tags]).or(consumer_version_tag_name: nil)
|
52
|
-
end
|
53
|
-
rows = rows.eager(:consumer_version_tags)
|
54
|
-
.eager(:provider_version_tags)
|
55
|
-
.eager(:latest_verification_for_consumer_version_tag)
|
56
|
-
.eager(:latest_verification_for_consumer_and_provider)
|
57
|
-
end
|
58
|
-
rows = rows.all.group_by(&:pact_publication_id).values.collect{ | rows| Matrix::AggregatedRow.new(rows) }
|
59
|
-
|
60
|
-
rows.sort.collect do | row |
|
61
|
-
PactBroker::Domain::IndexItem.create(
|
62
|
-
row.consumer,
|
63
|
-
row.provider,
|
64
|
-
row.pact,
|
65
|
-
row.overall_latest?,
|
66
|
-
row.latest_verification_for_pseudo_branch,
|
67
|
-
row.webhooks,
|
68
|
-
row.latest_triggered_webhooks,
|
69
|
-
options[:tags] ? row.consumer_head_tag_names : [],
|
70
|
-
options[:tags] ? row.provider_version_tags.select(&:latest?) : []
|
71
|
-
)
|
72
|
-
end
|
35
|
+
def self.find_all_index_items
|
36
|
+
# Is there a better way to do this? Setting a page_size of nil or -1 doesn't work
|
37
|
+
# If we get to 100000000000 index items, we're probably going to have bigger issues...
|
38
|
+
find_index_items(page_number: 1, page_size: 100000000000)
|
73
39
|
end
|
74
40
|
|
75
|
-
def self.
|
41
|
+
def self.find_index_items options = {}
|
76
42
|
latest_verifications_for_cv_tags = latest_verifications_for_consumer_version_tags(options)
|
77
43
|
latest_pact_publication_ids = latest_pact_publications.select(:id).all.collect{ |h| h[:id] }
|
78
44
|
|
@@ -82,7 +48,7 @@ module PactBroker
|
|
82
48
|
pact_publication_ids = head_pact_publication_ids(options)
|
83
49
|
pagination_record_count = pact_publication_ids.pagination_record_count
|
84
50
|
|
85
|
-
pact_publications =
|
51
|
+
pact_publications = pact_publication_scope
|
86
52
|
.where(id: pact_publication_ids)
|
87
53
|
.select_all_qualified
|
88
54
|
.eager(:consumer)
|
@@ -144,7 +110,7 @@ module PactBroker
|
|
144
110
|
latest_pact_publication_ids = latest_pact_publications.select(:id).all.collect{ |h| h[:id] }
|
145
111
|
pact_publication_ids = head_pact_publication_ids(consumer_name: consumer_name, provider_name: provider_name, tags: true)
|
146
112
|
|
147
|
-
pact_publications =
|
113
|
+
pact_publications = pact_publication_scope
|
148
114
|
.where(id: pact_publication_ids)
|
149
115
|
.select_all_qualified
|
150
116
|
.eager(:consumer)
|
@@ -195,7 +195,7 @@ module PactBroker
|
|
195
195
|
InteractionsMissingVerifications.new(selector_for(row.consumer_name), selector_for(row.provider_name), row.verification.interactions_missing_test_results)
|
196
196
|
end
|
197
197
|
rescue StandardError => e
|
198
|
-
|
198
|
+
logger.warn("Error determining if there were missing interaction verifications", e)
|
199
199
|
nil
|
200
200
|
end
|
201
201
|
end.compact.tap { |it| report_missing_interaction_verifications(it) if it.any? }
|
@@ -54,12 +54,12 @@ module PactBroker
|
|
54
54
|
# TODO raise error if attributes apart from name are different, because this indicates that
|
55
55
|
# the second request is not at the same time.
|
56
56
|
def create args
|
57
|
-
PactBroker::Domain::Pacticipant.
|
57
|
+
PactBroker::Domain::Pacticipant.new(
|
58
58
|
name: args[:name],
|
59
59
|
repository_url: args[:repository_url],
|
60
60
|
created_at: Sequel.datetime_class.now,
|
61
61
|
updated_at: Sequel.datetime_class.now
|
62
|
-
)
|
62
|
+
).insert_ignore
|
63
63
|
PactBroker::Domain::Pacticipant.find(name: args[:name])
|
64
64
|
end
|
65
65
|
|
@@ -4,16 +4,13 @@ require 'pact_broker/repositories/helpers'
|
|
4
4
|
module PactBroker
|
5
5
|
module Pacts
|
6
6
|
class LatestPactPublicationIdForConsumerVersion < Sequel::Model(:latest_pact_publication_ids_for_consumer_versions)
|
7
|
-
|
7
|
+
set_primary_key [:provider_id, :consumer_version_id]
|
8
8
|
unrestrict_primary_key
|
9
|
+
plugin :upsert, identifying_columns: [:provider_id, :consumer_version_id]
|
9
10
|
|
10
11
|
dataset_module do
|
11
12
|
include PactBroker::Repositories::Helpers
|
12
13
|
end
|
13
|
-
|
14
|
-
def upsert
|
15
|
-
self.class.upsert(to_hash, [:provider_id, :consumer_version_id])
|
16
|
-
end
|
17
14
|
end
|
18
15
|
end
|
19
16
|
end
|
@@ -7,7 +7,6 @@ require 'pact_broker/tags/head_pact_tags'
|
|
7
7
|
module PactBroker
|
8
8
|
module Pacts
|
9
9
|
class PactPublication < Sequel::Model(:pact_publications)
|
10
|
-
UNIQUE_CONSTRAINT_KEYS = [:consumer_version_id, :provider_id, :revision_number].freeze
|
11
10
|
|
12
11
|
extend Forwardable
|
13
12
|
|
@@ -22,6 +21,9 @@ module PactBroker
|
|
22
21
|
one_to_one(:latest_verification, class: "PactBroker::Verifications::LatestVerificationForPactVersion", key: :pact_version_id, primary_key: :pact_version_id)
|
23
22
|
one_to_many(:head_pact_tags, class: "PactBroker::Tags::HeadPactTag", primary_key: :id, key: :pact_publication_id)
|
24
23
|
|
24
|
+
plugin :upsert, identifying_columns: [:consumer_version_id, :provider_id, :revision_number]
|
25
|
+
plugin :timestamps, update_on_create: true
|
26
|
+
|
25
27
|
dataset_module do
|
26
28
|
include PactBroker::Repositories::Helpers
|
27
29
|
|
@@ -71,6 +73,14 @@ module PactBroker
|
|
71
73
|
where(name_like(Sequel[:providers][:name], name))
|
72
74
|
end
|
73
75
|
|
76
|
+
def consumer_name_like(name)
|
77
|
+
where(name_like(Sequel[:consumers][:name], name))
|
78
|
+
end
|
79
|
+
|
80
|
+
def consumer_version_number_like(number)
|
81
|
+
where(name_like(Sequel[:cv][:number], number))
|
82
|
+
end
|
83
|
+
|
74
84
|
def consumer_version_tag(tag)
|
75
85
|
where(Sequel[:ct][:name] => tag)
|
76
86
|
end
|
@@ -150,20 +160,12 @@ module PactBroker
|
|
150
160
|
OpenStruct.new(number: consumer_version.number, pacticipant: consumer, order: consumer_version.order)
|
151
161
|
end
|
152
162
|
|
153
|
-
def upsert
|
154
|
-
params = to_hash.merge(created_at: Sequel.datetime_class.now)
|
155
|
-
self.id = PactPublication.upsert(params, UNIQUE_CONSTRAINT_KEYS).id
|
156
|
-
self.refresh
|
157
|
-
end
|
158
|
-
|
159
163
|
private
|
160
164
|
|
161
165
|
def cached_domain_for_delegation
|
162
166
|
@domain_object ||= to_domain
|
163
167
|
end
|
164
168
|
end
|
165
|
-
|
166
|
-
PactPublication.plugin :timestamps, update_on_create: true
|
167
169
|
end
|
168
170
|
end
|
169
171
|
|
@@ -6,6 +6,8 @@ module PactBroker
|
|
6
6
|
module Pacts
|
7
7
|
class PactVersion < Sequel::Model(:pact_versions)
|
8
8
|
plugin :timestamps
|
9
|
+
plugin :upsert, identifying_columns: [:consumer_id, :provider_id, :sha]
|
10
|
+
|
9
11
|
one_to_many :pact_publications, reciprocal: :pact_version
|
10
12
|
one_to_many :verifications, reciprocal: :verification, order: :id, class: "PactBroker::Domain::Verification"
|
11
13
|
one_to_one :latest_verification, class: "PactBroker::Verifications::LatestVerificationForPactVersion", key: :pact_version_id, primary_key: :id
|
@@ -79,14 +81,11 @@ module PactBroker
|
|
79
81
|
.join(:versions, Sequel[:versions][:id] => Sequel[:verifications][:provider_version_id])
|
80
82
|
.any?
|
81
83
|
end
|
82
|
-
|
83
|
-
def upsert
|
84
|
-
self.class.upsert(to_hash, [:consumer_id, :provider_id, :sha])
|
85
|
-
end
|
86
84
|
end
|
87
85
|
end
|
88
86
|
end
|
89
87
|
|
88
|
+
|
90
89
|
# Table: pact_versions
|
91
90
|
# Columns:
|
92
91
|
# id | integer | PRIMARY KEY DEFAULT nextval('pact_versions_id_seq'::regclass)
|
@@ -26,6 +26,16 @@ module PactBroker
|
|
26
26
|
include PactBroker::Repositories
|
27
27
|
include PactBroker::Repositories::Helpers
|
28
28
|
|
29
|
+
def scope_for(scope)
|
30
|
+
PactBroker.policy_scope!(scope)
|
31
|
+
end
|
32
|
+
|
33
|
+
# For the times when it doesn't make sense to use the scoped class, this is a way to
|
34
|
+
# indicate that it is an intentional use of the PactVersion class directly.
|
35
|
+
def unscoped(scope)
|
36
|
+
scope
|
37
|
+
end
|
38
|
+
|
29
39
|
def create params
|
30
40
|
pact_version = find_or_create_pact_version(
|
31
41
|
params.fetch(:consumer_id),
|
@@ -87,16 +97,19 @@ module PactBroker
|
|
87
97
|
end
|
88
98
|
|
89
99
|
def delete params
|
90
|
-
id =
|
91
|
-
.
|
92
|
-
.
|
93
|
-
.
|
94
|
-
.
|
95
|
-
|
100
|
+
id = scope_for(PactPublication)
|
101
|
+
.join_consumers
|
102
|
+
.join_providers
|
103
|
+
.join_consumer_versions
|
104
|
+
.consumer_name_like(params.consumer_name)
|
105
|
+
.provider_name_like(params.provider_name)
|
106
|
+
.consumer_version_number_like(params.consumer_version_number)
|
107
|
+
.select_for_subquery(Sequel[:pact_publications][:id].as(:id))
|
108
|
+
unscoped(PactPublication).where(id: id).delete
|
96
109
|
end
|
97
110
|
|
98
111
|
def delete_by_version_id version_id
|
99
|
-
|
112
|
+
scope_for(PactPublication).where(consumer_version_id: version_id).delete
|
100
113
|
end
|
101
114
|
|
102
115
|
def find_all_pact_versions_between consumer_name, options
|
@@ -109,25 +122,25 @@ module PactBroker
|
|
109
122
|
def delete_all_pact_publications_between consumer_name, options
|
110
123
|
consumer = pacticipant_repository.find_by_name!(consumer_name)
|
111
124
|
provider = pacticipant_repository.find_by_name!(options.fetch(:and))
|
112
|
-
query = PactPublication.where(consumer: consumer, provider: provider)
|
125
|
+
query = scope_for(PactPublication).where(consumer: consumer, provider: provider)
|
113
126
|
query = query.tag(options[:tag]) if options[:tag]
|
114
127
|
|
115
128
|
ids = query.select_for_subquery(:id)
|
116
129
|
webhook_repository.delete_triggered_webhooks_by_pact_publication_ids(ids)
|
117
|
-
PactPublication.where(id: ids).delete
|
130
|
+
unscoped(PactPublication).where(id: ids).delete
|
118
131
|
end
|
119
132
|
|
120
133
|
def delete_all_pact_versions_between consumer_name, options
|
121
134
|
consumer = pacticipant_repository.find_by_name(consumer_name)
|
122
135
|
provider = pacticipant_repository.find_by_name(options.fetch(:and))
|
123
|
-
PactVersion.where(consumer: consumer, provider: provider).delete
|
136
|
+
scope_for(PactVersion).where(consumer: consumer, provider: provider).delete
|
124
137
|
end
|
125
138
|
|
126
139
|
def find_latest_pact_versions_for_provider provider_name, tag = nil
|
127
140
|
if tag
|
128
|
-
LatestTaggedPactPublications.provider(provider_name).order_ignore_case(:consumer_name).where(tag_name: tag).collect(&:to_domain)
|
141
|
+
scope_for(LatestTaggedPactPublications).provider(provider_name).order_ignore_case(:consumer_name).where(tag_name: tag).collect(&:to_domain)
|
129
142
|
else
|
130
|
-
LatestPactPublications.provider(provider_name).order_ignore_case(:consumer_name).collect(&:to_domain)
|
143
|
+
scope_for(LatestPactPublications).provider(provider_name).order_ignore_case(:consumer_name).collect(&:to_domain)
|
131
144
|
end
|
132
145
|
end
|
133
146
|
|
@@ -135,7 +148,7 @@ module PactBroker
|
|
135
148
|
provider = pacticipant_repository.find_by_name(provider_name)
|
136
149
|
consumer = selector.consumer ? pacticipant_repository.find_by_name(selector.consumer) : nil
|
137
150
|
|
138
|
-
PactPublication
|
151
|
+
scope_for(PactPublication)
|
139
152
|
.select_all_qualified
|
140
153
|
.select_append(Sequel[:cv][:order].as(:consumer_version_order))
|
141
154
|
.select_append(Sequel[:ct][:name].as(:consumer_version_tag_name))
|
@@ -189,7 +202,7 @@ module PactBroker
|
|
189
202
|
non_wip_pact_publication_ids,
|
190
203
|
options)
|
191
204
|
|
192
|
-
wip_pacts =
|
205
|
+
wip_pacts = scope_for(PactPublication).where(id: wip_pact_publication_ids)
|
193
206
|
|
194
207
|
# The first instance (by date) of each provider tag with that name
|
195
208
|
provider_tag_collection = PactBroker::Domain::Tag
|
@@ -212,12 +225,12 @@ module PactBroker
|
|
212
225
|
selectors = Selectors.create_for_latest_of_each_tag(pact.head_tag_names)
|
213
226
|
VerifiablePact.new(pact.to_domain, selectors, true, pre_existing_pending_tags, [], true)
|
214
227
|
end
|
215
|
-
end.compact
|
228
|
+
end.compact.sort
|
216
229
|
end
|
217
230
|
|
218
231
|
def find_pact_versions_for_provider provider_name, tag = nil
|
219
232
|
if tag
|
220
|
-
LatestPactPublicationsByConsumerVersion
|
233
|
+
scope_for(LatestPactPublicationsByConsumerVersion)
|
221
234
|
.join(:tags, {version_id: :consumer_version_id})
|
222
235
|
.provider(provider_name)
|
223
236
|
.order_ignore_case(:consumer_name)
|
@@ -225,7 +238,7 @@ module PactBroker
|
|
225
238
|
.where(Sequel[:tags][:name] => tag)
|
226
239
|
.collect(&:to_domain)
|
227
240
|
else
|
228
|
-
LatestPactPublicationsByConsumerVersion
|
241
|
+
scope_for(LatestPactPublicationsByConsumerVersion)
|
229
242
|
.provider(provider_name)
|
230
243
|
.order_ignore_case(:consumer_name)
|
231
244
|
.order_append(:consumer_version_order)
|
@@ -235,25 +248,25 @@ module PactBroker
|
|
235
248
|
|
236
249
|
# Returns latest pact version for the consumer_version_number
|
237
250
|
def find_by_consumer_version consumer_name, consumer_version_number
|
238
|
-
LatestPactPublicationsByConsumerVersion
|
251
|
+
scope_for(LatestPactPublicationsByConsumerVersion)
|
239
252
|
.consumer(consumer_name)
|
240
253
|
.consumer_version_number(consumer_version_number)
|
241
254
|
.collect(&:to_domain_with_content)
|
242
255
|
end
|
243
256
|
|
244
257
|
def find_by_version_and_provider version_id, provider_id
|
245
|
-
LatestPactPublicationsByConsumerVersion
|
258
|
+
scope_for(LatestPactPublicationsByConsumerVersion)
|
246
259
|
.eager(:tags)
|
247
260
|
.where(consumer_version_id: version_id, provider_id: provider_id)
|
248
261
|
.limit(1).collect(&:to_domain_with_content)[0]
|
249
262
|
end
|
250
263
|
|
251
264
|
def find_latest_pacts
|
252
|
-
LatestPactPublications.order(:consumer_name, :provider_name).collect(&:to_domain)
|
265
|
+
scope_for(LatestPactPublications).order(:consumer_name, :provider_name).collect(&:to_domain)
|
253
266
|
end
|
254
267
|
|
255
268
|
def find_latest_pact(consumer_name, provider_name, tag = nil)
|
256
|
-
query = LatestPactPublicationsByConsumerVersion
|
269
|
+
query = scope_for(LatestPactPublicationsByConsumerVersion)
|
257
270
|
.select_all_qualified
|
258
271
|
.consumer(consumer_name)
|
259
272
|
.provider(provider_name)
|
@@ -267,7 +280,7 @@ module PactBroker
|
|
267
280
|
|
268
281
|
# Allows optional consumer_name and provider_name
|
269
282
|
def search_for_latest_pact(consumer_name, provider_name, tag = nil)
|
270
|
-
query = LatestPactPublicationsByConsumerVersion.select_all_qualified
|
283
|
+
query = scope_for(LatestPactPublicationsByConsumerVersion).select_all_qualified
|
271
284
|
query = query.consumer(consumer_name) if consumer_name
|
272
285
|
query = query.provider(provider_name) if provider_name
|
273
286
|
|
@@ -281,12 +294,12 @@ module PactBroker
|
|
281
294
|
|
282
295
|
def find_pact consumer_name, consumer_version, provider_name, pact_version_sha = nil
|
283
296
|
query = if pact_version_sha
|
284
|
-
AllPactPublications
|
297
|
+
scope_for(AllPactPublications)
|
285
298
|
.pact_version_sha(pact_version_sha)
|
286
299
|
.reverse_order(:consumer_version_order)
|
287
300
|
.limit(1)
|
288
301
|
else
|
289
|
-
LatestPactPublicationsByConsumerVersion
|
302
|
+
scope_for(LatestPactPublicationsByConsumerVersion)
|
290
303
|
end
|
291
304
|
query = query
|
292
305
|
.eager(:tags)
|
@@ -297,7 +310,7 @@ module PactBroker
|
|
297
310
|
end
|
298
311
|
|
299
312
|
def find_all_revisions consumer_name, consumer_version, provider_name
|
300
|
-
AllPactPublications
|
313
|
+
scope_for(AllPactPublications)
|
301
314
|
.consumer(consumer_name)
|
302
315
|
.provider(provider_name)
|
303
316
|
.consumer_version_number(consumer_version)
|
@@ -305,7 +318,7 @@ module PactBroker
|
|
305
318
|
end
|
306
319
|
|
307
320
|
def find_previous_pact pact, tag = nil
|
308
|
-
query = LatestPactPublicationsByConsumerVersion
|
321
|
+
query = scope_for(LatestPactPublicationsByConsumerVersion)
|
309
322
|
.eager(:tags)
|
310
323
|
.consumer(pact.consumer.name)
|
311
324
|
.provider(pact.provider.name)
|
@@ -321,7 +334,7 @@ module PactBroker
|
|
321
334
|
end
|
322
335
|
|
323
336
|
def find_next_pact pact
|
324
|
-
LatestPactPublicationsByConsumerVersion
|
337
|
+
scope_for(LatestPactPublicationsByConsumerVersion)
|
325
338
|
.eager(:tags)
|
326
339
|
.consumer(pact.consumer.name)
|
327
340
|
.provider(pact.provider.name)
|
@@ -384,7 +397,7 @@ module PactBroker
|
|
384
397
|
|
385
398
|
def find_pacts_for_which_the_latest_version_is_required(provider_name, consumer_version_selectors)
|
386
399
|
if consumer_version_selectors.empty?
|
387
|
-
LatestPactPublications
|
400
|
+
scope_for(LatestPactPublications)
|
388
401
|
.provider(provider_name)
|
389
402
|
.order_ignore_case(:consumer_name)
|
390
403
|
.collect do | latest_pact_publication |
|
@@ -403,7 +416,7 @@ module PactBroker
|
|
403
416
|
# TODO make this an efficient query!
|
404
417
|
# These are not yet de-duped. Should make the behaviour consistent between this and find_pacts_for_which_all_versions_for_the_tag_are_required ?
|
405
418
|
if tag_names.any?
|
406
|
-
LatestTaggedPactPublications
|
419
|
+
scope_for(LatestTaggedPactPublications)
|
407
420
|
.provider(provider_name)
|
408
421
|
.where(tag_name: tag_names)
|
409
422
|
.all
|
@@ -421,7 +434,7 @@ module PactBroker
|
|
421
434
|
selector_tag_names = pact_publications.collect(&:tag_name)
|
422
435
|
selectors = Selectors.create_for_latest_of_each_tag(selector_tag_names)
|
423
436
|
last_pact_publication = pact_publications.sort_by(&:consumer_version_order).last
|
424
|
-
pact_publication = PactPublication.find(id: last_pact_publication.id)
|
437
|
+
pact_publication = scope_for(PactPublication).find(id: last_pact_publication.id)
|
425
438
|
SelectedPact.new(
|
426
439
|
pact_publication.to_domain,
|
427
440
|
selectors
|
@@ -432,7 +445,7 @@ module PactBroker
|
|
432
445
|
selector_tag_names = pact_publications.collect(&:tag_name)
|
433
446
|
selectors = Selectors.create_for_latest_fallback_of_each_tag(selector_tag_names)
|
434
447
|
last_pact_publication = pact_publications.sort_by(&:consumer_version_order).last
|
435
|
-
pact_publication = PactPublication.find(id: last_pact_publication.id)
|
448
|
+
pact_publication = unscoped(PactPublication).find(id: last_pact_publication.id)
|
436
449
|
SelectedPact.new(
|
437
450
|
pact_publication.to_domain,
|
438
451
|
selectors
|
@@ -441,12 +454,12 @@ module PactBroker
|
|
441
454
|
|
442
455
|
def find_pacts_for_which_the_latest_version_for_the_fallback_tag_is_required(provider_name, selectors)
|
443
456
|
selectors.collect do | selector |
|
444
|
-
LatestTaggedPactPublications
|
457
|
+
scope_for(LatestTaggedPactPublications)
|
445
458
|
.provider(provider_name)
|
446
459
|
.where(tag_name: selector.fallback_tag)
|
447
460
|
.all
|
448
461
|
.collect do | latest_tagged_pact_publication |
|
449
|
-
pact_publication = PactPublication.find(id: latest_tagged_pact_publication.id)
|
462
|
+
pact_publication = unscoped(PactPublication).find(id: latest_tagged_pact_publication.id)
|
450
463
|
SelectedPact.new(
|
451
464
|
pact_publication.to_domain,
|
452
465
|
Selectors.new(selector)
|
@@ -467,13 +480,13 @@ module PactBroker
|
|
467
480
|
|
468
481
|
def find_previous_distinct_pact_by_sha pact
|
469
482
|
current_pact_content_sha =
|
470
|
-
LatestPactPublicationsByConsumerVersion.select(:pact_version_sha)
|
483
|
+
scope_for(LatestPactPublicationsByConsumerVersion).select(:pact_version_sha)
|
471
484
|
.consumer(pact.consumer.name)
|
472
485
|
.provider(pact.provider.name)
|
473
486
|
.consumer_version_number(pact.consumer_version_number)
|
474
487
|
.limit(1)
|
475
488
|
|
476
|
-
LatestPactPublicationsByConsumerVersion
|
489
|
+
scope_for(LatestPactPublicationsByConsumerVersion)
|
477
490
|
.eager(:tags)
|
478
491
|
.consumer(pact.consumer.name)
|
479
492
|
.provider(pact.provider.name)
|
@@ -488,7 +501,8 @@ module PactBroker
|
|
488
501
|
end
|
489
502
|
|
490
503
|
def find_or_create_pact_version consumer_id, provider_id, pact_version_sha, json_content
|
491
|
-
PactVersion.find(sha: pact_version_sha, consumer_id: consumer_id, provider_id: provider_id) ||
|
504
|
+
unscoped(PactVersion).find(sha: pact_version_sha, consumer_id: consumer_id, provider_id: provider_id) ||
|
505
|
+
create_pact_version(consumer_id, provider_id, pact_version_sha, json_content)
|
492
506
|
end
|
493
507
|
|
494
508
|
def create_pact_version consumer_id, provider_id, sha, json_content
|
@@ -504,7 +518,7 @@ module PactBroker
|
|
504
518
|
def find_all_database_versions_between(consumer_name, options, base_class = LatestPactPublicationsByConsumerVersion)
|
505
519
|
provider_name = options.fetch(:and)
|
506
520
|
|
507
|
-
query = base_class
|
521
|
+
query = scope_for(base_class)
|
508
522
|
.consumer(consumer_name)
|
509
523
|
.provider(provider_name)
|
510
524
|
|
@@ -535,7 +549,7 @@ module PactBroker
|
|
535
549
|
|
536
550
|
def find_head_pacts_that_have_not_been_successfully_verified_by_all_provider_tags(provider_id, pact_publication_ids_successfully_verified_by_all_provider_tags, options)
|
537
551
|
# Exclude the head pacts that have been successfully verified by all the specified provider tags
|
538
|
-
LatestTaggedPactPublications
|
552
|
+
scope_for(LatestTaggedPactPublications)
|
539
553
|
.where(provider_id: provider_id)
|
540
554
|
.where(Sequel.lit('latest_tagged_pact_publications.created_at > ?', options.fetch(:include_wip_pacts_since)))
|
541
555
|
.exclude(id: pact_publication_ids_successfully_verified_by_all_provider_tags)
|
@@ -557,7 +571,7 @@ module PactBroker
|
|
557
571
|
Sequel[:verifications][:provider_version_id] => Sequel[:provider_tags][:version_id],
|
558
572
|
Sequel[:provider_tags][:name] => provider_tag
|
559
573
|
}
|
560
|
-
head_pacts = LatestTaggedPactPublications
|
574
|
+
head_pacts = scope_for(LatestTaggedPactPublications)
|
561
575
|
.select(Sequel[:latest_tagged_pact_publications][:id].as(:id))
|
562
576
|
.join(:verifications, verifications_join)
|
563
577
|
.join(:tags, tags_join, { table_alias: :provider_tags } )
|