MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / handle_github_command

Function handle_github_command

crates/opencode-cli/src/main.rs:5122–5551  ·  view source on GitHub ↗
(action: GithubCommands)

Source from the content-addressed store, hash-verified

5120}
5121
5122async fn handle_github_command(action: GithubCommands) -> anyhow::Result<()> {
5123 match action {
5124 GithubCommands::Status => {
5125 let version = std::process::Command::new("gh")
5126 .arg("--version")
5127 .output()
5128 .map_err(|e| anyhow::anyhow!("Failed to run `gh --version`: {}", e))?;
5129
5130 if !version.status.success() {
5131 anyhow::bail!("GitHub CLI is not available on PATH");
5132 }
5133
5134 println!("{}", String::from_utf8_lossy(&version.stdout));
5135
5136 let auth = std::process::Command::new("gh")
5137 .arg("auth")
5138 .arg("status")
5139 .output()
5140 .map_err(|e| anyhow::anyhow!("Failed to run `gh auth status`: {}", e))?;
5141
5142 if auth.status.success() {
5143 println!("{}", String::from_utf8_lossy(&auth.stdout));
5144 let stderr = String::from_utf8_lossy(&auth.stderr);
5145 if !stderr.trim().is_empty() {
5146 println!("{}", stderr);
5147 }
5148 } else {
5149 let stderr = String::from_utf8_lossy(&auth.stderr);
5150 anyhow::bail!("`gh auth status` failed: {}", stderr.trim());
5151 }
5152 }
5153 GithubCommands::Install => {
5154 let git_check = ProcessCommand::new("git")
5155 .args(["rev-parse", "--is-inside-work-tree"])
5156 .output()
5157 .map_err(|e| anyhow::anyhow!("Failed to run git: {}", e))?;
5158 if !git_check.status.success() {
5159 anyhow::bail!("Run `opencode github install` inside a git repository.");
5160 }
5161
5162 let remote = ProcessCommand::new("git")
5163 .args(["remote", "get-url", "origin"])
5164 .output()
5165 .map_err(|e| anyhow::anyhow!("Failed to read git origin remote: {}", e))?;
5166 if !remote.status.success() {
5167 anyhow::bail!("Could not read `origin` remote.");
5168 }
5169 let remote_url = String::from_utf8_lossy(&remote.stdout).trim().to_string();
5170 let (owner, repo) = parse_github_remote(&remote_url).ok_or_else(|| {
5171 anyhow::anyhow!("Unsupported GitHub remote URL format: {}", remote_url)
5172 })?;
5173
5174 let model = choose_github_model().await?;
5175 let workflow_path = PathBuf::from(".github/workflows/opencode.yml");
5176 if workflow_path.exists() {
5177 println!("Workflow already exists: {}", workflow_path.display());
5178 } else {
5179 if let Some(parent) = workflow_path.parent() {

Callers 1

mainFunction · 0.85

Calls 15

newFunction · 0.85
parse_github_remoteFunction · 0.85
choose_github_modelFunction · 0.85
build_github_workflowFunction · 0.85
provider_secret_keysFunction · 0.85
ensure_gh_availableFunction · 0.85
load_mock_eventFunction · 0.85
github_is_user_eventFunction · 0.85
github_is_repo_eventFunction · 0.85
github_is_comment_eventFunction · 0.85
github_is_pr_contextFunction · 0.85

Tested by

no test coverage detected