move author to core

This commit is contained in:
Kiril Videlov 2024-07-07 16:13:06 +02:00
parent 7627a41c89
commit 41f28383a0
No known key found for this signature in database
GPG Key ID: A4C733025427C471
5 changed files with 35 additions and 41 deletions

View File

@ -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
}
}

View File

@ -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<git2::Signature<'_>> 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 {

View File

@ -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");

View File

@ -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<git2::Signature<'_>> 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,
}
}
}

View File

@ -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;