use anyhow::{Result, anyhow};
use std::path::{Path, PathBuf};
use super::git_config::{run_git_command, set_local_config};
use super::write_git_credential_helper_script;
pub fn configure_repo_git_auth(repo_path: &Path, workspace_id: &str) -> Result<PathBuf> {
let helper_path = repo_path.join(".codetether-git-credential-helper");
write_git_credential_helper_script(&helper_path, workspace_id)?;
let helper_path_str = helper_path
.to_str()
.ok_or_else(|| anyhow!("Helper path is not valid UTF-8"))?;
run_git_command(
repo_path,
&["config", "--local", "credential.helper", helper_path_str],
)?;
run_git_command(
repo_path,
&["config", "--local", "credential.useHttpPath", "true"],
)?;
run_git_command(
repo_path,
&["config", "--local", "codetether.workspaceId", workspace_id],
)?;
Ok(helper_path)
}
pub fn configure_repo_git_github_app(
repo_path: &Path,
installation_id: Option<&str>,
app_id: Option<&str>,
) -> Result<()> {
set_local_config(
repo_path,
"codetether.githubInstallationId",
installation_id,
)?;
set_local_config(repo_path, "codetether.githubAppId", app_id)?;
Ok(())
}