diff --git a/docs/tools/forge.md b/docs/tools/forge.md index f3dead35..53b5cb51 100644 --- a/docs/tools/forge.md +++ b/docs/tools/forge.md @@ -37,7 +37,7 @@ hive-forge pr-reviews 42 --comment -m "msg" # submit COMMENT review hive-forge diff 42 # unified diff (lockfile hunks collapsed by default) hive-forge diff 42 --full # include unfiltered lockfile hunks hive-forge list # open issues/PRs -hive-forge list --kind pr --state all --all # every PR across all pages (repo-wide sweep; --all follows pagination) +hive-forge list --kind pr --state all --page 2 # page 2 of all PRs (walk --page 1,2,… with --limit as page size for a repo-wide sweep) hive-forge milestone # list milestones hive-forge branches deployed/ # filter branches by pattern hive-forge tree-sha main # git tree SHA for a ref diff --git a/hive-forge/src/verbs/list.rs b/hive-forge/src/verbs/list.rs index 9cac82df..01197652 100644 --- a/hive-forge/src/verbs/list.rs +++ b/hive-forge/src/verbs/list.rs @@ -1,8 +1,9 @@ //! `list [--kind issue|pr|both] [--state open|closed|all] [--assignee -//! ] [--author ] [--label ] [--limit N] [--all]` — +//! ] [--author ] [--label ] [--limit N] [--page N]` — //! list issues / PRs with filters. Pretty `#NNN [author] title` output by -//! default; `--json` for piping. `--all` drains every page (for repo-wide -//! analysis) instead of a single `--limit` page. +//! default; `--json` for piping. `--limit` is the page size and `--page` +//! the 1-based page number — walk pages incrementally for a large result +//! set rather than pulling the whole population into one response. //! //! Mirrors Forgejo's `GET /repos/{owner}/{repo}/issues` query-string //! filters one-for-one so the mental model carries over. Closes the @@ -84,29 +85,27 @@ pub struct Args { /// Filter to items carrying any of these label names. Repeatable. #[arg(long = "label")] labels: Vec, - /// Max items to return (default: 30; forge's per-page cap applies). + /// Page size — items per page (default: 30; forge's per-page cap, + /// ~50, applies). #[arg(long, default_value_t = 30)] limit: u64, - /// Drain ALL matching items across every page, not just the first - /// `--limit` (which the forge caps at its per-page max, ~50). Follows - /// pagination up to a safety cap. Use for repo-wide analysis — e.g. - /// `--kind pr --state all --all` to sweep every PR. Overrides - /// `--limit` (each page is fetched at the per-page max). - #[arg(long)] - all: bool, + /// Page number to fetch (1-based; default 1). Combine with `--limit` + /// to walk a large result set incrementally — fetch page 1, process, + /// fetch page 2, … until a short/empty page. This keeps each call + /// token-bounded (one page at a time) instead of pulling a whole + /// repo's population into a single response. + #[arg(long, default_value_t = 1)] + page: u64, } pub fn run(client: &Client, args: Args) -> Result<()> { let repo = client.repo(); - // With `--all` each page is fetched at the forge's per-page max so we - // make the fewest round-trips; `get_json_all` then follows the - // `Link: rel="next"` chain. Otherwise honour `--limit` as a single page. - let per_page = if args.all { 50 } else { args.limit }; let mut path = format!( - "/repos/{repo}/issues?type={}&state={}&limit={}", + "/repos/{repo}/issues?type={}&state={}&limit={}&page={}", args.kind.api_value(), args.state.api_value(), - per_page + args.limit, + args.page ); if let Some(u) = args.assignee.as_deref() && !u.is_empty() @@ -130,20 +129,6 @@ pub fn run(client: &Client, args: Args) -> Result<()> { let encoded: Vec = args.labels.iter().map(|l| super::pct_encode(l)).collect(); write!(path, "&labels={}", encoded.join(",")).unwrap(); } - if args.all { - // Safety cap: 200 pages * 50/page = 10k items, well past any - // realistic repo while still bounding a runaway loop. - const MAX_PAGES: u32 = 200; - let items = client.get_json_all(&path, MAX_PAGES)?; - if client.json_mode() { - return print_json(&Value::Array(items)); - } - for item in &items { - print_row(item); - } - return Ok(()); - } - let resp = client.get_json(&path)?; if client.json_mode() { return print_json(&resp);