//! `issue-create --title [body sources] [--assignee ] [repo]` //! — create an issue. Prints the issue URL. use anyhow::Result; use clap::Args as ClapArgs; use forgejo_api::structs::CreateIssueOption; use crate::body; use crate::client::Client; #[derive(ClapArgs)] pub struct Args { /// Issue title (required). #[arg(long)] title: String, /// Inline body text. #[arg(long, conflicts_with = "body_file")] body: Option, /// Read body from a file. `-` means stdin. #[arg(long = "body-file")] body_file: Option, /// Initial assignee login. #[arg(long)] assignee: Option, } /// # Errors /// /// Propagates any I/O error from the body input (`--body-file`, /// stdin), any transport error from the Forgejo REST call (network /// unreachable, 4xx/5xx response, token missing/invalid), and any /// I/O error from writing the issue URL to stdout. pub fn run(client: &Client, args: Args) -> Result<()> { let body = body::resolve(args.body.as_deref(), args.body_file.as_deref())?.unwrap_or_default(); let (owner, name) = client.owner_repo()?; let payload = CreateIssueOption { assignee: None, assignees: args.assignee.map(|a| vec![a]), body: Some(body), closed: None, due_date: None, labels: None, milestone: None, r#ref: None, title: args.title, }; let issue = client .api() .issue_create_issue(owner, name, payload) .send()?; if let Some(url) = issue.html_url { println!("{url}"); } Ok(()) }