@@ -518,36 +518,43 @@ pub fn make_gist<'a>(
518
518
)
519
519
}
520
520
521
- pub fn update_labels ( issue : & hubcaps:: issues:: IssueRef , add : & [ String ] , remove : & [ String ] ) {
522
- let l = issue. labels ( ) ;
521
+ pub fn update_labels ( issueref : & hubcaps:: issues:: IssueRef , add : & [ String ] , remove : & [ String ] ) {
522
+ let l = issueref. labels ( ) ;
523
+ let issue = issueref. get ( ) . expect ( "Failed to get issue" ) ;
523
524
524
- let existing: Vec < String > = issue
525
- . get ( )
526
- . unwrap ( )
527
- . labels
528
- . iter ( )
529
- . map ( |l| l. name . clone ( ) )
530
- . collect ( ) ;
531
- info ! ( "Already: {:?}" , existing) ;
525
+ let existing: Vec < String > = issue. labels . iter ( ) . map ( |l| l. name . clone ( ) ) . collect ( ) ;
532
526
533
- let to_add = add
527
+ let to_add: Vec < & str > = add
534
528
. iter ( )
535
529
. filter ( |l| !existing. contains ( l) ) // Remove labels already on the issue
536
530
. map ( |l| l. as_ref ( ) )
537
531
. collect ( ) ;
538
- info ! ( "Adding labels: {:?}" , to_add) ;
539
532
540
533
let to_remove: Vec < String > = remove
541
534
. iter ( )
542
535
. filter ( |l| existing. contains ( l) ) // Remove labels already on the issue
543
536
. cloned ( )
544
537
. collect ( ) ;
545
- info ! ( "Removing labels: {:?}" , to_remove) ;
546
538
547
- l. add ( to_add) . expect ( "Failed to add tags" ) ;
539
+ info ! (
540
+ "Labeling issue #{}: + {:?} , - {:?}, = {:?}" ,
541
+ issue. id, to_add, to_remove, existing
542
+ ) ;
543
+
544
+ l. add ( to_add. clone ( ) ) . unwrap_or_else ( |e| {
545
+ panic ! (
546
+ "Failed to add labels {:?} to issue #{}: {:?}" ,
547
+ to_add, issue. id, e
548
+ )
549
+ } ) ;
548
550
549
551
for label in to_remove {
550
- l. remove ( & label) . expect ( "Failed to remove tag" ) ;
552
+ l. remove ( & label) . unwrap_or_else ( |e| {
553
+ panic ! (
554
+ "Failed to remove label {:?} from issue #{}: {:?}" ,
555
+ label, issue. id, e
556
+ )
557
+ } ) ;
551
558
}
552
559
}
553
560
0 commit comments