pact_broker 2.95.1 → 2.98.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -0
- data/Gemfile +1 -0
- data/docs/CONFIGURATION.md +120 -66
- data/lib/db.rb +1 -7
- data/lib/pact_broker/api/middleware/http_debug_logs.rb +36 -0
- data/lib/pact_broker/app.rb +3 -7
- data/lib/pact_broker/config/basic_auth_configuration.rb +7 -0
- data/lib/pact_broker/config/runtime_configuration.rb +22 -4
- data/lib/pact_broker/config/runtime_configuration_coercion_methods.rb +11 -0
- data/lib/pact_broker/config/runtime_configuration_database_methods.rb +6 -1
- data/lib/pact_broker/config/runtime_configuration_logging_methods.rb +13 -2
- data/lib/pact_broker/configuration.rb +2 -12
- data/lib/pact_broker/db/models.rb +2 -2
- data/lib/pact_broker/index/service.rb +2 -3
- data/lib/pact_broker/integrations/integration.rb +21 -6
- data/lib/pact_broker/integrations/service.rb +1 -1
- data/lib/pact_broker/matrix/repository.rb +2 -3
- data/lib/pact_broker/matrix/service.rb +0 -1
- data/lib/pact_broker/metrics/service.rb +2 -2
- data/lib/pact_broker/pacts/lazy_loaders.rb +26 -0
- data/lib/pact_broker/pacts/pact_publication.rb +13 -34
- data/lib/pact_broker/pacts/pact_version.rb +24 -28
- data/lib/pact_broker/pacts/pact_version_association_loaders.rb +36 -0
- data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +9 -13
- data/lib/pact_broker/pacts/repository.rb +29 -25
- data/lib/pact_broker/repositories/helpers.rb +4 -0
- data/lib/pact_broker/test/http_test_data_builder.rb +8 -1
- data/lib/pact_broker/test/test_data_builder.rb +2 -1
- data/lib/pact_broker/ui/controllers/matrix.rb +14 -11
- data/lib/pact_broker/version.rb +1 -1
- data/pact_broker.gemspec +1 -1
- metadata +9 -16
- data/lib/pact_broker/matrix/aggregated_row.rb +0 -79
- data/lib/pact_broker/matrix/head_row.rb +0 -80
- data/lib/pact_broker/matrix/row.rb +0 -287
@@ -1,287 +0,0 @@
|
|
1
|
-
require "pact_broker/repositories/helpers"
|
2
|
-
require "pact_broker/webhooks/latest_triggered_webhook"
|
3
|
-
require "pact_broker/tags/tag_with_latest_flag"
|
4
|
-
require "pact_broker/logging"
|
5
|
-
require "pact_broker/verifications/latest_verification_for_consumer_version_tag"
|
6
|
-
require "pact_broker/verifications/latest_verification_for_consumer_and_provider"
|
7
|
-
|
8
|
-
# TODO DELETE THIS!!!
|
9
|
-
|
10
|
-
module PactBroker
|
11
|
-
module Matrix
|
12
|
-
class Row < Sequel::Model(:matrix)
|
13
|
-
|
14
|
-
# Used when using table_print to output query results
|
15
|
-
TP_COLS = [ :consumer_version_number, :pact_revision_number, :provider_version_number, :verification_number]
|
16
|
-
|
17
|
-
associate(:one_to_many, :latest_triggered_webhooks, :class => "PactBroker::Webhooks::LatestTriggeredWebhook", primary_key: :pact_publication_id, key: :pact_publication_id)
|
18
|
-
associate(:one_to_many, :consumer_version_tags, :class => "PactBroker::Tags::TagWithLatestFlag", primary_key: :consumer_version_id, key: :version_id)
|
19
|
-
associate(:one_to_many, :provider_version_tags, :class => "PactBroker::Tags::TagWithLatestFlag", primary_key: :provider_version_id, key: :version_id)
|
20
|
-
|
21
|
-
many_to_one :latest_verification_for_consumer_and_provider,
|
22
|
-
:class => "PactBroker::Verifications::LatestVerificationForConsumerAndProvider",
|
23
|
-
primary_key: [:provider_id, :consumer_id], key: [:provider_id, :consumer_id]
|
24
|
-
|
25
|
-
dataset_module do
|
26
|
-
include PactBroker::Repositories::Helpers
|
27
|
-
include PactBroker::Logging
|
28
|
-
|
29
|
-
def consumer consumer_name
|
30
|
-
where(name_like(:consumer_name, consumer_name))
|
31
|
-
end
|
32
|
-
|
33
|
-
def provider provider_name
|
34
|
-
where(name_like(:provider_name, provider_name))
|
35
|
-
end
|
36
|
-
|
37
|
-
def matching_selectors selectors
|
38
|
-
if selectors.size == 1
|
39
|
-
where_consumer_or_provider_is(selectors.first)
|
40
|
-
else
|
41
|
-
where_consumer_and_provider_in(selectors)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# find rows where (the consumer (and optional version) matches any of the selectors)
|
46
|
-
# AND
|
47
|
-
# the (provider (and optional version) matches any of the selectors OR the provider matches
|
48
|
-
# and the verification is missing (and hence the provider version is null))
|
49
|
-
def where_consumer_and_provider_in selectors
|
50
|
-
where{
|
51
|
-
Sequel.&(
|
52
|
-
Sequel.|(
|
53
|
-
*QueryHelper.consumer_and_maybe_consumer_version_match_any_selector(selectors)
|
54
|
-
),
|
55
|
-
Sequel.|(
|
56
|
-
*QueryHelper.provider_and_maybe_provider_version_match_any_selector_or_verification_is_missing(selectors)
|
57
|
-
),
|
58
|
-
QueryHelper.either_consumer_or_provider_was_specified_in_query(selectors)
|
59
|
-
)
|
60
|
-
}
|
61
|
-
end
|
62
|
-
|
63
|
-
# Can't access other dataset_module methods from inside the Sequel `where{ ... }` block, so make a private class
|
64
|
-
# with some helper methods
|
65
|
-
class QueryHelper
|
66
|
-
def self.consumer_and_maybe_consumer_version_match_any_selector(selectors)
|
67
|
-
selectors.collect { |s| consumer_and_maybe_consumer_version_match_selector(s) }
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.consumer_and_maybe_consumer_version_match_selector(s)
|
71
|
-
if s[:pact_publication_ids]
|
72
|
-
Sequel.&(pact_publication_id: s[:pact_publication_ids])
|
73
|
-
elsif s[:pacticipant_version_id]
|
74
|
-
Sequel.&(consumer_id: s[:pacticipant_id], consumer_version_id: s[:pacticipant_version_id])
|
75
|
-
else
|
76
|
-
Sequel.&(consumer_id: s[:pacticipant_id])
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.provider_and_maybe_provider_version_match_selector(s)
|
81
|
-
if s[:verification_ids]
|
82
|
-
Sequel.&(verification_id: s[:verification_ids])
|
83
|
-
elsif s[:pacticipant_version_id]
|
84
|
-
Sequel.&(provider_id: s[:pacticipant_id], provider_version_id: s[:pacticipant_version_id])
|
85
|
-
else
|
86
|
-
Sequel.&(provider_id: s[:pacticipant_id])
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# if the pact for a consumer version has never been verified, it exists in the matrix as a row
|
91
|
-
# with a blank provider version id
|
92
|
-
def self.provider_verification_is_missing_for_matching_selector(s)
|
93
|
-
Sequel.&(provider_id: s[:pacticipant_id], provider_version_id: nil)
|
94
|
-
end
|
95
|
-
|
96
|
-
def self.provider_and_maybe_provider_version_match_any_selector_or_verification_is_missing(selectors)
|
97
|
-
selectors.collect { |s|
|
98
|
-
provider_and_maybe_provider_version_match_selector(s)
|
99
|
-
} + selectors.collect { |s|
|
100
|
-
provider_verification_is_missing_for_matching_selector(s)
|
101
|
-
}
|
102
|
-
end
|
103
|
-
|
104
|
-
# Some selecters are specified in the query, others are implied (when only one pacticipant is specified,
|
105
|
-
# the integrations are automatically worked out, and the selectors for these are of type :implied )
|
106
|
-
# When there are 3 pacticipants that each have dependencies on each other (A->B, A->C, B->C), the query
|
107
|
-
# to deploy C (implied A, implied B, specified C) was returning the A->B row because it matched the
|
108
|
-
# implied selectors as well.
|
109
|
-
# This extra filter makes sure that every row that is returned actually matches one of the specified
|
110
|
-
# selectors.
|
111
|
-
def self.either_consumer_or_provider_was_specified_in_query(selectors)
|
112
|
-
specified_pacticipant_ids = selectors.select{ |s| s[:type] == :specified }.collect{ |s| s[:pacticipant_id] }
|
113
|
-
Sequel.|({ consumer_id: specified_pacticipant_ids } , { provider_id: specified_pacticipant_ids })
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def where_consumer_or_provider_is s
|
118
|
-
where{
|
119
|
-
Sequel.|(
|
120
|
-
s[:pacticipant_version_id] ? Sequel.&(consumer_id: s[:pacticipant_id], consumer_version_id: s[:pacticipant_version_id]) : Sequel.&(consumer_id: s[:pacticipant_id]),
|
121
|
-
s[:pacticipant_version_id] ? Sequel.&(provider_id: s[:pacticipant_id], provider_version_id: s[:pacticipant_version_id]) : Sequel.&(provider_id: s[:pacticipant_id])
|
122
|
-
)
|
123
|
-
}
|
124
|
-
end
|
125
|
-
|
126
|
-
def order_by_names_ascending_most_recent_first
|
127
|
-
order(
|
128
|
-
Sequel.asc(:consumer_name),
|
129
|
-
Sequel.desc(:consumer_version_order),
|
130
|
-
Sequel.desc(:pact_revision_number),
|
131
|
-
Sequel.asc(:provider_name),
|
132
|
-
Sequel.desc(:provider_version_order),
|
133
|
-
Sequel.desc(:verification_id))
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
# Temporary method while we transition from returning Hashes to return Matrix objects
|
138
|
-
# from the repository find methods
|
139
|
-
# Need to make the object act as a hash and an object
|
140
|
-
def [] key
|
141
|
-
if key == :provider_version_tags || key == :consumer_version_tags
|
142
|
-
send(key)
|
143
|
-
else
|
144
|
-
super
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
def summary
|
149
|
-
"#{consumer_name}#{consumer_version_number} #{provider_name}#{provider_version_number || '?'} (r#{pact_revision_number}n#{verification_number || '?'})"
|
150
|
-
end
|
151
|
-
|
152
|
-
def consumer
|
153
|
-
@consumer ||= Domain::Pacticipant.new(name: consumer_name).tap { |pacticipant| pacticipant.id = consumer_id }
|
154
|
-
end
|
155
|
-
|
156
|
-
def provider
|
157
|
-
@provider ||= Domain::Pacticipant.new(name: provider_name).tap { |pacticipant| pacticipant.id = provider_id }
|
158
|
-
end
|
159
|
-
|
160
|
-
def consumer_version
|
161
|
-
@consumer_version ||= OpenStruct.new(number: consumer_version_number, order: consumer_version_order, id: consumer_version_id, pacticipant: consumer)
|
162
|
-
end
|
163
|
-
|
164
|
-
def provider_version
|
165
|
-
if provider_version_number
|
166
|
-
@provider_version ||= OpenStruct.new(number: provider_version_number, order: provider_version_order, id: provider_version_id, pacticipant: provider)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def pact
|
171
|
-
@pact ||= OpenStruct.new(
|
172
|
-
consumer: consumer,
|
173
|
-
provider: provider,
|
174
|
-
consumer_version: consumer_version,
|
175
|
-
consumer_version_number: consumer_version_number,
|
176
|
-
created_at: pact_created_at,
|
177
|
-
revision_number: pact_revision_number,
|
178
|
-
pact_version_sha: pact_version_sha
|
179
|
-
)
|
180
|
-
end
|
181
|
-
|
182
|
-
def verification
|
183
|
-
if verification_executed_at
|
184
|
-
@latest_verification ||= OpenStruct.new(
|
185
|
-
id: verification_id,
|
186
|
-
success: success,
|
187
|
-
number: verification_number,
|
188
|
-
execution_date: verification_executed_at,
|
189
|
-
created_at: verification_executed_at,
|
190
|
-
provider_version_number: provider_version_number,
|
191
|
-
provider_version_order: provider_version_order,
|
192
|
-
build_url: verification_build_url,
|
193
|
-
provider_version: provider_version,
|
194
|
-
consumer_name: consumer_name,
|
195
|
-
provider_name: provider_name,
|
196
|
-
pact_version_sha: pact_version_sha
|
197
|
-
)
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
# Add logic for ignoring case
|
202
|
-
def <=> other
|
203
|
-
comparisons = [
|
204
|
-
compare_name_asc(consumer_name, other.consumer_name),
|
205
|
-
compare_number_desc(consumer_version_order, other.consumer_version_order),
|
206
|
-
compare_number_desc(pact_revision_number, other.pact_revision_number),
|
207
|
-
compare_name_asc(provider_name, other.provider_name),
|
208
|
-
compare_number_desc(provider_version_order, other.provider_version_order),
|
209
|
-
compare_number_desc(verification_id, other.verification_id)
|
210
|
-
]
|
211
|
-
|
212
|
-
comparisons.find{|c| c != 0 } || 0
|
213
|
-
end
|
214
|
-
|
215
|
-
def compare_name_asc name1, name2
|
216
|
-
name1 <=> name2
|
217
|
-
end
|
218
|
-
|
219
|
-
def to_s
|
220
|
-
"#{consumer_name} #{consumer_version_number} #{provider_name} #{provider_version_number} #{success}"
|
221
|
-
end
|
222
|
-
|
223
|
-
def compare_number_desc number1, number2
|
224
|
-
if number1 && number2
|
225
|
-
number2 <=> number1
|
226
|
-
elsif number1
|
227
|
-
1
|
228
|
-
else
|
229
|
-
-1
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
# For some reason, with MySQL, the success column value
|
234
|
-
# comes back as an integer rather than a boolean
|
235
|
-
# for the latest_matrix view (but not the matrix view!)
|
236
|
-
# Maybe something to do with the union?
|
237
|
-
# Haven't investigated as this is an easy enough fix.
|
238
|
-
def success
|
239
|
-
value = super
|
240
|
-
value.nil? ? nil : value == true || value == 1
|
241
|
-
end
|
242
|
-
|
243
|
-
def values
|
244
|
-
super.merge(success: success)
|
245
|
-
end
|
246
|
-
|
247
|
-
# Need to overwrite eql? from lib/sequel/model/base.rb
|
248
|
-
# because it uses @values instead of self.values
|
249
|
-
# so the success boolean/integer problem mentioned above
|
250
|
-
# screws things up
|
251
|
-
def eql?(obj)
|
252
|
-
(obj.class == model) && (obj.values == values)
|
253
|
-
end
|
254
|
-
|
255
|
-
def pacticipant_names
|
256
|
-
[consumer_name, provider_name]
|
257
|
-
end
|
258
|
-
|
259
|
-
def involves_pacticipant_with_name?(pacticipant_name)
|
260
|
-
pacticipant_name.include?(pacticipant_name)
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
# Table: matrix
|
267
|
-
# Columns:
|
268
|
-
# consumer_id | integer |
|
269
|
-
# consumer_name | text |
|
270
|
-
# consumer_version_id | integer |
|
271
|
-
# consumer_version_number | text |
|
272
|
-
# consumer_version_order | integer |
|
273
|
-
# pact_publication_id | integer |
|
274
|
-
# pact_version_id | integer |
|
275
|
-
# pact_version_sha | text |
|
276
|
-
# pact_revision_number | integer |
|
277
|
-
# pact_created_at | timestamp without time zone |
|
278
|
-
# provider_id | integer |
|
279
|
-
# provider_name | text |
|
280
|
-
# provider_version_id | integer |
|
281
|
-
# provider_version_number | text |
|
282
|
-
# provider_version_order | integer |
|
283
|
-
# verification_id | integer |
|
284
|
-
# success | boolean |
|
285
|
-
# verification_number | integer |
|
286
|
-
# verification_executed_at | timestamp without time zone |
|
287
|
-
# verification_build_url | text |
|