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
|
|
@ -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
|
refuses an issue number, which the old generic `close` couldn't). Run
|
||||||
`hive-forge pr --help` / `hive-forge issue --help` for the full subcommand
|
`hive-forge pr --help` / `hive-forge issue --help` for the full subcommand
|
||||||
list (show/create/edit/status/merge/reviews/commits/diff/view/comment/
|
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
|
The flat forms below (`close 42`, `pr-create …`, `pr-status …`, …) still work
|
||||||
as **hidden back-compat aliases** during the transition and are dropped from
|
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 assign 42 damocles
|
||||||
hive-forge close 42
|
hive-forge close 42
|
||||||
hive-forge labels 42 add feature
|
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 "..."
|
||||||
hive-forge issue-create --title "..." --body "..." --label area/ops --label type/bug # repeatable
|
hive-forge issue-create --title "..." --body "..." --label area/ops --label type/bug # repeatable
|
||||||
hive-forge issue-edit 42 --title "new title"
|
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.
|
||||||
<name>` (directly). `--workflow <file>` picks the workflow file for
|
<name>` (directly). `--workflow <file>` picks the workflow file for
|
||||||
`--pr` / `--branch` (default `ci.yml`). Dispatch re-runs the whole
|
`--pr` / `--branch` (default `ci.yml`). Dispatch re-runs the whole
|
||||||
workflow — there is no single-job variant.
|
workflow — there is no single-job variant.
|
||||||
|
- `issue dependency <n> add <dep...>` / `pr dependency <n> add <dep...>`
|
||||||
|
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,
|
- Do NOT use raw `curl` for forge access -- the CLI handles auth,
|
||||||
error checking, and output formatting.
|
error checking, and output formatting.
|
||||||
- `issue-create --label <name>` / `pr-create --label <name>` are
|
- `issue-create --label <name>` / `pr-create --label <name>` are
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ enum Verb {
|
||||||
/// Dump title + body + all comments for an issue or PR.
|
/// Dump title + body + all comments for an issue or PR.
|
||||||
#[command(hide = true)]
|
#[command(hide = true)]
|
||||||
View(verbs::view::Args),
|
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),
|
Issue(verbs::issue_cmd::Args),
|
||||||
/// Create an issue. Prints the issue URL on success.
|
/// Create an issue. Prints the issue URL on success.
|
||||||
#[command(hide = true)]
|
#[command(hide = true)]
|
||||||
|
|
@ -75,7 +75,7 @@ enum Verb {
|
||||||
/// Edit an issue's title, body, state, or milestone.
|
/// Edit an issue's title, body, state, or milestone.
|
||||||
#[command(hide = true)]
|
#[command(hide = true)]
|
||||||
IssueEdit(verbs::issue_edit::Args),
|
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),
|
Pr(verbs::pr_cmd::Args),
|
||||||
/// List a PR's commits as JSON (sha, message, author date, author).
|
/// List a PR's commits as JSON (sha, message, author date, author).
|
||||||
#[command(hide = true)]
|
#[command(hide = true)]
|
||||||
|
|
|
||||||
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
//! `issue <verb>` — issue-scoped sub-commands. Wraps the per-verb modules
|
//! `issue <verb>` — issue-scoped sub-commands. Wraps the per-verb modules
|
||||||
//! under an `issue` parent so `hive-forge issue close 42`, `issue create …`,
|
//! 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
|
//! 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
|
//! PRs (view/comment/comments/close/reopen/labels/assign/dependency/timeline)
|
||||||
//! number is an issue first (`assert_kind`); the issue-only verbs are
|
//! kind-check the number is an issue first (`assert_kind`); the issue-only
|
||||||
//! kind-correct by construction. The flat `issue-*` + bare generic verbs stay
|
//! verbs are kind-correct by construction. The flat `issue-*` + bare generic
|
||||||
//! as hidden back-compat aliases (see `main.rs`).
|
//! verbs stay as hidden back-compat aliases (see `main.rs`).
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{Args as ClapArgs, Subcommand};
|
use clap::{Args as ClapArgs, Subcommand};
|
||||||
|
|
@ -40,6 +40,8 @@ enum Cmd {
|
||||||
Labels(verbs::labels::Args),
|
Labels(verbs::labels::Args),
|
||||||
/// Assign or unassign a user.
|
/// Assign or unassign a user.
|
||||||
Assign(verbs::assign::Args),
|
Assign(verbs::assign::Args),
|
||||||
|
/// List / add / remove dependencies (issues this one is blocked by).
|
||||||
|
Dependency(verbs::dependency::Args),
|
||||||
/// List timeline events.
|
/// List timeline events.
|
||||||
Timeline(verbs::timeline::Args),
|
Timeline(verbs::timeline::Args),
|
||||||
}
|
}
|
||||||
|
|
@ -79,6 +81,10 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
|
||||||
assert_kind(client, a.number, Kind::Issue)?;
|
assert_kind(client, a.number, Kind::Issue)?;
|
||||||
verbs::assign::run(client, a)
|
verbs::assign::run(client, a)
|
||||||
}
|
}
|
||||||
|
Cmd::Dependency(a) => {
|
||||||
|
assert_kind(client, a.number, Kind::Issue)?;
|
||||||
|
verbs::dependency::run(client, a)
|
||||||
|
}
|
||||||
Cmd::Timeline(a) => {
|
Cmd::Timeline(a) => {
|
||||||
assert_kind(client, a.number, Kind::Issue)?;
|
assert_kind(client, a.number, Kind::Issue)?;
|
||||||
verbs::timeline::run(client, a)
|
verbs::timeline::run(client, a)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ pub mod comment;
|
||||||
pub mod comment_edit;
|
pub mod comment_edit;
|
||||||
pub mod comment_show;
|
pub mod comment_show;
|
||||||
pub mod comments;
|
pub mod comments;
|
||||||
|
pub mod dependency;
|
||||||
pub mod diff;
|
pub mod diff;
|
||||||
pub mod issue;
|
pub mod issue;
|
||||||
pub mod issue_cmd;
|
pub mod issue_cmd;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
//! `pr <verb>` — PR-scoped sub-commands. Wraps the per-verb modules under a
|
//! `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
|
//! `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
|
//! kind-namespaced commands. The generic verbs that also work on issues
|
||||||
//! (view/comment/comments/close/reopen/edit/labels/assign-committer/timeline)
|
//! (view/comment/comments/close/reopen/edit/labels/assign-committer/
|
||||||
//! kind-check the number is a PR first (`assert_kind`); the PR-only verbs
|
//! dependency/timeline) kind-check the number is a PR first (`assert_kind`);
|
||||||
//! hit `/pulls/…` and are kind-correct by construction. The flat `pr-*` +
|
//! the PR-only verbs hit `/pulls/…` and are kind-correct by construction.
|
||||||
//! bare generic verbs stay as hidden back-compat aliases (see `main.rs`).
|
//! The flat `pr-*` + bare generic verbs stay as hidden back-compat aliases
|
||||||
|
//! (see `main.rs`).
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{Args as ClapArgs, Subcommand};
|
use clap::{Args as ClapArgs, Subcommand};
|
||||||
|
|
@ -54,6 +55,8 @@ enum Cmd {
|
||||||
/// Assign or unassign a user (the PR's assignee list).
|
/// Assign or unassign a user (the PR's assignee list).
|
||||||
#[command(alias = "assign")]
|
#[command(alias = "assign")]
|
||||||
AssignCommitter(verbs::assign::Args),
|
AssignCommitter(verbs::assign::Args),
|
||||||
|
/// List / add / remove dependencies (issues/PRs this one is blocked by).
|
||||||
|
Dependency(verbs::dependency::Args),
|
||||||
/// List timeline events.
|
/// List timeline events.
|
||||||
Timeline(verbs::timeline::Args),
|
Timeline(verbs::timeline::Args),
|
||||||
}
|
}
|
||||||
|
|
@ -102,6 +105,10 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
|
||||||
assert_kind(client, a.number, Kind::Pr)?;
|
assert_kind(client, a.number, Kind::Pr)?;
|
||||||
verbs::assign::run(client, a)
|
verbs::assign::run(client, a)
|
||||||
}
|
}
|
||||||
|
Cmd::Dependency(a) => {
|
||||||
|
assert_kind(client, a.number, Kind::Pr)?;
|
||||||
|
verbs::dependency::run(client, a)
|
||||||
|
}
|
||||||
Cmd::Timeline(a) => {
|
Cmd::Timeline(a) => {
|
||||||
assert_kind(client, a.number, Kind::Pr)?;
|
assert_kind(client, a.number, Kind::Pr)?;
|
||||||
verbs::timeline::run(client, a)
|
verbs::timeline::run(client, a)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue