@@ -5,12 +5,11 @@ mod commands;
55use crate :: db:: notifications:: add_metadata;
66use crate :: db:: notifications:: { self , delete_ping, move_indices, record_ping, Identifier } ;
77use crate :: db:: review_prefs:: { get_review_prefs, upsert_review_prefs, RotationMode } ;
8- use crate :: github:: { get_id_for_username , User } ;
8+ use crate :: github:: User ;
99use crate :: handlers:: docs_update:: docs_update;
1010use crate :: handlers:: pr_tracking:: get_assigned_prs;
1111use crate :: handlers:: project_goals:: { self , ping_project_goals_owners} ;
1212use crate :: handlers:: Context ;
13- use crate :: team_data:: TeamApiClient ;
1413use crate :: utils:: pluralize;
1514use crate :: zulip:: api:: { MessageApiResponse , Recipient } ;
1615use crate :: zulip:: client:: ZulipClient ;
@@ -83,33 +82,6 @@ struct Response {
8382 content : String ,
8483}
8584
86- pub async fn to_github_id ( client : & TeamApiClient , zulip_id : u64 ) -> anyhow:: Result < Option < u64 > > {
87- let map = client. zulip_map ( ) . await ?;
88- Ok ( map. users . get ( & zulip_id) . copied ( ) )
89- }
90-
91- pub async fn username_from_gh_id (
92- client : & TeamApiClient ,
93- gh_id : u64 ,
94- ) -> anyhow:: Result < Option < String > > {
95- let people_map = client. people ( ) . await ?;
96- Ok ( people_map
97- . people
98- . into_iter ( )
99- . filter ( |( _, p) | p. github_id == gh_id)
100- . map ( |p| p. 0 )
101- . next ( ) )
102- }
103-
104- pub async fn to_zulip_id ( client : & TeamApiClient , github_id : u64 ) -> anyhow:: Result < Option < u64 > > {
105- let map = client. zulip_map ( ) . await ?;
106- Ok ( map
107- . users
108- . iter ( )
109- . find ( |& ( _, & github) | github == github_id)
110- . map ( |v| * v. 0 ) )
111- }
112-
11385/// Top-level handler for Zulip webhooks.
11486///
11587/// Returns a JSON response.
@@ -157,7 +129,7 @@ async fn process_zulip_request(ctx: &Context, req: Request) -> anyhow::Result<Op
157129 log:: trace!( "zulip hook: {req:?}" ) ;
158130
159131 // Zulip commands are only available to users in the team database
160- let gh_id = match to_github_id ( & ctx. team_api , req. message . sender_id ) . await {
132+ let gh_id = match ctx. team_api . zulip_to_github_id ( req. message . sender_id ) . await {
161133 Ok ( Some ( gh_id) ) => gh_id,
162134 Ok ( None ) => {
163135 return Err ( anyhow:: anyhow!(
@@ -187,7 +159,9 @@ async fn handle_command<'a>(
187159 let mut impersonated = false ;
188160 if let Some ( & "as" ) = words. get ( 0 ) {
189161 if let Some ( username) = words. get ( 1 ) {
190- let impersonated_gh_id = match get_id_for_username ( & ctx. github , username)
162+ let impersonated_gh_id = match ctx
163+ . team_api
164+ . get_gh_id_from_username ( username)
191165 . await
192166 . context ( "getting ID of github user" ) ?
193167 {
@@ -228,7 +202,9 @@ async fn handle_command<'a>(
228202
229203 // Let the impersonated person know about the impersonation if the command was sensitive
230204 if impersonated && is_sensitive_command ( & cmd) {
231- let impersonated_zulip_id = to_zulip_id ( & ctx. github , gh_id)
205+ let impersonated_zulip_id = ctx
206+ . team_api
207+ . github_to_zulip_id ( gh_id)
232208 . await ?
233209 . ok_or_else ( || anyhow:: anyhow!( "Zulip user for GitHub ID {gh_id} was not found" ) ) ?;
234210 let users = ctx. zulip . get_zulip_users ( ) . await ?;
@@ -332,7 +308,9 @@ async fn workqueue_commands(
332308) -> anyhow:: Result < Option < String > > {
333309 let db_client = ctx. db . get ( ) . await ;
334310
335- let gh_username = username_from_gh_id ( & ctx. team_api , gh_id)
311+ let gh_username = ctx
312+ . team_api
313+ . username_from_gh_id ( gh_id)
336314 . await ?
337315 . ok_or_else ( || anyhow:: anyhow!( "Cannot find your GitHub username in the team database" ) ) ?;
338316 let user = User {
@@ -440,7 +418,9 @@ async fn workqueue_commands(
440418
441419/// The `whoami` command displays the user's membership in Rust teams.
442420async fn whoami_cmd ( ctx : & Context , gh_id : u64 ) -> anyhow:: Result < Option < String > > {
443- let gh_username = username_from_gh_id ( & ctx. team_api , gh_id)
421+ let gh_username = ctx
422+ . team_api
423+ . username_from_gh_id ( gh_id)
444424 . await ?
445425 . ok_or_else ( || anyhow:: anyhow!( "Cannot find your GitHub username in the team database" ) ) ?;
446426 let teams = ctx
@@ -531,10 +511,10 @@ async fn lookup_github_username(ctx: &Context, zulip_username: &str) -> anyhow::
531511 Some ( name) => name. to_string ( ) ,
532512 None => {
533513 let zulip_id = zulip_user. user_id ;
534- let Some ( gh_id) = to_github_id ( & ctx. team_api , zulip_id) . await ? else {
514+ let Some ( gh_id) = ctx. team_api . zulip_to_github_id ( zulip_id) . await ? else {
535515 return Ok ( format ! ( "Zulip user {zulip_username} was not found in team Zulip mapping. Maybe they do not have zulip-id configured in team." ) ) ;
536516 } ;
537- let Some ( username) = username_from_gh_id ( & ctx. team_api , gh_id) . await ? else {
517+ let Some ( username) = ctx. team_api . username_from_gh_id ( gh_id) . await ? else {
538518 return Ok ( format ! (
539519 "Zulip user {zulip_username} was not found in the team database."
540520 ) ) ;
@@ -593,7 +573,7 @@ async fn lookup_zulip_username(ctx: &Context, gh_username: &str) -> anyhow::Resu
593573 return Ok ( None ) ;
594574 } ;
595575
596- let Some ( zulip_id) = to_zulip_id ( & ctx. team_api , person. github_id ) . await ? else {
576+ let Some ( zulip_id) = ctx. team_api . github_to_zulip_id ( person. github_id ) . await ? else {
597577 return Ok ( None ) ;
598578 } ;
599579 Ok ( Some ( zulip_id) )
0 commit comments