hive-forge: show/pr show now list current dependencies

This commit is contained in:
damocles 2026-08-02 12:38:07 +02:00
commit 29a11476a4
3 changed files with 34 additions and 3 deletions

View file

@ -5,7 +5,7 @@ use clap::Args as ClapArgs;
use serde_json::json;
use crate::client::{Client, index};
use crate::verbs::print_json;
use crate::verbs::{dependency_summaries, print_json};
#[derive(ClapArgs)]
pub struct Args {
@ -33,6 +33,7 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
.iter()
.filter_map(|l| l.name.as_deref())
.collect();
let dependencies = dependency_summaries(client, owner, name, args.number)?;
let trimmed = json!({
"number": issue.number,
"title": issue.title,
@ -40,6 +41,7 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
"user": issue.user.as_ref().and_then(|u| u.login.as_deref()),
"assignees": assignees,
"labels": labels,
"dependencies": dependencies,
"body": issue.body,
});
print_json(&trimmed)

View file

@ -46,7 +46,7 @@ pub mod view;
use std::fmt::Write as _;
use anyhow::Result;
use serde_json::Value;
use serde_json::{Value, json};
use time::OffsetDateTime;
use time::format_description::well_known::Rfc3339;
@ -204,6 +204,33 @@ pub(crate) fn latest_reviews(client: &Client, repo: &str, pr: u64) -> Result<Vec
Ok(latest)
}
/// The current dependency list for an issue or PR — each entry names
/// another issue/PR this one is blocked on. Forgejo's dependency endpoint
/// works on the shared issue/PR index (PRs are issues internally under
/// the hood), so `issue show` and `pr show` both call this instead of
/// duplicating the fetch-and-shape step. A reviewer asked whether
/// `show`/`view` surface dependencies — they didn't (only `timeline`
/// rendered them, as history); this is the current-state complement.
///
/// # Errors
///
/// Propagates the forge API errors from listing dependencies.
pub(crate) fn dependency_summaries(
client: &Client,
owner: &str,
name: &str,
number: u64,
) -> Result<Vec<Value>> {
let deps = client
.api()
.issue_list_issue_dependencies(owner, name, index(number)?)
.send()?;
Ok(deps
.into_iter()
.map(|d| json!({ "number": d.number, "title": d.title }))
.collect())
}
#[cfg(test)]
mod tests {
use super::pct_encode;

View file

@ -5,7 +5,7 @@ use clap::Args as ClapArgs;
use serde_json::json;
use crate::client::{Client, index};
use crate::verbs::print_json;
use crate::verbs::{dependency_summaries, print_json};
#[derive(ClapArgs)]
pub struct Args {
@ -19,6 +19,7 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
.api()
.repo_get_pull_request(owner, name, index(args.number)?)
.send()?;
let dependencies = dependency_summaries(client, owner, name, args.number)?;
let trimmed = json!({
"number": pull.number,
"title": pull.title,
@ -28,6 +29,7 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
"head_sha": pull.head.as_ref().and_then(|h| h.sha.as_deref()),
"head_branch": pull.head.as_ref().and_then(|h| h.label.as_deref()),
"base_branch": pull.base.as_ref().and_then(|b| b.label.as_deref()),
"dependencies": dependencies,
});
print_json(&trimmed)
}