LINE1 10 20 30 40 50 60 70 80 90 100 110 1201mod cache;2mod cli;3mod config;4mod github;5mod prompt;67use anyhow::{bail, Result};8use clap::Parser;910fn get_token() -> Result<String> {11 std::env::var("GITHUB_TOKEN")12 .map_err(|_| anyhow::anyhow!("GITHUB_TOKEN environment variable not set. Set it and try again, or run `pike setup`."))13}1415async fn run_create_issue() -> Result<()> {16 let token = get_token()?;17 let config = config::Config::load()?;18 let mut cache = cache::Cache::load()?;1920 if cache.repos.is_empty() {21 bail!("No cached repositories. Run `pike setup` first.");22 }2324 let input = prompt::collect_issue_input(&config, &cache)?;25 let client = github::GitHubClient::new(&token);2627 println!("Creating issue...");28 let issue = client29 .create_issue(&input.repo_full_name, &input.title, &input.description)30 .await?;31 println!(" Issue #{}: {}", issue.number, issue.html_url);3233 if let Some(ref project) = input.project {34 println!("Adding to project \"{}\"...", project.title);35 let item_id = client36 .add_issue_to_project(&project.id, &issue.node_id)37 .await?;3839 if let Some(ref status) = input.status {40 println!("Setting status to \"{}\"...", status.name);41 client42 .set_issue_status(43 &project.id,44 &item_id,45 &project.status_field_id,46 &status.id,47 )48 .await?;49 println!(" Status set to \"{}\"", status.name);50 }5152 println!(" Added to project \"{}\"", project.title);53 }5455 let project_id = input.project.as_ref().map(|p| p.id.as_str());56 cache.record_issue(&input.repo_full_name, project_id)?;5758 Ok(())59}6061async fn run_setup() -> Result<()> {62 let token = get_token()?;63 prompt::run_setup(&token).await64}6566#[tokio::main]67async fn main() -> Result<()> {68 let cli = cli::Cli::parse();6970 match cli.command {71 Some(cli::Commands::Setup) => run_setup().await,72 None => run_create_issue().await,73 }74}