@@ -9,8 +9,12 @@ use anyhow::{format_err, Context as _};
99use std:: env;
1010use std:: fmt:: Write as _;
1111use std:: str:: FromStr ;
12+ use std:: sync:: LazyLock ;
1213use tracing as log;
1314
15+ static ZULIP_URL : LazyLock < String > =
16+ LazyLock :: new ( || env:: var ( "ZULIP_URL" ) . unwrap_or ( "https://rust-lang.zulipchat.com" . into ( ) ) ) ;
17+
1418#[ derive( Debug , serde:: Deserialize ) ]
1519pub struct Request {
1620 /// Markdown body of the sent message.
@@ -71,8 +75,6 @@ struct Response {
7175 content : String ,
7276}
7377
74- pub const BOT_EMAIL : & str =
"[email protected] " ; 75-
7678pub async fn to_github_id ( client : & GithubClient , zulip_id : u64 ) -> anyhow:: Result < Option < u64 > > {
7779 let map = crate :: team_data:: zulip_map ( client) . await ?;
7880 Ok ( map. users . get ( & zulip_id) . copied ( ) )
@@ -295,12 +297,14 @@ async fn execute_for_other_user(
295297 command
296298 } ;
297299 let bot_api_token = env:: var ( "ZULIP_API_TOKEN" ) . expect ( "ZULIP_API_TOKEN" ) ;
300+ let bot_email =
301+ env
:: var ( "ZULIP_BOT_EMAIL" ) . unwrap_or ( "[email protected] " . into ( ) ) ; 298302
299303 let members = ctx
300304 . github
301305 . raw ( )
302- . get ( "https://rust-lang.zulipchat.com/ api/v1/users")
303- . basic_auth ( BOT_EMAIL , Some ( & bot_api_token) )
306+ . get ( format ! ( "{}/ api/v1/users", * ZULIP_URL ) )
307+ . basic_auth ( bot_email , Some ( & bot_api_token) )
304308 . send ( )
305309 . await
306310 . map_err ( |e| format_err ! ( "Failed to get list of zulip users: {e:?}." ) ) ?;
@@ -414,7 +418,7 @@ impl Recipient<'_> {
414418 }
415419
416420 pub fn url ( & self ) -> String {
417- format ! ( "https://rust-lang.zulipchat.com/ #narrow/{}" , self . narrow( ) )
421+ format ! ( "{}/ #narrow/{}" , * ZULIP_URL , self . narrow( ) )
418422 }
419423}
420424
@@ -458,6 +462,8 @@ impl<'a> MessageApiRequest<'a> {
458462
459463 pub async fn send ( & self , client : & reqwest:: Client ) -> anyhow:: Result < reqwest:: Response > {
460464 let bot_api_token = env:: var ( "ZULIP_API_TOKEN" ) . expect ( "ZULIP_API_TOKEN" ) ;
465+ let bot_email =
466+ env
:: var ( "ZULIP_BOT_EMAIL" ) . unwrap_or ( "[email protected] " . into ( ) ) ; 461467
462468 #[ derive( serde:: Serialize ) ]
463469 struct SerializedApi < ' a > {
@@ -470,8 +476,8 @@ impl<'a> MessageApiRequest<'a> {
470476 }
471477
472478 Ok ( client
473- . post ( "https://rust-lang.zulipchat.com/ api/v1/messages")
474- . basic_auth ( BOT_EMAIL , Some ( & bot_api_token) )
479+ . post ( format ! ( "{}/ api/v1/messages", * ZULIP_URL ) )
480+ . basic_auth ( bot_email , Some ( & bot_api_token) )
475481 . form ( & SerializedApi {
476482 type_ : match self . recipient {
477483 Recipient :: Stream { .. } => "stream" ,
@@ -509,6 +515,8 @@ pub struct UpdateMessageApiRequest<'a> {
509515impl < ' a > UpdateMessageApiRequest < ' a > {
510516 pub async fn send ( & self , client : & reqwest:: Client ) -> anyhow:: Result < reqwest:: Response > {
511517 let bot_api_token = env:: var ( "ZULIP_API_TOKEN" ) . expect ( "ZULIP_API_TOKEN" ) ;
518+ let bot_email =
519+ env
:: var ( "ZULIP_BOT_EMAIL" ) . unwrap_or ( "[email protected] " . into ( ) ) ; 512520
513521 #[ derive( serde:: Serialize ) ]
514522 struct SerializedApi < ' a > {
@@ -522,10 +530,10 @@ impl<'a> UpdateMessageApiRequest<'a> {
522530
523531 Ok ( client
524532 . patch ( & format ! (
525- "https://rust-lang.zulipchat.com /api/v1/messages/{}" ,
526- self . message_id
533+ "{} /api/v1/messages/{}" ,
534+ * ZULIP_URL , self . message_id
527535 ) )
528- . basic_auth ( BOT_EMAIL , Some ( & bot_api_token) )
536+ . basic_auth ( bot_email , Some ( & bot_api_token) )
529537 . form ( & SerializedApi {
530538 topic : self . topic ,
531539 propagate_mode : self . propagate_mode ,
@@ -712,13 +720,15 @@ struct AddReaction<'a> {
712720impl < ' a > AddReaction < ' a > {
713721 pub async fn send ( self , client : & reqwest:: Client ) -> anyhow:: Result < reqwest:: Response > {
714722 let bot_api_token = env:: var ( "ZULIP_API_TOKEN" ) . expect ( "ZULIP_API_TOKEN" ) ;
723+ let bot_email =
724+ env
:: var ( "ZULIP_BOT_EMAIL" ) . unwrap_or ( "[email protected] " . into ( ) ) ; 715725
716726 Ok ( client
717727 . post ( & format ! (
718- "https://rust-lang.zulipchat.com /api/v1/messages/{}/reactions" ,
719- self . message_id
728+ "{} /api/v1/messages/{}/reactions" ,
729+ * ZULIP_URL , self . message_id
720730 ) )
721- . basic_auth ( BOT_EMAIL , Some ( & bot_api_token) )
731+ . basic_auth ( bot_email , Some ( & bot_api_token) )
722732 . form ( & self )
723733 . send ( )
724734 . await ?)
0 commit comments