feat: use GitDir in place of raw PathBuf
All checks were successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful

This commit is contained in:
Paul Campbell 2024-04-21 18:47:07 +01:00
parent 56e253b545
commit a024c3de5e
6 changed files with 14 additions and 22 deletions

View file

@ -171,7 +171,7 @@ impl Display for ForgeConfig {
pub struct ServerRepoConfig { pub struct ServerRepoConfig {
repo: String, repo: String,
branch: String, branch: String,
gitdir: Option<PathBuf>, gitdir: Option<GitDir>,
main: Option<String>, main: Option<String>,
next: Option<String>, next: Option<String>,
dev: Option<String>, dev: Option<String>,

View file

@ -1,4 +1,4 @@
use crate::server::config::BranchName; use crate::server::config::{BranchName, GitDir};
#[derive(Debug)] #[derive(Debug)]
pub enum ForgeFileError { pub enum ForgeFileError {
@ -42,7 +42,7 @@ impl std::fmt::Display for ForgeBranchError {
#[derive(Debug)] #[derive(Debug)]
pub enum RepoCloneError { pub enum RepoCloneError {
InvalidGitDir(std::path::PathBuf), InvalidGitDir(GitDir),
Wait(std::io::Error), Wait(std::io::Error),
Spawn(std::io::Error), Spawn(std::io::Error),
} }

View file

@ -2,8 +2,6 @@ mod branch;
mod file; mod file;
mod repo; mod repo;
use std::path::PathBuf;
use actix::prelude::*; use actix::prelude::*;
use kxio::network::{self, Network}; use kxio::network::{self, Network};
@ -11,7 +9,7 @@ use tracing::{error, warn};
use crate::server::{ use crate::server::{
actors::repo::RepoActor, actors::repo::RepoActor,
config::{BranchName, RepoConfig, RepoDetails}, config::{BranchName, GitDir, RepoConfig, RepoDetails},
gitforge::{self, RepoCloneError}, gitforge::{self, RepoCloneError},
types::GitRef, 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) repo::clone(&self.repo_details, gitdir)
} }
} }

View file

@ -1,13 +1,11 @@
use std::path::PathBuf;
use tracing::{info, warn}; 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> { pub fn clone(repo_details: &RepoDetails, gitdir: GitDir) -> Result<(), RepoCloneError> {
let Some(gitdir) = gitdir.to_str() else {
return Err(RepoCloneError::InvalidGitDir(gitdir));
};
let origin = repo_details.origin(); let origin = repo_details.origin();
// INFO: never log the command as it contains the API token within the 'origin' // INFO: never log the command as it contains the API token within the 'origin'
use secrecy::ExposeSecret; use secrecy::ExposeSecret;

View file

@ -1,8 +1,6 @@
use std::path::PathBuf;
use crate::server::{ use crate::server::{
actors::repo::RepoActor, actors::repo::RepoActor,
config::{BranchName, RepoConfig}, config::{BranchName, GitDir, RepoConfig},
gitforge::{self, RepoCloneError}, gitforge::{self, RepoCloneError},
types::GitRef, types::GitRef,
}; };
@ -54,7 +52,7 @@ impl super::ForgeLike for MockForgeEnv {
todo!() todo!()
} }
fn repo_clone(&self, _gitdir: PathBuf) -> Result<(), RepoCloneError> { fn repo_clone(&self, _gitdir: GitDir) -> Result<(), RepoCloneError> {
todo!() todo!()
} }
} }

View file

@ -1,7 +1,5 @@
#![allow(dead_code)] #![allow(dead_code)]
use std::path::PathBuf;
use kxio::network::Network; use kxio::network::Network;
#[cfg(feature = "forgejo")] #[cfg(feature = "forgejo")]
@ -19,7 +17,7 @@ mod errors;
pub use errors::*; pub use errors::*;
use crate::server::{ use crate::server::{
config::{BranchName, RepoConfig, RepoDetails}, config::{BranchName, GitDir, RepoConfig, RepoDetails},
types::GitRef, types::GitRef,
}; };
@ -57,7 +55,7 @@ pub trait ForgeLike {
async fn commit_status(&self, commit: &Commit) -> CommitStatus; async fn commit_status(&self, commit: &Commit) -> CommitStatus;
/// Clones a repo to disk. /// Clones a repo to disk.
fn repo_clone(&self, gitdir: PathBuf) -> Result<(), RepoCloneError>; fn repo_clone(&self, gitdir: GitDir) -> Result<(), RepoCloneError>;
} }
#[derive(Clone)] #[derive(Clone)]