@@ -548,7 +548,10 @@ async fn lookup_github_username(ctx: &Context, zulip_username: &str) -> anyhow::
548
548
549
549
/// Tries to find a Zulip username from a GitHub username.
550
550
async fn lookup_zulip_username ( ctx : & Context , gh_username : & str ) -> anyhow:: Result < String > {
551
- async fn lookup_from_zulip ( ctx : & Context , gh_username : & str ) -> anyhow:: Result < Option < String > > {
551
+ async fn lookup_zulip_id_from_zulip (
552
+ ctx : & Context ,
553
+ gh_username : & str ,
554
+ ) -> anyhow:: Result < Option < u64 > > {
552
555
let username_lowercase = gh_username. to_lowercase ( ) ;
553
556
let users = get_zulip_users ( ctx. github . raw ( ) ) . await ?;
554
557
Ok ( users
@@ -559,10 +562,13 @@ async fn lookup_zulip_username(ctx: &Context, gh_username: &str) -> anyhow::Resu
559
562
. as_deref ( )
560
563
== Some ( username_lowercase. as_str ( ) )
561
564
} )
562
- . map ( |u| u. name ) )
565
+ . map ( |u| u. user_id ) )
563
566
}
564
567
565
- async fn lookup_from_team ( ctx : & Context , gh_username : & str ) -> anyhow:: Result < Option < String > > {
568
+ async fn lookup_zulip_id_from_team (
569
+ ctx : & Context ,
570
+ gh_username : & str ,
571
+ ) -> anyhow:: Result < Option < u64 > > {
566
572
let people = people ( & ctx. github ) . await ?. people ;
567
573
568
574
// Lookup the person in the team DB
@@ -579,25 +585,24 @@ async fn lookup_zulip_username(ctx: &Context, gh_username: &str) -> anyhow::Resu
579
585
let Some ( zulip_id) = to_zulip_id ( & ctx. github , person. github_id ) . await ? else {
580
586
return Ok ( None ) ;
581
587
} ;
582
- let Ok ( zulip_user) = get_zulip_user ( & ctx. github . raw ( ) , zulip_id) . await else {
583
- return Ok ( None ) ;
584
- } ;
585
- Ok ( Some ( zulip_user. name ) )
588
+ Ok ( Some ( zulip_id) )
586
589
}
587
590
588
- let zulip_username = match lookup_from_team ( ctx, gh_username) . await ? {
589
- Some ( username ) => username ,
590
- None => match lookup_from_zulip ( ctx, gh_username) . await ? {
591
- Some ( username ) => username ,
591
+ let zulip_id = match lookup_zulip_id_from_team ( ctx, gh_username) . await ? {
592
+ Some ( id ) => id ,
593
+ None => match lookup_zulip_id_from_zulip ( ctx, gh_username) . await ? {
594
+ Some ( id ) => id ,
592
595
None => {
593
596
return Ok ( format ! (
594
597
"No Zulip account found for GitHub username `{gh_username}`."
595
598
) )
596
599
}
597
600
} ,
598
601
} ;
602
+ // @**|<zulip-id>** is Zulip syntax that will render as the username (and a link) of the user
603
+ // with the given Zulip ID.
599
604
Ok ( format ! (
600
- "The GitHub user `{gh_username}` has the following Zulip account: @**{zulip_username }**"
605
+ "The GitHub user `{gh_username}` has the following Zulip account: @**|{zulip_id }**"
601
606
) )
602
607
}
603
608
@@ -658,29 +663,6 @@ async fn get_zulip_users(client: &reqwest::Client) -> anyhow::Result<Vec<ZulipUs
658
663
}
659
664
}
660
665
661
- async fn get_zulip_user ( client : & reqwest:: Client , zulip_id : u64 ) -> anyhow:: Result < ZulipUser > {
662
- let bot_api_token = env:: var ( "ZULIP_API_TOKEN" ) . expect ( "ZULIP_API_TOKEN" ) ;
663
-
664
- let resp = client
665
- . get ( & format ! ( "{}/api/v1/users/{zulip_id}" , * ZULIP_URL ) )
666
- . basic_auth ( & * ZULIP_BOT_EMAIL , Some ( & bot_api_token) )
667
- . send ( )
668
- . await ?;
669
-
670
- let status = resp. status ( ) ;
671
-
672
- if !status. is_success ( ) {
673
- let body = resp
674
- . text ( )
675
- . await
676
- . context ( "fail receiving Zulip API response (when getting Zulip user)" ) ?;
677
-
678
- anyhow:: bail!( body)
679
- } else {
680
- Ok ( resp. json :: < ZulipUser > ( ) . await ?)
681
- }
682
- }
683
-
684
666
// This does two things:
685
667
// * execute the command for the other user
686
668
// * tell the user executed for that a command was run as them by the user
0 commit comments