@@ -6,6 +6,24 @@ class Repository
6
6
include PactBroker ::Repositories ::Helpers
7
7
include PactBroker ::Repositories
8
8
9
+ def find criteria
10
+ version_ids = criteria . reject { |key , value | !value } . collect do | key , value |
11
+ version_repository . find_by_pacticipant_name_and_number ( key , value ) . id
12
+ end
13
+
14
+ pacticipant_names = criteria . reject { |key , value | value } . keys
15
+
16
+ # If there is a nil provider_version_number it is because there is no verification
17
+ # but the row has been included because it is a left outer join.
18
+ # All the unverified pacts will be grouped together in the group_by because of this,
19
+ # so we include all of that group.
20
+ find_for_version_ids ( version_ids , pacticipant_names )
21
+ . group_by { |line | [ line [ :consumer_version_number ] , line [ :provider_version_number ] ] }
22
+ . values
23
+ . collect { | lines | lines . first [ :provider_version_number ] . nil? ? lines : lines . last }
24
+ . flatten
25
+ end
26
+
9
27
def find_for_consumer_and_provider pacticipant_1_name , pacticipant_2_name
10
28
find_for_version_ids ( [ ] , [ pacticipant_1_name , pacticipant_2_name ] )
11
29
. sort { |l1 , l2 | l2 [ :consumer_version_order ] <=> l1 [ :consumer_version_order ] }
@@ -17,17 +35,7 @@ def find_for_consumer_and_provider pacticipant_1_name, pacticipant_2_name
17
35
# Returns a list of matrix lines indicating the compatible versions
18
36
#
19
37
def find_compatible_pacticipant_versions criteria
20
- version_ids = criteria . reject { |key , value | !value } . collect do | key , value |
21
- version_repository . find_by_pacticipant_name_and_number ( key , value ) . id
22
- end
23
-
24
- pacticipant_names = criteria . reject { |key , value | value } . keys
25
-
26
- find_for_version_ids ( version_ids , pacticipant_names )
27
- . group_by { |line | [ line [ :consumer_version_number ] , line [ :provider_version_number ] ] }
28
- . values
29
- . collect ( &:last )
30
- . select { |line | line [ :success ] }
38
+ find ( criteria ) . select { |line | line [ :success ] }
31
39
end
32
40
33
41
def find_for_version_ids version_ids , pacticipant_names = [ ]
0 commit comments