hive-forge: add dependency verb for issue/pr blocking relationships

This commit is contained in:
damocles 2026-08-14 23:32:49 +02:00 committed by mara
commit 6a95aceedb
6 changed files with 121 additions and 11 deletions

View file

@ -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 <show|create|edit|view|comment|comments|close|reopen|labels|assign|timeline> …`.
/// Issue-scoped commands: `issue <show|create|edit|view|comment|comments|close|reopen|labels|assign|dependency|timeline> …`.
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 <show|status|create|merge|reviews|assign-reviewer|commits|diff|view|edit|comment|comments|close|reopen|labels|assign-committer|timeline> …`.
/// PR-scoped commands: `pr <show|status|create|merge|reviews|assign-reviewer|commits|diff|view|edit|comment|comments|close|reopen|labels|assign-committer|dependency|timeline> …`.
Pr(verbs::pr_cmd::Args),
/// List a PR's commits as JSON (sha, message, author date, author).
#[command(hide = true)]

View file

@ -0,0 +1,85 @@
//! `dependency <number> [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 <verb>`
//! and `pr <verb>` the same way `labels`/`assign`/`timeline` are.
//! Setting `<number>`'s dependency on `<dep>` means `<number>` is
//! blocked by `<dep>` — 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<Action>,
}
#[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<u64>,
},
/// Remove one or more dependency links.
Remove {
/// Issue/PR numbers to remove as dependencies.
deps: Vec<u64>,
},
}
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<IssueMeta> {
Ok(IssueMeta {
index: Some(index(dep)?),
owner: None,
repo: None,
})
}

View file

@ -1,10 +1,10 @@
//! `issue <verb>` — 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)

View file

@ -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;

View file

@ -1,10 +1,11 @@
//! `pr <verb>` — 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)