hyperhive/hive-forge/src/verbs/repo_create.rs
atlas 03f8bc8a6a docs(#2671): trim per-verb arg help (repo-create)
Drop the API path from --org and the "Forgejo applies it to the initial
commit" mechanics from --default-branch (kept the user-facing caveat:
only takes effect with --auto-init). Swept the remaining verbs
(attachment-get, pr-reviews, attach, repo-add-collaborator, comment,
clone, pr-cmd router, …) — already user-relevant, no changes needed.
2026-07-23 22:54:15 +02:00

77 lines
2.7 KiB
Rust

//! `repo-create <name> [--description <d>] [--private] [--default-branch <b>]
//! [--org <org>] [--auto-init]` — create a forge repository under the current
//! user (or under `--org`). Prints the new repo's web URL (or the full repo
//! object under `--json`).
//!
//! Wraps `POST /api/v1/user/repos` (or `/orgs/{org}/repos`) so agents don't
//! reach for raw API calls when the operator greenlights a new repo — the
//! instance has push-to-create disabled, so `git push` to a non-existent
//! repo 403s. Pairs with `clone` (then push your content) and
//! `repo-add-collaborator` (add peers to a fresh agent-namespace repo).
use anyhow::Result;
use clap::Args as ClapArgs;
use forgejo_api::structs::CreateRepoOption;
use crate::client::Client;
use crate::verbs::print_json;
#[derive(ClapArgs)]
pub struct Args {
/// Repository name (required). Created under the authenticated user
/// unless `--org` is given.
name: String,
/// Repository description.
#[arg(long)]
description: Option<String>,
/// Create the repo as private (default: public).
#[arg(long)]
private: bool,
/// Default branch name (e.g. `main`). Only takes effect with `--auto-init`.
#[arg(long = "default-branch")]
default_branch: Option<String>,
/// Create under this organisation instead of your own namespace.
#[arg(long)]
org: Option<String>,
/// Seed an initial commit (README) so the repo is non-empty and can
/// be cloned immediately. Omit to create a bare repo you push into.
#[arg(long = "auto-init")]
auto_init: bool,
}
/// # Errors
///
/// Propagates any transport error from the Forgejo REST call (network
/// unreachable, 4xx/5xx response such as a name clash or insufficient
/// permission on the target namespace, token missing/invalid) and any
/// I/O error from writing the result to stdout.
pub fn run(client: &Client, args: Args) -> Result<()> {
let payload = CreateRepoOption {
auto_init: Some(args.auto_init),
default_branch: args.default_branch,
description: args.description,
gitignores: None,
issue_labels: None,
license: None,
name: args.name,
object_format_name: None,
private: Some(args.private),
readme: None,
template: None,
trust_model: None,
};
let resp = match args.org.as_deref() {
Some(org) => client.api().create_org_repo(org, payload).send()?,
None => client.api().create_current_user_repo(payload).send()?,
};
if client.json_mode() {
return print_json(&serde_json::to_value(&resp)?);
}
// Default human path: print the web URL, like issue-create / pr-create.
if let Some(url) = resp.html_url {
println!("{url}");
}
Ok(())
}