feat(#1877): restructure hive-forge into pr/issue sub-verbs
Group issue/PR operations under `pr` and `issue` parent commands (`hive-forge pr close 42`, `issue create …`, `pr status --pr 42`) per the operator decision — kind-namespaced verbs replace the flat surface. - new `verbs::pr_cmd` / `verbs::issue_cmd` parent commands wrap the existing per-verb modules (reuse their Args + run fns) under `#[command(subcommand)]`. - kind-validation (the win over the old generic verbs): the generics that work on both (view/comment/comments/close/labels/assign/timeline) call `assert_kind` first, so `pr close <issue>` / `issue close <pr>` are rejected with a 'use the other command' message. PR-only / issue-only verbs are kind-correct by construction. `number` exposed `pub(crate)` on the shared verbs so the wrappers can probe it. - every flat kind verb (`close`, `pr-create`, `pr-status`, `issue-edit`, …) kept as a `#[command(hide = true)]` back-compat alias — still parses, dropped from --help; removed in a later sweep once usage migrates. (`pr`/`issue` bare-show become `pr show` / `issue show` — the names are now parents.) - docs/tools/forge.md documents the new surface + the deprecated aliases. cargo build/clippy/fmt clean, 54 tests pass; --help surface + alias parsing smoke-tested.
This commit is contained in:
parent
fe974c580d
commit
dc4c5460d5
12 changed files with 257 additions and 13 deletions
|
|
@ -17,6 +17,7 @@ pub mod comment_show;
|
|||
pub mod comments;
|
||||
pub mod diff;
|
||||
pub mod issue;
|
||||
pub mod issue_cmd;
|
||||
pub mod issue_create;
|
||||
pub mod issue_edit;
|
||||
pub mod labels;
|
||||
|
|
@ -24,6 +25,7 @@ pub mod lint;
|
|||
pub mod list;
|
||||
pub mod milestone;
|
||||
pub mod pr;
|
||||
pub mod pr_cmd;
|
||||
pub mod pr_commits;
|
||||
pub mod pr_create;
|
||||
pub mod pr_merge;
|
||||
|
|
@ -52,6 +54,37 @@ pub(crate) fn print_json(v: &Value) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Issue-vs-PR kind, for the `pr <verb>` / `issue <verb>` sub-command
|
||||
/// validation.
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) enum Kind {
|
||||
Pr,
|
||||
Issue,
|
||||
}
|
||||
|
||||
/// Verify `number` is the expected kind before a kind-namespaced verb (one
|
||||
/// of the generics that work on both — close/comment/labels/…) acts on it —
|
||||
/// the validation win the `pr <verb>` / `issue <verb>` split buys over the
|
||||
/// old generic verbs. Forgejo's `/issues/{n}` endpoint serves both issues and
|
||||
/// PRs and marks PRs with a non-null `pull_request` field, so one GET
|
||||
/// classifies it. Errors with a "use the other command" message on mismatch.
|
||||
pub(crate) fn assert_kind(client: &Client, number: u64, expected: Kind) -> Result<()> {
|
||||
let repo = client.repo();
|
||||
let v = client.get_json(&format!("/repos/{repo}/issues/{number}"))?;
|
||||
let is_pr = v.get("pull_request").is_some_and(|p| !p.is_null());
|
||||
match (expected, is_pr) {
|
||||
(Kind::Pr, false) => {
|
||||
anyhow::bail!(
|
||||
"#{number} is an issue, not a PR — use `hive-forge issue <verb> {number}`"
|
||||
)
|
||||
}
|
||||
(Kind::Issue, true) => {
|
||||
anyhow::bail!("#{number} is a PR, not an issue — use `hive-forge pr <verb> {number}`")
|
||||
}
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Minimal RFC 3986 unreserved-set percent encoder. Covers the subset of
|
||||
/// characters that show up in the values we splice into request paths —
|
||||
/// usernames, label names, artifact names — without pulling in a fresh
|
||||
|
|
|
|||
Loading…
Reference in a new issue