use super::GitHubCommandAuth;
use super::command::needs_github_auth;
use super::config::resolve_gh_config_dir;
use super::credentials::load_github_password;
use super::repo_context::load_repo_context;
use anyhow::Result;
pub async fn load_github_command_auth(
command: &str,
cwd: Option<&str>,
) -> Result<Option<GitHubCommandAuth>> {
if !needs_github_auth(command) {
return Ok(None);
}
let Some((workspace_id, host, path)) = load_repo_context(cwd).await else {
return Ok(None);
};
let password = load_github_password(&workspace_id, host, path).await?;
Ok(password.map(|password| GitHubCommandAuth::new(password, resolve_gh_config_dir())))
}