From 6a95aceedbaf015a566a198ef905a6273f118a37 Mon Sep 17 00:00:00 2001 From: damocles Date: Fri, 14 Aug 2026 23:32:49 +0200 Subject: [PATCH] hive-forge: add dependency verb for issue/pr blocking relationships --- docs/tools/forge.md | 13 ++++- hive-forge/src/main.rs | 4 +- hive-forge/src/verbs/dependency.rs | 85 ++++++++++++++++++++++++++++++ hive-forge/src/verbs/issue_cmd.rs | 14 +++-- hive-forge/src/verbs/mod.rs | 1 + hive-forge/src/verbs/pr_cmd.rs | 15 ++++-- 6 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 hive-forge/src/verbs/dependency.rs diff --git a/docs/tools/forge.md b/docs/tools/forge.md index bd515d95..ce3ef548 100644 --- a/docs/tools/forge.md +++ b/docs/tools/forge.md @@ -21,7 +21,7 @@ under `issue` and `pr` parent commands — `hive-forge pr close 42`, refuses an issue number, which the old generic `close` couldn't). Run `hive-forge pr --help` / `hive-forge issue --help` for the full subcommand list (show/create/edit/status/merge/reviews/commits/diff/view/comment/ -comments/close/reopen/labels/assign/timeline as applicable). +comments/close/reopen/labels/assign/dependency/timeline as applicable). The flat forms below (`close 42`, `pr-create …`, `pr-status …`, …) still work as **hidden back-compat aliases** during the transition and are dropped from @@ -49,6 +49,10 @@ hive-forge comment-edit 18042 --body "..." # edit a comment hive-forge assign 42 damocles hive-forge close 42 hive-forge labels 42 add feature +hive-forge issue dependency 42 # list #42's dependencies (issues it's blocked by) +hive-forge issue dependency 42 add 40 41 # #42 is now blocked by #40 and #41 +hive-forge issue dependency 42 remove 40 # drop the #40 dependency link +hive-forge pr dependency 55 add 42 # same verb, PR-scoped (Forgejo shares the issue/PR index) hive-forge issue-create --title "..." --body "..." hive-forge issue-create --title "..." --body "..." --label area/ops --label type/bug # repeatable hive-forge issue-edit 42 --title "new title" @@ -273,6 +277,13 @@ to discover valid label names before triaging or to audit the label set. ` (directly). `--workflow ` picks the workflow file for `--pr` / `--branch` (default `ci.yml`). Dispatch re-runs the whole workflow — there is no single-job variant. +- `issue dependency add ` / `pr dependency add ` + set "blocked by" links via Forgejo's dependency feature — the + operator's preferred way to track blocking relationships over labels + (labels can go stale; dependencies are structured and show in the + forge UI's dependency panel). Same-repo only, matching the web UI (no + cross-repo dependency support). `list` (the default action) and `add`/ + `remove` all print the resulting dependency list as JSON. - Do NOT use raw `curl` for forge access -- the CLI handles auth, error checking, and output formatting. - `issue-create --label ` / `pr-create --label ` are diff --git a/hive-forge/src/main.rs b/hive-forge/src/main.rs index 0226ca80..b5a44b27 100644 --- a/hive-forge/src/main.rs +++ b/hive-forge/src/main.rs @@ -67,7 +67,7 @@ enum Verb { /// Dump title + body + all comments for an issue or PR. #[command(hide = true)] View(verbs::view::Args), - /// Issue-scoped commands: `issue …`. + /// Issue-scoped commands: `issue …`. Issue(verbs::issue_cmd::Args), /// Create an issue. Prints the issue URL on success. #[command(hide = true)] @@ -75,7 +75,7 @@ enum Verb { /// Edit an issue's title, body, state, or milestone. #[command(hide = true)] IssueEdit(verbs::issue_edit::Args), - /// PR-scoped commands: `pr …`. + /// PR-scoped commands: `pr …`. Pr(verbs::pr_cmd::Args), /// List a PR's commits as JSON (sha, message, author date, author). #[command(hide = true)] diff --git a/hive-forge/src/verbs/dependency.rs b/hive-forge/src/verbs/dependency.rs new file mode 100644 index 00000000..2e53f9af --- /dev/null +++ b/hive-forge/src/verbs/dependency.rs @@ -0,0 +1,85 @@ +//! `dependency [list|add|remove] [numbers...]` — manage an +//! issue/PR's "blocked by" dependency links. Default action: list. +//! +//! Forgejo's dependency endpoints work on the shared issue/PR index (a +//! PR is an issue internally), so this is wired into both `issue ` +//! and `pr ` the same way `labels`/`assign`/`timeline` are. +//! Setting ``'s dependency on `` means `` is +//! blocked by `` — matching the forge web UI's "add dependency" +//! action, which is a same-repo-only relationship (there is no +//! cross-repo dependency support in this CLI, mirroring the UI). + +use anyhow::{Result, bail}; +use clap::{Args as ClapArgs, Subcommand}; +use forgejo_api::structs::IssueMeta; + +use crate::client::{Client, index}; +use crate::verbs::{dependency_summaries, print_json}; + +#[derive(ClapArgs)] +pub struct Args { + /// Issue or PR number. + pub(crate) number: u64, + #[command(subcommand)] + action: Option, +} + +#[derive(Subcommand)] +enum Action { + /// List dependencies (default when no action is given) — the + /// issues/PRs this one is blocked by. + List, + /// Add one or more issues/PRs this one is blocked by. + Add { + /// Issue/PR numbers to add as dependencies. + deps: Vec, + }, + /// Remove one or more dependency links. + Remove { + /// Issue/PR numbers to remove as dependencies. + deps: Vec, + }, +} + +pub fn run(client: &Client, args: Args) -> Result<()> { + let (owner, name) = client.owner_repo()?; + let idx = index(args.number)?; + match args.action.unwrap_or(Action::List) { + Action::List => {} + Action::Add { deps } => { + if deps.is_empty() { + bail!("hive-forge dependency add: pass at least one issue/PR number"); + } + for dep in &deps { + client + .api() + .issue_create_issue_dependencies(owner, name, idx, dep_meta(*dep)?) + .send()?; + } + } + Action::Remove { deps } => { + if deps.is_empty() { + bail!("hive-forge dependency remove: pass at least one issue/PR number"); + } + for dep in &deps { + client + .api() + .issue_remove_issue_dependencies(owner, name, idx, dep_meta(*dep)?) + .send()?; + } + } + } + let deps = dependency_summaries(client, owner, name, args.number)?; + print_json(&serde_json::json!(deps)) +} + +/// Build the `IssueMeta` body the create/remove endpoints want — just the +/// dependency's index; `owner`/`repo` stay `None` since this CLI only +/// supports same-repo dependencies (matching the forge web UI). +fn dep_meta(dep: u64) -> Result { + Ok(IssueMeta { + index: Some(index(dep)?), + owner: None, + repo: None, + }) +} diff --git a/hive-forge/src/verbs/issue_cmd.rs b/hive-forge/src/verbs/issue_cmd.rs index 886f0611..ec9fd864 100644 --- a/hive-forge/src/verbs/issue_cmd.rs +++ b/hive-forge/src/verbs/issue_cmd.rs @@ -1,10 +1,10 @@ //! `issue ` — issue-scoped sub-commands. Wraps the per-verb modules //! under an `issue` parent so `hive-forge issue close 42`, `issue create …`, //! etc. read as kind-namespaced commands. The generic verbs that also work on -//! PRs (view/comment/comments/close/reopen/labels/assign/timeline) kind-check the -//! number is an issue first (`assert_kind`); the issue-only verbs are -//! kind-correct by construction. The flat `issue-*` + bare generic verbs stay -//! as hidden back-compat aliases (see `main.rs`). +//! PRs (view/comment/comments/close/reopen/labels/assign/dependency/timeline) +//! kind-check the number is an issue first (`assert_kind`); the issue-only +//! verbs are kind-correct by construction. The flat `issue-*` + bare generic +//! verbs stay as hidden back-compat aliases (see `main.rs`). use anyhow::Result; use clap::{Args as ClapArgs, Subcommand}; @@ -40,6 +40,8 @@ enum Cmd { Labels(verbs::labels::Args), /// Assign or unassign a user. Assign(verbs::assign::Args), + /// List / add / remove dependencies (issues this one is blocked by). + Dependency(verbs::dependency::Args), /// List timeline events. Timeline(verbs::timeline::Args), } @@ -79,6 +81,10 @@ pub fn run(client: &Client, args: Args) -> Result<()> { assert_kind(client, a.number, Kind::Issue)?; verbs::assign::run(client, a) } + Cmd::Dependency(a) => { + assert_kind(client, a.number, Kind::Issue)?; + verbs::dependency::run(client, a) + } Cmd::Timeline(a) => { assert_kind(client, a.number, Kind::Issue)?; verbs::timeline::run(client, a) diff --git a/hive-forge/src/verbs/mod.rs b/hive-forge/src/verbs/mod.rs index a3a92f26..d0ffca72 100644 --- a/hive-forge/src/verbs/mod.rs +++ b/hive-forge/src/verbs/mod.rs @@ -16,6 +16,7 @@ pub mod comment; pub mod comment_edit; pub mod comment_show; pub mod comments; +pub mod dependency; pub mod diff; pub mod issue; pub mod issue_cmd; diff --git a/hive-forge/src/verbs/pr_cmd.rs b/hive-forge/src/verbs/pr_cmd.rs index f0c99539..de94548c 100644 --- a/hive-forge/src/verbs/pr_cmd.rs +++ b/hive-forge/src/verbs/pr_cmd.rs @@ -1,10 +1,11 @@ //! `pr ` — PR-scoped sub-commands. Wraps the per-verb modules under a //! `pr` parent so `hive-forge pr close 42`, `pr status --pr 42`, etc. read as //! kind-namespaced commands. The generic verbs that also work on issues -//! (view/comment/comments/close/reopen/edit/labels/assign-committer/timeline) -//! kind-check the number is a PR first (`assert_kind`); the PR-only verbs -//! hit `/pulls/…` and are kind-correct by construction. The flat `pr-*` + -//! bare generic verbs stay as hidden back-compat aliases (see `main.rs`). +//! (view/comment/comments/close/reopen/edit/labels/assign-committer/ +//! dependency/timeline) kind-check the number is a PR first (`assert_kind`); +//! the PR-only verbs hit `/pulls/…` and are kind-correct by construction. +//! The flat `pr-*` + bare generic verbs stay as hidden back-compat aliases +//! (see `main.rs`). use anyhow::Result; use clap::{Args as ClapArgs, Subcommand}; @@ -54,6 +55,8 @@ enum Cmd { /// Assign or unassign a user (the PR's assignee list). #[command(alias = "assign")] AssignCommitter(verbs::assign::Args), + /// List / add / remove dependencies (issues/PRs this one is blocked by). + Dependency(verbs::dependency::Args), /// List timeline events. Timeline(verbs::timeline::Args), } @@ -102,6 +105,10 @@ pub fn run(client: &Client, args: Args) -> Result<()> { assert_kind(client, a.number, Kind::Pr)?; verbs::assign::run(client, a) } + Cmd::Dependency(a) => { + assert_kind(client, a.number, Kind::Pr)?; + verbs::dependency::run(client, a) + } Cmd::Timeline(a) => { assert_kind(client, a.number, Kind::Pr)?; verbs::timeline::run(client, a)