@@ -547,30 +547,13 @@ where
547547 }
548548}
549549
550- #[ derive( Debug ) ]
551- pub enum AssignmentError {
552- InvalidAssignee ,
553- Http ( anyhow:: Error ) ,
554- }
555-
556550#[ derive( Debug ) ]
557551pub enum Selection < ' a , T : ?Sized > {
558552 All ,
559553 One ( & ' a T ) ,
560554 Except ( & ' a T ) ,
561555}
562556
563- impl fmt:: Display for AssignmentError {
564- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
565- match self {
566- AssignmentError :: InvalidAssignee => write ! ( f, "invalid assignee" ) ,
567- AssignmentError :: Http ( e) => write ! ( f, "cannot assign: {e}" ) ,
568- }
569- }
570- }
571-
572- impl std:: error:: Error for AssignmentError { }
573-
574557#[ derive( Debug , Clone , PartialEq , Eq ) ]
575558pub struct IssueRepository {
576559 pub organization : String ,
@@ -889,7 +872,7 @@ impl Issue {
889872 & self ,
890873 client : & GithubClient ,
891874 selection : Selection < ' _ , str > ,
892- ) -> Result < ( ) , AssignmentError > {
875+ ) -> anyhow :: Result < ( ) > {
893876 log:: info!( "remove {:?} assignees for {}" , selection, self . global_id( ) ) ;
894877 let url = format ! (
895878 "{repo_url}/issues/{number}/assignees" ,
@@ -916,20 +899,18 @@ impl Issue {
916899 struct AssigneeReq < ' a > {
917900 assignees : & ' a [ & ' a str ] ,
918901 }
902+
919903 client
920904 . send_req ( client. delete ( & url) . json ( & AssigneeReq {
921905 assignees : & assignees[ ..] ,
922906 } ) )
923907 . await
924- . map_err ( AssignmentError :: Http ) ?;
908+ . context ( "failed to remove assignees" ) ?;
909+
925910 Ok ( ( ) )
926911 }
927912
928- pub async fn add_assignee (
929- & self ,
930- client : & GithubClient ,
931- user : & str ,
932- ) -> Result < ( ) , AssignmentError > {
913+ pub async fn add_assignee ( & self , client : & GithubClient , user : & str ) -> anyhow:: Result < ( ) > {
933914 log:: info!( "add_assignee {} for {}" , user, self . global_id( ) ) ;
934915 let url = format ! (
935916 "{repo_url}/issues/{number}/assignees" ,
@@ -944,27 +925,23 @@ impl Issue {
944925
945926 let result: Issue = client
946927 . json ( client. post ( & url) . json ( & AssigneeReq { assignees : & [ user] } ) )
947- . await
948- . map_err ( AssignmentError :: Http ) ? ;
928+ . await ? ;
929+
949930 // Invalid assignees are silently ignored. We can just check if the user is now
950931 // contained in the assignees list.
951932 let success = result
952933 . assignees
953934 . iter ( )
954935 . any ( |u| u. login . as_str ( ) . to_lowercase ( ) == user. to_lowercase ( ) ) ;
955936
956- if success {
957- Ok ( ( ) )
958- } else {
959- Err ( AssignmentError :: InvalidAssignee )
937+ if !success {
938+ anyhow:: bail!( UserError :: InvalidAssignee ) ;
960939 }
940+
941+ Ok ( ( ) )
961942 }
962943
963- pub async fn set_assignee (
964- & self ,
965- client : & GithubClient ,
966- user : & str ,
967- ) -> Result < ( ) , AssignmentError > {
944+ pub async fn set_assignee ( & self , client : & GithubClient , user : & str ) -> anyhow:: Result < ( ) > {
968945 log:: info!( "set_assignee for {} to {}" , self . global_id( ) , user) ;
969946 self . add_assignee ( client, user) . await ?;
970947 self . remove_assignees ( client, Selection :: Except ( user) )
0 commit comments