Skip to main content

gitfox_client/models/
user.rs

1use serde::{Deserialize, Serialize};
2
3/// The authenticated principal, as reported by `GET /api/v1/user`.
4///
5/// Every field is optional because self-hosted GitFox instances of different
6/// versions populate slightly different subsets, and `gf auth status` must not
7/// fail just because one of them is missing.
8#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9pub struct User {
10    /// The principal id — what pull request filters such as `reviewer_id`
11    /// take.
12    #[serde(default)]
13    pub id: Option<i64>,
14    #[serde(default, alias = "uid", alias = "user_id")]
15    pub uid: Option<String>,
16    #[serde(default)]
17    pub email: Option<String>,
18    #[serde(default, alias = "display_name")]
19    pub display_name: Option<String>,
20    #[serde(default)]
21    pub admin: Option<bool>,
22}
23
24impl User {
25    /// The best available name for display purposes.
26    pub fn label(&self) -> String {
27        self.display_name
28            .clone()
29            .or_else(|| self.uid.clone())
30            .or_else(|| self.email.clone())
31            .unwrap_or_else(|| "(unknown)".to_string())
32    }
33}