feat: with git username and email in config

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-08-01 22:38:58 +02:00
parent 1e15e41354
commit 5229d30758
7 changed files with 81 additions and 11 deletions

View File

@@ -3,7 +3,11 @@ use std::path::{Path, PathBuf};
#[derive(Clone, Debug, PartialEq)]
pub enum VcsClient {
Noop {},
Git { source: PathBuf },
Git {
source: PathBuf,
username: String,
email: String,
},
}
impl VcsClient {
@@ -11,13 +15,23 @@ impl VcsClient {
Self::Noop {}
}
pub fn new_git(path: &Path) -> anyhow::Result<VcsClient> {
pub fn new_git(
path: &Path,
git_username: Option<impl Into<String>>,
git_email: Option<impl Into<String>>,
) -> anyhow::Result<VcsClient> {
if !path.to_path_buf().join(".git").exists() {
anyhow::bail!("git directory not found in: {}", path.display().to_string())
}
Ok(Self::Git {
source: path.to_path_buf(),
username: git_username
.map(|u| u.into())
.unwrap_or("cuddle-please".to_string()),
email: git_email
.map(|e| e.into())
.unwrap_or("bot@cuddle.sh".to_string()),
})
}
@@ -38,7 +52,7 @@ impl VcsClient {
fn exec_git(&self, args: &[&str]) -> anyhow::Result<()> {
match self {
VcsClient::Noop {} => {}
VcsClient::Git { source } => {
VcsClient::Git { source, .. } => {
let checkout_branch = std::process::Command::new("git")
.current_dir(source.as_path())
.args(args)