Skip to main content

sparrow/cmd_handlers/
handle_github_cmd.rs

1// src/cmd_handlers/handle_github_cmd.rs
2pub fn handle_github(action: sparrow::cli::GithubAction) -> anyhow::Result<()> {
3    use sparrow::cli::GithubAction;
4    use sparrow::github;
5
6    match action {
7        GithubAction::Review {
8            pr,
9            dry_run,
10            model,
11            allowed_tools,
12        } => {
13            let mut plan = github::plan_review(pr, model, allowed_tools, dry_run);
14            if dry_run {
15                println!("{}", serde_json::to_string_pretty(&plan)?);
16                return Ok(());
17            }
18            github::require_action_env()?;
19            plan.diff_preview = github::fetch_pr_diff(pr)?;
20            // We intentionally do NOT call the model here. The actual review
21            // is performed by `sparrow run` invoked separately by the Action
22            // composite step, so this command stays a pure data-fetcher.
23            println!("{}", serde_json::to_string_pretty(&plan)?);
24        }
25        GithubAction::Status => {
26            github::require_action_env()?;
27            println!("{}", github::ci_status()?);
28        }
29        GithubAction::Logs { run_id } => {
30            github::require_action_env()?;
31            println!("{}", github::ci_logs(&run_id)?);
32        }
33    }
34    Ok(())
35}
36
37// ─── MCP commands ───────────────────────────────────────────────────────────────