diff --git a/crates/gitbutler-branch/src/assets.rs b/crates/gitbutler-branch/src/assets.rs index 2e2cb4183..e3b0b1a45 100644 --- a/crates/gitbutler-branch/src/assets.rs +++ b/crates/gitbutler-branch/src/assets.rs @@ -1,6 +1,6 @@ use futures::future::join_all; -use crate::{Author, VirtualBranch, VirtualBranchCommit}; +use crate::{VirtualBranch, VirtualBranchCommit}; #[derive(Clone)] pub struct Proxy { @@ -35,22 +35,12 @@ impl Proxy { } } - async fn proxy_author(&self, author: Author) -> Author { - Author { - gravatar_url: self.core_proxy.proxy(&author.gravatar_url).await.unwrap_or_else(|error| { - tracing::error!(gravatar_url = %author.gravatar_url, ?error, "failed to proxy gravatar url"); - author.gravatar_url - }), - ..author - } - } - async fn proxy_virtual_branch_commit( &self, commit: VirtualBranchCommit, ) -> VirtualBranchCommit { VirtualBranchCommit { - author: self.proxy_author(commit.author).await, + author: self.core_proxy.proxy_author(commit.author).await, ..commit } } diff --git a/crates/gitbutler-branch/src/virtual.rs b/crates/gitbutler-branch/src/virtual.rs index e8b6a8891..df707d0f8 100644 --- a/crates/gitbutler-branch/src/virtual.rs +++ b/crates/gitbutler-branch/src/virtual.rs @@ -4,7 +4,6 @@ use std::os::unix::prelude::PermissionsExt; use std::time::SystemTime; use std::{ collections::HashMap, - hash::Hash, path::{Path, PathBuf}, time, vec, }; @@ -15,6 +14,7 @@ use diffy::{apply_bytes as diffy_apply, Line, Patch}; use git2::build::TreeUpdateBuilder; use git2::ErrorCode; use git2_hooks::HookResult; +use gitbutler_core::virtual_branches::Author; use hex::ToHex; use serde::{Deserialize, Serialize}; @@ -195,33 +195,6 @@ impl VirtualBranchHunk { } } -#[derive(Debug, Serialize, Hash, Clone, PartialEq, Eq)] -#[serde(rename_all = "camelCase")] -pub struct Author { - pub name: String, - pub email: String, - pub gravatar_url: url::Url, -} - -impl From> for Author { - fn from(value: git2::Signature) -> Self { - let name = value.name().unwrap_or_default().to_string(); - let email = value.email().unwrap_or_default().to_string(); - - let gravatar_url = url::Url::parse(&format!( - "https://www.gravatar.com/avatar/{:x}?s=100&r=g&d=retro", - md5::compute(email.to_lowercase()) - )) - .unwrap(); - - Author { - name, - email, - gravatar_url, - } - } -} - #[derive(Default, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase", tag = "type", content = "value")] pub enum NameConflitResolution { diff --git a/crates/gitbutler-core/src/assets.rs b/crates/gitbutler-core/src/assets.rs index 7a792d35c..873c3a7ac 100644 --- a/crates/gitbutler-core/src/assets.rs +++ b/crates/gitbutler-core/src/assets.rs @@ -52,7 +52,7 @@ impl Proxy { } } - async fn proxy_author(&self, author: Author) -> Author { + pub async fn proxy_author(&self, author: Author) -> Author { Author { gravatar_url: self.proxy(&author.gravatar_url).await.unwrap_or_else(|error| { tracing::error!(gravatar_url = %author.gravatar_url, ?error, "failed to proxy gravatar url"); diff --git a/crates/gitbutler-core/src/virtual_branches/author.rs b/crates/gitbutler-core/src/virtual_branches/author.rs new file mode 100644 index 000000000..b4ee295f8 --- /dev/null +++ b/crates/gitbutler-core/src/virtual_branches/author.rs @@ -0,0 +1,28 @@ +use serde::Serialize; + +#[derive(Debug, Serialize, Hash, Clone, PartialEq, Eq)] +#[serde(rename_all = "camelCase")] +pub struct Author { + pub name: String, + pub email: String, + pub gravatar_url: url::Url, +} + +impl From> for Author { + fn from(value: git2::Signature) -> Self { + let name = value.name().unwrap_or_default().to_string(); + let email = value.email().unwrap_or_default().to_string(); + + let gravatar_url = url::Url::parse(&format!( + "https://www.gravatar.com/avatar/{:x}?s=100&r=g&d=retro", + md5::compute(email.to_lowercase()) + )) + .unwrap(); + + Author { + name, + email, + gravatar_url, + } + } +} diff --git a/crates/gitbutler-core/src/virtual_branches/mod.rs b/crates/gitbutler-core/src/virtual_branches/mod.rs index 354cb7dde..e5304d1d3 100644 --- a/crates/gitbutler-core/src/virtual_branches/mod.rs +++ b/crates/gitbutler-core/src/virtual_branches/mod.rs @@ -20,3 +20,6 @@ pub use remote::*; mod state; pub use state::VirtualBranches as VirtualBranchesState; pub use state::VirtualBranchesHandle; + +mod author; +pub use author::Author;