@@ -588,6 +588,26 @@ impl fmt::Display for UnknownLabels {
588
588
589
589
impl std:: error:: Error for UnknownLabels { }
590
590
591
+ #[ derive( Debug ) ]
592
+ pub ( crate ) struct AmbiguousLabelMatch {
593
+ pub requested_label : String ,
594
+ pub labels : Vec < String > ,
595
+ }
596
+
597
+ // NOTE: This is used to post the Github comment; make sure it's valid markdown.
598
+ impl fmt:: Display for AmbiguousLabelMatch {
599
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
600
+ write ! (
601
+ f,
602
+ "Unsure which label to use for `{}` - could be one of: {}" ,
603
+ self . requested_label,
604
+ self . labels. join( ", " )
605
+ )
606
+ }
607
+ }
608
+
609
+ impl std:: error:: Error for AmbiguousLabelMatch { }
610
+
591
611
impl Issue {
592
612
pub fn to_zulip_github_reference ( & self ) -> ZulipGitHubReference {
593
613
ZulipGitHubReference {
@@ -742,14 +762,24 @@ impl Issue {
742
762
}
743
763
744
764
// Try normalizing requested label (remove emoji, case insensitive, trim whitespace)
745
- let normalized_requested = normalize ( requested_label) ;
746
- if let Some ( found) = available_labels
765
+ let normalized_requested: String = normalize ( requested_label) ;
766
+
767
+ // Find matching labels by normalized name
768
+ let found = available_labels
747
769
. iter ( )
748
- . find ( |l| normalize ( & l. name ) == normalized_requested)
749
- {
750
- found_labels . push ( & found . name ) ;
751
- } else {
770
+ . filter ( |l| normalize ( & l. name ) == normalized_requested)
771
+ . collect :: < Vec < _ > > ( ) ;
772
+
773
+ if found . is_empty ( ) {
752
774
unknown_labels. push ( requested_label. as_str ( ) ) ;
775
+ } else if found. len ( ) > 1 {
776
+ return Err ( AmbiguousLabelMatch {
777
+ requested_label : requested_label. clone ( ) ,
778
+ labels : found. into_iter ( ) . map ( |l| l. name . clone ( ) ) . collect ( ) ,
779
+ }
780
+ . into ( ) ) ;
781
+ } else {
782
+ found_labels. push ( & found. first ( ) . unwrap ( ) . name ) ;
753
783
}
754
784
}
755
785
0 commit comments