diff --git a/src/main.rs b/src/main.rs index 20e8930c2..5a0085d4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ const USER_AGENT: &str = "https://github.com/rust-lang/team (infra@rust-lang.org use data::Data; use schema::{Email, Team, TeamKind}; +use zulip::ZulipApi; use crate::schema::RepoPermission; use anyhow::{bail, format_err, Error}; @@ -292,8 +293,23 @@ fn run() -> Result<(), Error> { println!(); println!("github: @{}", person.github()); + if let Some(zulip_id) = person.zulip_id() { + let zulip = ZulipApi::new(); + match zulip.require_auth() { + Ok(()) => match zulip.get_user(zulip_id) { + Ok(user) => println!("zulip: {} ({zulip_id})", user.name), + Err(err) => { + println!("zulip_id: {zulip_id} # Failed to look up Zulip name: {err}") + } + }, + Err(err) => { + // We have no authentication credentials, so don't even attempt the network access. + println!("zulip_id: {zulip_id} # Skipped name lookup: {err}"); + } + } + } if let Email::Present(email) = person.email() { - println!("email: {}", email); + println!("email: {}", email); } println!(); diff --git a/src/zulip.rs b/src/zulip.rs index 6cf459a97..058116857 100644 --- a/src/zulip.rs +++ b/src/zulip.rs @@ -36,11 +36,7 @@ impl ZulipApi { pub(crate) fn require_auth(&self) -> Result<(), Error> { if self.auth.is_none() { - bail!( - "missing {} and/or {} environment variables", - USER_VAR, - TOKEN_VAR - ); + bail!("missing {USER_VAR} and/or {TOKEN_VAR} environment variables"); } Ok(()) } @@ -56,6 +52,17 @@ impl ZulipApi { Ok(response) } + /// Get a single user of the Rust Zulip instance + pub(crate) fn get_user(&self, user_id: u64) -> Result { + let response = self + .req(Method::GET, &format!("/users/{user_id}"), None)? + .error_for_status()? + .json::()? + .user; + + Ok(response) + } + /// Perform a request against the Zulip API fn req( &self, @@ -78,12 +85,18 @@ impl ZulipApi { } } -/// A collection of Zulip users +/// A collection of Zulip users, as returned from '/users' #[derive(Deserialize)] struct ZulipUsers { members: Vec, } +/// A collection of exactly one Zulip user, as returned from '/users/{user_id}' +#[derive(Deserialize)] +struct ZulipOneUser { + user: ZulipUser, +} + /// A single Zulip user #[derive(Clone, Deserialize, PartialEq, Eq, Hash)] pub(crate) struct ZulipUser {