Watch
0
0
Fork
You've already forked hyperhive
0

hive-forge: page past the forge's 50-row clamp; show list --json truncation

The forge clamps page_size to 50. branches, pr reviews, the review
bodies merged into `comments <pr>`, and view's comment list each sent
one request, so anything past the first page was dropped silently.
labels::repo_labels did loop, but asked for 100/page and stopped on
`len < 100`, so a clamped full page of 50 ended the walk.

Add verbs::all_pages: requests 50/page until a short page, capped at
50 pages with a stderr warning when the cap is hit. Use it in all of
the above; repo-labels now calls labels::repo_labels instead of its
own copy of the loop.

list --json now prints the same "N of M shown" stderr trailer as the
pretty output; its paging and stdout shape are unchanged.

Closes #5051
This commit is contained in:
atlas 2026-10-09 11:44:03 +02:00 • committed by mara
commit 0e5c61d12c

View file

@ -7,7 +7,7 @@ use forgejo_api::structs::{DeleteLabelsOption, IssueLabelsOption, IssueListLabel
use serde_json::json;
use crate::client::{Client, index};
use crate::verbs::print_json;
use crate::verbs::{all_pages, print_json};
#[derive(ClapArgs)]
pub struct Args {
@ -105,37 +105,24 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
}
/// The repo's whole label set, for name → id resolution. `pub(crate)` so
/// other verbs (`issue create`, `pr create`, `list`) can resolve a label
/// name without duplicating the lookup.
/// other verbs (`issue create`, `pr create`, `list`, `repo-labels`) share
/// one lookup.
///
/// Paginated, where this used to ask for one page of 100 — **a page size
/// with no page loop is a lie the size of the page.** Truncation here is
/// worse than it looks: it doesn't drop a result, it makes a *valid*
/// label past the cut fail to resolve, and then prints an "available
/// labels" list that is itself incomplete, so the error argues for the
/// typo. Same root as the `list` trailer bug (assuming one request
/// returns the whole population), opposite direction — that one was a
/// false positive, this is a false negative.
/// Every page, not one: a page size with no page loop silently truncates
/// the set, and a truncated set makes a *valid* label past the cut fail to
/// resolve, with an "available labels" list that is itself incomplete, so
/// the error argues for the typo.
pub(crate) fn repo_labels(client: &Client) -> Result<Vec<Label>> {
/// Generous cap so a misbehaving server can't spin us forever.
const MAX_PAGES: u32 = 50;
const PAGE: u32 = 100;
let (owner, name) = client.owner_repo()?;
let mut all = Vec::new();
for page in 1..=MAX_PAGES {
all_pages(|page, size| {
let (_, batch) = client
.api()
.issue_list_labels(owner, name, IssueListLabelsQuery::default())
.page(page)
.page_size(PAGE)
.page_size(size)
.send()?;
let short = batch.len() < PAGE as usize;
all.extend(batch);
if short {
break;
}
}
Ok(all)
Ok(batch)
})
}
/// Resolve label names to ids, hard-erroring if any name doesn't match an