@@ -9,8 +9,12 @@ use anyhow::{format_err, Context as _};
9
9
use std:: env;
10
10
use std:: fmt:: Write as _;
11
11
use std:: str:: FromStr ;
12
+ use std:: sync:: LazyLock ;
12
13
use tracing as log;
13
14
15
+ static ZULIP_URL : LazyLock < String > =
16
+ LazyLock :: new ( || env:: var ( "ZULIP_URL" ) . unwrap_or ( "https://rust-lang.zulipchat.com" . into ( ) ) ) ;
17
+
14
18
#[ derive( Debug , serde:: Deserialize ) ]
15
19
pub struct Request {
16
20
/// Markdown body of the sent message.
@@ -71,8 +75,6 @@ struct Response {
71
75
content : String ,
72
76
}
73
77
74
- pub const BOT_EMAIL : & str = "triage-rust-lang-bot@zulipchat.com" ;
75
-
76
78
pub async fn to_github_id ( client : & GithubClient , zulip_id : u64 ) -> anyhow:: Result < Option < u64 > > {
77
79
let map = crate :: team_data:: zulip_map ( client) . await ?;
78
80
Ok ( map. users . get ( & zulip_id) . copied ( ) )
@@ -295,12 +297,14 @@ async fn execute_for_other_user(
295
297
command
296
298
} ;
297
299
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 ( "triage-rust-lang-bot@zulipchat.com" . into ( ) ) ;
298
302
299
303
let members = ctx
300
304
. github
301
305
. 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) )
304
308
. send ( )
305
309
. await
306
310
. map_err ( |e| format_err ! ( "Failed to get list of zulip users: {e:?}." ) ) ?;
@@ -414,7 +418,7 @@ impl Recipient<'_> {
414
418
}
415
419
416
420
pub fn url ( & self ) -> String {
417
- format ! ( "https://rust-lang.zulipchat.com/ #narrow/{}" , self . narrow( ) )
421
+ format ! ( "{}/ #narrow/{}" , * ZULIP_URL , self . narrow( ) )
418
422
}
419
423
}
420
424
@@ -458,6 +462,8 @@ impl<'a> MessageApiRequest<'a> {
458
462
459
463
pub async fn send ( & self , client : & reqwest:: Client ) -> anyhow:: Result < reqwest:: Response > {
460
464
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 ( "triage-rust-lang-bot@zulipchat.com" . into ( ) ) ;
461
467
462
468
#[ derive( serde:: Serialize ) ]
463
469
struct SerializedApi < ' a > {
@@ -470,8 +476,8 @@ impl<'a> MessageApiRequest<'a> {
470
476
}
471
477
472
478
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) )
475
481
. form ( & SerializedApi {
476
482
type_ : match self . recipient {
477
483
Recipient :: Stream { .. } => "stream" ,
@@ -509,6 +515,8 @@ pub struct UpdateMessageApiRequest<'a> {
509
515
impl < ' a > UpdateMessageApiRequest < ' a > {
510
516
pub async fn send ( & self , client : & reqwest:: Client ) -> anyhow:: Result < reqwest:: Response > {
511
517
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 ( "triage-rust-lang-bot@zulipchat.com" . into ( ) ) ;
512
520
513
521
#[ derive( serde:: Serialize ) ]
514
522
struct SerializedApi < ' a > {
@@ -522,10 +530,10 @@ impl<'a> UpdateMessageApiRequest<'a> {
522
530
523
531
Ok ( client
524
532
. 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
527
535
) )
528
- . basic_auth ( BOT_EMAIL , Some ( & bot_api_token) )
536
+ . basic_auth ( bot_email , Some ( & bot_api_token) )
529
537
. form ( & SerializedApi {
530
538
topic : self . topic ,
531
539
propagate_mode : self . propagate_mode ,
@@ -712,13 +720,15 @@ struct AddReaction<'a> {
712
720
impl < ' a > AddReaction < ' a > {
713
721
pub async fn send ( self , client : & reqwest:: Client ) -> anyhow:: Result < reqwest:: Response > {
714
722
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 ( "triage-rust-lang-bot@zulipchat.com" . into ( ) ) ;
715
725
716
726
Ok ( client
717
727
. 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
720
730
) )
721
- . basic_auth ( BOT_EMAIL , Some ( & bot_api_token) )
731
+ . basic_auth ( bot_email , Some ( & bot_api_token) )
722
732
. form ( & self )
723
733
. send ( )
724
734
. await ?)
0 commit comments