hive-forge: add dependency verb for issue/pr blocking relationships
This commit is contained in:
parent
32643dae36
commit
6a95aceedb
6 changed files with 121 additions and 11 deletions
85
hive-forge/src/verbs/dependency.rs
Normal file
85
hive-forge/src/verbs/dependency.rs
Normal 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,
|
||||
})
|
||||
}
|
||||
Loading…
Reference in a new issue