From a024c3de5e04d3fd1d339c91dca2c8598b70e3c1 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 21 Apr 2024 18:47:07 +0100 Subject: [PATCH] feat: use GitDir in place of raw PathBuf --- src/server/config/mod.rs | 2 +- src/server/gitforge/errors.rs | 4 ++-- src/server/gitforge/forgejo/mod.rs | 6 ++---- src/server/gitforge/forgejo/repo/clone.rs | 12 +++++------- src/server/gitforge/mock_forge.rs | 6 ++---- src/server/gitforge/mod.rs | 6 ++---- 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/server/config/mod.rs b/src/server/config/mod.rs index 35020ef6..8b608b49 100644 --- a/src/server/config/mod.rs +++ b/src/server/config/mod.rs @@ -171,7 +171,7 @@ impl Display for ForgeConfig { pub struct ServerRepoConfig { repo: String, branch: String, - gitdir: Option, + gitdir: Option, main: Option, next: Option, dev: Option, diff --git a/src/server/gitforge/errors.rs b/src/server/gitforge/errors.rs index 171d234f..6e85a5ad 100644 --- a/src/server/gitforge/errors.rs +++ b/src/server/gitforge/errors.rs @@ -1,4 +1,4 @@ -use crate::server::config::BranchName; +use crate::server::config::{BranchName, GitDir}; #[derive(Debug)] pub enum ForgeFileError { @@ -42,7 +42,7 @@ impl std::fmt::Display for ForgeBranchError { #[derive(Debug)] pub enum RepoCloneError { - InvalidGitDir(std::path::PathBuf), + InvalidGitDir(GitDir), Wait(std::io::Error), Spawn(std::io::Error), } diff --git a/src/server/gitforge/forgejo/mod.rs b/src/server/gitforge/forgejo/mod.rs index 19cc4688..a78d4714 100644 --- a/src/server/gitforge/forgejo/mod.rs +++ b/src/server/gitforge/forgejo/mod.rs @@ -2,8 +2,6 @@ mod branch; mod file; mod repo; -use std::path::PathBuf; - use actix::prelude::*; use kxio::network::{self, Network}; @@ -11,7 +9,7 @@ use tracing::{error, warn}; use crate::server::{ actors::repo::RepoActor, - config::{BranchName, RepoConfig, RepoDetails}, + config::{BranchName, GitDir, RepoConfig, RepoDetails}, gitforge::{self, RepoCloneError}, types::GitRef, }; @@ -102,7 +100,7 @@ impl super::ForgeLike for ForgeJoEnv { } } - fn repo_clone(&self, gitdir: PathBuf) -> Result<(), RepoCloneError> { + fn repo_clone(&self, gitdir: GitDir) -> Result<(), RepoCloneError> { repo::clone(&self.repo_details, gitdir) } } diff --git a/src/server/gitforge/forgejo/repo/clone.rs b/src/server/gitforge/forgejo/repo/clone.rs index ef10b4aa..2b3df744 100644 --- a/src/server/gitforge/forgejo/repo/clone.rs +++ b/src/server/gitforge/forgejo/repo/clone.rs @@ -1,13 +1,11 @@ -use std::path::PathBuf; - use tracing::{info, warn}; -use crate::server::{config::RepoDetails, gitforge::RepoCloneError}; +use crate::server::{ + config::{GitDir, RepoDetails}, + gitforge::RepoCloneError, +}; -pub fn clone(repo_details: &RepoDetails, gitdir: PathBuf) -> Result<(), RepoCloneError> { - let Some(gitdir) = gitdir.to_str() else { - return Err(RepoCloneError::InvalidGitDir(gitdir)); - }; +pub fn clone(repo_details: &RepoDetails, gitdir: GitDir) -> Result<(), RepoCloneError> { let origin = repo_details.origin(); // INFO: never log the command as it contains the API token within the 'origin' use secrecy::ExposeSecret; diff --git a/src/server/gitforge/mock_forge.rs b/src/server/gitforge/mock_forge.rs index 58e13ce2..37579cc8 100644 --- a/src/server/gitforge/mock_forge.rs +++ b/src/server/gitforge/mock_forge.rs @@ -1,8 +1,6 @@ -use std::path::PathBuf; - use crate::server::{ actors::repo::RepoActor, - config::{BranchName, RepoConfig}, + config::{BranchName, GitDir, RepoConfig}, gitforge::{self, RepoCloneError}, types::GitRef, }; @@ -54,7 +52,7 @@ impl super::ForgeLike for MockForgeEnv { todo!() } - fn repo_clone(&self, _gitdir: PathBuf) -> Result<(), RepoCloneError> { + fn repo_clone(&self, _gitdir: GitDir) -> Result<(), RepoCloneError> { todo!() } } diff --git a/src/server/gitforge/mod.rs b/src/server/gitforge/mod.rs index a1b863b1..1b6765d6 100644 --- a/src/server/gitforge/mod.rs +++ b/src/server/gitforge/mod.rs @@ -1,7 +1,5 @@ #![allow(dead_code)] -use std::path::PathBuf; - use kxio::network::Network; #[cfg(feature = "forgejo")] @@ -19,7 +17,7 @@ mod errors; pub use errors::*; use crate::server::{ - config::{BranchName, RepoConfig, RepoDetails}, + config::{BranchName, GitDir, RepoConfig, RepoDetails}, types::GitRef, }; @@ -57,7 +55,7 @@ pub trait ForgeLike { async fn commit_status(&self, commit: &Commit) -> CommitStatus; /// Clones a repo to disk. - fn repo_clone(&self, gitdir: PathBuf) -> Result<(), RepoCloneError>; + fn repo_clone(&self, gitdir: GitDir) -> Result<(), RepoCloneError>; } #[derive(Clone)]