2
2
require 'pact_broker/matrix/row'
3
3
require 'pact_broker/matrix/head_row'
4
4
require 'pact_broker/error'
5
-
5
+ require 'pact_broker/matrix/query_results'
6
+ require 'pact_broker/matrix/integration'
7
+ require 'pact_broker/matrix/query_results_with_deployment_status_summary'
6
8
7
9
module PactBroker
8
10
module Matrix
@@ -65,7 +67,8 @@ def find_ids_for_pacticipant_names params
65
67
66
68
# Return the latest matrix row (pact/verification) for each consumer_version_number/provider_version_number
67
69
def find selectors , options = { }
68
- lines = query_matrix ( resolve_selectors ( selectors , options ) , options )
70
+ resolved_selectors = resolve_selectors ( selectors , options )
71
+ lines = query_matrix ( resolved_selectors , options )
69
72
lines = apply_latestby ( options , selectors , lines )
70
73
71
74
# This needs to be done after the latestby, so can't be done in the db unless
@@ -74,9 +77,31 @@ def find selectors, options = {}
74
77
lines = lines . select { |l | options [ :success ] . include? ( l . success ) }
75
78
end
76
79
77
- lines . sort
80
+ QueryResults . new ( lines . sort , selectors , options , resolved_selectors )
81
+ end
82
+
83
+ def find_for_consumer_and_provider pacticipant_1_name , pacticipant_2_name
84
+ selectors = [ { pacticipant_name : pacticipant_1_name } , { pacticipant_name : pacticipant_2_name } ]
85
+ options = { latestby : 'cvpv' }
86
+ find ( selectors , options )
87
+ end
88
+
89
+ def find_compatible_pacticipant_versions selectors
90
+ find ( selectors , latestby : 'cvpv' ) . select { |line | line . success }
91
+ end
92
+
93
+ def find_integrations ( pacticipant_names )
94
+ selectors = pacticipant_names . collect { | pacticipant_name | add_ids ( pacticipant_name : pacticipant_name ) }
95
+ Row
96
+ . select ( :consumer_name , :consumer_id , :provider_name , :provider_id )
97
+ . matching_selectors ( selectors )
98
+ . distinct
99
+ . all
100
+ . collect { |row | Integration . from_hash ( row . to_hash ) } . uniq
78
101
end
79
102
103
+ private
104
+
80
105
def apply_latestby options , selectors , lines
81
106
return lines unless options [ :latestby ]
82
107
group_by_columns = case options [ :latestby ]
@@ -106,16 +131,6 @@ def remove_overwritten_revisions lines
106
131
latest_revisions
107
132
end
108
133
109
- def find_for_consumer_and_provider pacticipant_1_name , pacticipant_2_name
110
- selectors = [ { pacticipant_name : pacticipant_1_name } , { pacticipant_name : pacticipant_2_name } ]
111
- options = { latestby : 'cvpv' }
112
- find ( selectors , options )
113
- end
114
-
115
- def find_compatible_pacticipant_versions selectors
116
- find ( selectors , latestby : 'cvpv' ) . select { |line | line . success }
117
- end
118
-
119
134
def query_matrix selectors , options
120
135
query = view_for ( options ) . select_all . matching_selectors ( selectors )
121
136
query = query . limit ( options [ :limit ] ) if options [ :limit ]
@@ -195,7 +210,7 @@ def add_ids(selector)
195
210
# eg. when checking to see if Foo version 2 can be deployed to prod,
196
211
# need to look up all the 'partner' pacticipants, and determine their latest prod versions
197
212
def apply_latest_and_tag_to_inferred_selectors ( selectors , options )
198
- all_pacticipant_names = all_pacticipant_names_in_specified_matrix ( selectors , options )
213
+ all_pacticipant_names = all_pacticipant_names_in_specified_matrix ( selectors )
199
214
specified_names = selectors . collect { |s | s [ :pacticipant_name ] }
200
215
inferred_names = all_pacticipant_names - specified_names
201
216
@@ -211,12 +226,9 @@ def apply_latest_and_tag_to_inferred_selectors(selectors, options)
211
226
selectors + look_up_version_numbers ( inferred_selectors , options )
212
227
end
213
228
214
- def all_pacticipant_names_in_specified_matrix ( selectors , options )
215
- query = view_for ( options ) . select ( :consumer_name , :provider_name )
216
- query = query . matching_selectors ( selectors )
217
- query
218
- . all
219
- . collect { | row | [ row . consumer_name , row . provider_name ] }
229
+ def all_pacticipant_names_in_specified_matrix ( selectors )
230
+ find_integrations ( selectors . collect { |s | s [ :pacticipant_name ] } )
231
+ . collect ( &:pacticipant_names )
220
232
. flatten
221
233
. uniq
222
234
end
0 commit comments