@@ -134,21 +134,19 @@ def view_for(options)
134
134
end
135
135
136
136
def resolve_selectors ( selectors , options )
137
- selectors = look_up_versions_for_latest_and_tag ( selectors , options )
138
-
139
- if options [ :latest ]
140
- apply_latest_and_tag_to_inferred_selectors ( selectors , options )
137
+ resolved_selectors = look_up_version_numbers ( selectors , options )
138
+ if options [ :latest ] || options [ :tag ]
139
+ apply_latest_and_tag_to_inferred_selectors ( resolved_selectors , options )
141
140
else
142
- selectors
141
+ resolved_selectors
143
142
end
144
143
end
145
144
146
- # Find the version number for selectors with the latest (tagged) version specified
147
- def look_up_versions_for_latest_and_tag ( selectors , options )
145
+ # Find the version number for selectors with the latest and/or tag specified
146
+ def look_up_version_numbers ( selectors , options )
148
147
selectors . collect do | selector |
149
- # resource validation currently stops tag being specified without latest=true
150
148
if selector [ :tag ] && selector [ :latest ]
151
- version = version_repository . find_by_pacticpant_name_and_latest_tag ( selector [ :pacticipant_name ] , selector [ :tag ] )
149
+ version = version_repository . find_by_pacticipant_name_and_latest_tag ( selector [ :pacticipant_name ] , selector [ :tag ] )
152
150
raise Error . new ( "Could not find version with tag #{ selector [ :tag ] . inspect } for #{ selector [ :pacticipant_name ] } " ) unless version
153
151
# validation in resource should ensure we always have a version
154
152
{
@@ -161,25 +159,38 @@ def look_up_versions_for_latest_and_tag(selectors, options)
161
159
pacticipant_name : selector [ :pacticipant_name ] ,
162
160
pacticipant_version_number : version . number
163
161
}
162
+ elsif selector [ :tag ]
163
+ # validation in resource should ensure we always have at least one version
164
+ versions = version_repository . find_by_pacticipant_name_and_tag ( selector [ :pacticipant_name ] , selector [ :tag ] )
165
+ versions . collect do | version |
166
+ {
167
+ pacticipant_name : selector [ :pacticipant_name ] ,
168
+ pacticipant_version_number : version . number
169
+ }
170
+ end
164
171
else
165
172
selector . dup
166
173
end
167
- end . collect do | selector |
168
- if selector [ :pacticipant_name ]
169
- pacticipant = PactBroker ::Domain ::Pacticipant . find ( name : selector [ :pacticipant_name ] )
170
- selector [ :pacticipant_id ] = pacticipant ? pacticipant . id : nil
171
- end
174
+ end . flatten . compact . collect do | selector |
175
+ add_ids ( selector )
176
+ end
177
+ end
172
178
173
- if selector [ :pacticipant_name ] && selector [ :pacticipant_version_number ]
174
- version = version_repository . find_by_pacticipant_name_and_number ( selector [ :pacticipant_name ] , selector [ :pacticipant_version_number ] )
175
- selector [ :pacticipant_version_id ] = version ? version . id : nil
176
- end
179
+ def add_ids ( selector )
180
+ if selector [ :pacticipant_name ]
181
+ pacticipant = PactBroker ::Domain ::Pacticipant . find ( name : selector [ :pacticipant_name ] )
182
+ selector [ :pacticipant_id ] = pacticipant ? pacticipant . id : nil
183
+ end
177
184
178
- if selector [ :pacticipant_version_number ] . nil?
179
- selector [ :pacticipant_version_id ] = nil
180
- end
181
- selector
185
+ if selector [ :pacticipant_name ] && selector [ :pacticipant_version_number ]
186
+ version = version_repository . find_by_pacticipant_name_and_number ( selector [ :pacticipant_name ] , selector [ :pacticipant_version_number ] )
187
+ selector [ :pacticipant_version_id ] = version ? version . id : nil
182
188
end
189
+
190
+ if selector [ :pacticipant_version_number ] . nil?
191
+ selector [ :pacticipant_version_id ] = nil
192
+ end
193
+ selector
183
194
end
184
195
185
196
# eg. when checking to see if Foo version 2 can be deployed to prod,
@@ -190,13 +201,15 @@ def apply_latest_and_tag_to_inferred_selectors(selectors, options)
190
201
inferred_names = all_pacticipant_names - specified_names
191
202
192
203
inferred_selectors = inferred_names . collect do | pacticipant_name |
193
- {
204
+ selector = {
194
205
pacticipant_name : pacticipant_name ,
195
- latest : options [ :latest ]
196
- } . tap { |it | it [ :tag ] = options [ :tag ] if options [ :tag ] }
206
+ }
207
+ selector [ :tag ] = options [ :tag ] if options [ :tag ]
208
+ selector [ :latest ] = options [ :latest ] if options [ :latest ]
209
+ selector
197
210
end
198
211
199
- selectors + look_up_versions_for_latest_and_tag ( inferred_selectors , options )
212
+ selectors + look_up_version_numbers ( inferred_selectors , options )
200
213
end
201
214
202
215
def all_pacticipant_names_in_specified_matrix ( selectors , options )
0 commit comments