mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-30 01:17:37 +03:00
feat: update user name field to be optional in User struct and User type to handle cases where name or given_name is not available
This commit is contained in:
parent
0976cd294a
commit
41d0494b73
@ -887,7 +887,7 @@ fn write_gb_commit(
|
||||
let comitter = git::Signature::now("gitbutler", "gitbutler@localhost")?;
|
||||
let author = match user {
|
||||
None => comitter.clone(),
|
||||
Some(user) => git::Signature::now(user.name.as_str(), user.email.as_str())?,
|
||||
Some(user) => git::Signature::try_from(user)?,
|
||||
};
|
||||
|
||||
let current_refname: git::Refname = "refs/heads/current".parse().unwrap();
|
||||
|
@ -34,9 +34,19 @@ impl TryFrom<&users::User> for Signature<'_> {
|
||||
type Error = super::Error;
|
||||
|
||||
fn try_from(value: &users::User) -> Result<Self, Self::Error> {
|
||||
git2::Signature::now(&value.name, &value.email)
|
||||
.map(Into::into)
|
||||
.map_err(Into::into)
|
||||
if let Some(name) = &value.name {
|
||||
git2::Signature::now(&name, &value.email)
|
||||
.map(Into::into)
|
||||
.map_err(Into::into)
|
||||
} else if let Some(name) = &value.given_name {
|
||||
git2::Signature::now(&name, &value.email)
|
||||
.map(Into::into)
|
||||
.map_err(Into::into)
|
||||
} else {
|
||||
git2::Signature::now(&value.email, &value.email)
|
||||
.map(Into::into)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,10 +40,21 @@ pub fn init(package_info: &PackageInfo) -> ClientInitGuard {
|
||||
/// Sets the current user in the Sentry scope.
|
||||
/// There is only one scope in the application, so this will overwrite any previous user.
|
||||
pub fn configure_scope(user: Option<&users::User>) {
|
||||
let name = match user {
|
||||
Some(user) => match user.name {
|
||||
Some(ref name) => Some(name.clone()),
|
||||
None => match user.given_name {
|
||||
Some(ref given_name) => Some(given_name.clone()),
|
||||
None => None,
|
||||
},
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
|
||||
sentry::configure_scope(|scope| {
|
||||
scope.set_user(user.map(|user| sentry::User {
|
||||
id: Some(user.id.to_string()),
|
||||
username: Some(user.name.clone()),
|
||||
username: name,
|
||||
email: Some(user.email.clone()),
|
||||
..Default::default()
|
||||
}));
|
||||
|
@ -35,7 +35,7 @@ impl Default for Suite {
|
||||
impl Suite {
|
||||
pub fn sign_in(&self) -> users::User {
|
||||
let user = users::User {
|
||||
name: "test".to_string(),
|
||||
name: Some("test".to_string()),
|
||||
email: "test@email.com".to_string(),
|
||||
access_token: "token".to_string(),
|
||||
..Default::default()
|
||||
|
@ -5,7 +5,7 @@ use crate::git;
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
|
||||
pub struct User {
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
pub name: Option<String>,
|
||||
pub given_name: Option<String>,
|
||||
pub family_name: Option<String>,
|
||||
pub email: String,
|
||||
@ -23,6 +23,12 @@ impl TryFrom<User> for git::Signature<'_> {
|
||||
type Error = git::Error;
|
||||
|
||||
fn try_from(value: User) -> Result<Self, Self::Error> {
|
||||
git::Signature::now(&value.name, &value.email)
|
||||
if let Some(name) = value.name {
|
||||
git::Signature::now(&name, &value.email)
|
||||
} else if let Some(name) = value.given_name {
|
||||
git::Signature::now(&name, &value.email)
|
||||
} else {
|
||||
git::Signature::now(&value.email, &value.email)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ export type LoginToken = {
|
||||
|
||||
export type User = {
|
||||
id: number;
|
||||
name: string;
|
||||
name: string | undefined;
|
||||
given_name: string | undefined;
|
||||
family_name: string | undefined;
|
||||
email: string;
|
||||
|
Loading…
Reference in New Issue
Block a user