Skip to content

Paginate files and commits in gh pr view --json#13340

Open
SebTardif wants to merge 1 commit into
cli:trunkfrom
SebTardif:fix/pr-files-commits-pagination
Open

Paginate files and commits in gh pr view --json#13340
SebTardif wants to merge 1 commit into
cli:trunkfrom
SebTardif:fix/pr-files-commits-pagination

Conversation

@SebTardif
Copy link
Copy Markdown

@SebTardif SebTardif commented May 4, 2026

gh pr view --json files and --json commits silently truncate at 100 items because the initial query never follows pagination.

This adds PageInfo to the Files and Commits structs, requests pageInfo in the GraphQL fragments, and adds preloadPrFiles / preloadPrCommits that page through remaining results in the existing errgroup. This matches the pattern already used by reviews, comments, and closingIssuesReferences.

Also adds the graphql:"authors(first: 100)" tag to PullRequestCommitCommit.Authors so the struct-based pagination query includes the required argument (the raw GraphQL fragment already had it).

Fixes #13338

Copilot AI review requested due to automatic review settings May 4, 2026 05:10
@SebTardif SebTardif requested a review from a team as a code owner May 4, 2026 05:10
@SebTardif SebTardif requested a review from babakks May 4, 2026 05:10
@github-actions github-actions Bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed unmet-requirements and removed needs-triage needs to be reviewed labels May 4, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Thanks for your pull request! Unfortunately, it doesn't meet the requirements for review:

  • None of the referenced issues have the help wanted label

Please update your PR to address the above. This PR will be automatically closed in 4 days if these requirements are not met.

Full contribution requirements
  1. Include a detailed description of what this PR does
  2. Link to an issue with the help wanted label (use Fixes #123 or Closes #123)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds pagination to gh pr view --json files and --json commits to avoid silent truncation at 100 items, aligning behavior with existing paginated PR subresources (reviews/comments/closingIssuesReferences).

Changes:

  • Extend PR GraphQL fragments for files and commits to include pageInfo { hasNextPage endCursor }.
  • Add PageInfo to the PullRequest.Files and PullRequest.Commits response structs.
  • Implement preloadPrFiles / preloadPrCommits to fetch subsequent pages and wire them into finder.Find’s existing errgroup preload flow.
  • Update query builder tests’ expected fragment output for files.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pkg/cmd/pr/shared/finder.go Adds concurrent preloading functions to paginate files and commits beyond the first 100 nodes.
api/query_builder_test.go Updates expected compressed query strings to reflect pageInfo being included.
api/query_builder.go Extends prFiles / prCommits fragments with pageInfo.
api/queries_pr.go Adds PageInfo fields to PullRequest.Files and PullRequest.Commits to receive pagination data.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +573 to +577
func preloadPrFiles(client *http.Client, repo ghrepo.Interface, pr *api.PullRequest) error {
if !pr.Files.PageInfo.HasNextPage {
return nil
}

Comment on lines +626 to +630
Commits struct {
Nodes []api.PullRequestCommit
PageInfo struct {
HasNextPage bool
EndCursor string
@github-actions
Copy link
Copy Markdown

Thanks for your pull request! Unfortunately, it doesn't meet the requirements for review:

  • None of the referenced issues have the help wanted label

Please update your PR to address the above. This PR will be automatically closed in 4 days if these requirements are not met.

Full contribution requirements
  1. Include a detailed description of what this PR does
  2. Link to an issue with the help wanted label (use Fixes #123 or Closes #123)

@babakks
Copy link
Copy Markdown
Member

babakks commented May 13, 2026

Reopened as discussed in #13338 (comment)

`gh pr view --json files` and `gh pr view --json commits` silently
truncate results at 100 items because the initial GraphQL query fetches
only the first page but never follows pagination.

Add PageInfo to the Files and Commits structs, request
pageInfo{hasNextPage,endCursor} in the GraphQL fragments, and add
preloadPrFiles/preloadPrCommits functions that page through remaining
results using the existing errgroup pattern already used by reviews,
comments, and closingIssuesReferences.

Also add the `graphql:"authors(first: 100)"` tag to
PullRequestCommitCommit.Authors so the struct-based pagination query
includes the required argument (the raw GraphQL fragment already had it).

Fixes cli#13338

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
@SebTardif SebTardif force-pushed the fix/pr-files-commits-pagination branch from bab3fa6 to 0292162 Compare May 15, 2026 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh pr view --json files and --json commits silently truncate at 100 items

4 participants