hive-forge: add --label to issue-create and pr-create

This commit is contained in:
damocles 2026-07-27 15:54:39 +02:00 committed by mara
commit abde71b0ed
4 changed files with 94 additions and 9 deletions

View file

@ -1,5 +1,5 @@
//! `issue-create --title <t> [body sources] [--assignee <u>] [repo]`
//! — create an issue. Prints the issue URL.
//! `issue-create --title <t> [body sources] [--assignee <u>]
//! [--label <name>]... [repo]` — create an issue. Prints the issue URL.
use anyhow::Result;
use clap::Args as ClapArgs;
@ -7,6 +7,7 @@ use forgejo_api::structs::CreateIssueOption;
use crate::body;
use crate::client::Client;
use crate::verbs::labels;
#[derive(ClapArgs)]
pub struct Args {
@ -22,24 +23,36 @@ pub struct Args {
/// Initial assignee login.
#[arg(long)]
assignee: Option<String>,
/// Label name to attach, repeatable (e.g. `--label area/ops --label
/// type/bug`). Same spelling `labels add` accepts. Unknown names are
/// silently dropped, matching `labels add`'s existing behavior.
#[arg(long = "label")]
labels: Vec<String>,
}
/// # 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.
/// unreachable, 4xx/5xx response, token missing/invalid, the
/// `--label` lookup's own list-labels call), 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 label_ids = if args.labels.is_empty() {
None
} else {
let all = labels::repo_labels(client)?;
Some(labels::resolve_ids(&all, &args.labels))
};
let payload = CreateIssueOption {
assignee: None,
assignees: args.assignee.map(|a| vec![a]),
body: Some(body),
closed: None,
due_date: None,
labels: None,
labels: label_ids,
milestone: None,
r#ref: None,
title: args.title,