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:
parent
52f589780f
commit
0e5c61d12c
9 changed files with 164 additions and 90 deletions
|
|
@ -5,16 +5,10 @@
|
|||
|
||||
use anyhow::Result;
|
||||
use clap::Args as ClapArgs;
|
||||
use forgejo_api::structs::{IssueListLabelsQuery, Label};
|
||||
use forgejo_api::structs::Label;
|
||||
|
||||
use crate::client::Client;
|
||||
use crate::verbs::print_json;
|
||||
|
||||
/// Page size on the label list endpoint.
|
||||
const PAGE_SIZE: u32 = 50;
|
||||
|
||||
/// Runaway cap on label pagination — same ceiling the raw client used.
|
||||
const MAX_PAGES: u32 = 10;
|
||||
use crate::verbs::{labels, print_json};
|
||||
|
||||
#[derive(ClapArgs)]
|
||||
pub struct Args {
|
||||
|
|
@ -23,23 +17,7 @@ pub struct Args {
|
|||
}
|
||||
|
||||
pub fn run(client: &Client, args: Args) -> Result<()> {
|
||||
let (owner, name) = client.owner_repo()?;
|
||||
// Repos can carry more than one page of labels; paginate so the list
|
||||
// is complete rather than capped at the first page.
|
||||
let mut labels: Vec<Label> = Vec::new();
|
||||
for page in 1..=MAX_PAGES {
|
||||
let (_, batch) = client
|
||||
.api()
|
||||
.issue_list_labels(owner, name, IssueListLabelsQuery::default())
|
||||
.page(page)
|
||||
.page_size(PAGE_SIZE)
|
||||
.send()?;
|
||||
let short = batch.len() < PAGE_SIZE as usize;
|
||||
labels.extend(batch);
|
||||
if short {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let labels = labels::repo_labels(client)?;
|
||||
let filtered: Vec<&Label> = labels
|
||||
.iter()
|
||||
.filter(|l| {
|
||||
|
|
|
|||
Loading…
Reference in a new issue