@@ -19,14 +19,14 @@ def can_provide_badge_using_redirect?
19
19
PactBroker . configuration . badge_provider_mode == :redirect && !!PactBroker . configuration . shields_io_base_url
20
20
end
21
21
22
- def pact_verification_badge pact , label , initials , pseudo_branch_verification_status
22
+ def pact_verification_badge pact , label , initials , pseudo_branch_verification_status , metadata = { }
23
23
return static_svg ( pact , pseudo_branch_verification_status ) unless pact
24
24
25
- dynamic_svg ( pact , label , initials , pseudo_branch_verification_status ) || static_svg ( pact , pseudo_branch_verification_status )
25
+ dynamic_svg ( pact , label , initials , pseudo_branch_verification_status , metadata ) || static_svg ( pact , pseudo_branch_verification_status )
26
26
end
27
27
28
- def pact_verification_badge_url ( pact , label , initials , pseudo_branch_verification_status )
29
- title = badge_title ( pact , label , initials )
28
+ def pact_verification_badge_url ( pact , label , initials , pseudo_branch_verification_status , metadata = { } )
29
+ title = badge_title ( pact , label , initials , metadata )
30
30
status = badge_status ( pseudo_branch_verification_status )
31
31
color = badge_color ( pseudo_branch_verification_status )
32
32
build_shield_io_uri ( title , status , color )
@@ -38,23 +38,26 @@ def clear_cache
38
38
39
39
private
40
40
41
- def badge_title pact , label , initials
41
+ def badge_title pact , label , initials , metadata
42
42
return 'pact not found' if pact . nil?
43
+ consumer_name = prepare_name ( pact . consumer_name , initials , metadata [ :consumer_tag ] )
44
+ provider_name = prepare_name ( pact . provider_name , initials , metadata [ :provider_tag ] )
43
45
title = case ( label || '' ) . downcase
44
- when 'consumer' then prepare_name ( pact . consumer_name , initials )
45
- when 'provider' then prepare_name ( pact . provider_name , initials )
46
- else "#{ prepare_name ( pact . consumer_name , initials ) } %2F#{ prepare_name ( pact . provider_name , initials ) } "
46
+ when 'consumer' then consumer_name
47
+ when 'provider' then provider_name
48
+ else "#{ consumer_name } %2F#{ provider_name } "
47
49
end
48
50
"#{ title } pact" . downcase
49
51
end
50
52
51
- def prepare_name name , initials
53
+ def prepare_name name , initials , tag = nil
54
+ tag_suffix = tag ? " (#{ tag } )" : ''
52
55
if initials
53
56
parts = split_space_dash_underscore ( name )
54
57
parts = split_camel_case ( name ) if parts . size == 1
55
- return parts . collect { |p | p [ 0 ] } . join . downcase if parts . size > 1
58
+ return parts . collect { |p | p [ 0 ] } . join . downcase + tag_suffix if parts . size > 1
56
59
end
57
- name . downcase
60
+ name . downcase + tag_suffix
58
61
end
59
62
60
63
def split_space_dash_underscore name
@@ -86,9 +89,9 @@ def badge_color pseudo_branch_verification_status
86
89
end
87
90
end
88
91
89
- def dynamic_svg pact , label , initials , pseudo_branch_verification_status
92
+ def dynamic_svg pact , label , initials , pseudo_branch_verification_status , metadata
90
93
return nil unless PactBroker . configuration . shields_io_base_url
91
- uri = pact_verification_badge_url ( pact , label , initials , pseudo_branch_verification_status )
94
+ uri = pact_verification_badge_url ( pact , label , initials , pseudo_branch_verification_status , metadata )
92
95
begin
93
96
response = do_request ( uri )
94
97
response . code == '200' ? response . body : nil
0 commit comments