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 {
repo: String,
branch: String,
gitdir: Option<PathBuf>,
gitdir: Option<GitDir>,
main: Option<String>,
next: Option<String>,
dev: Option<String>,

View file

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

View file

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

View file

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

View file

@ -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!()
}
}

View file

@ -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)]