Skip to content

fix!: Use cursor pagination for ListAttestations - #4755

Open
burrows99 wants to merge 1 commit into
google:masterfrom
burrows99:fix-attestations-cursor-pagination
Open

burrows99 wants to merge 1 commit into
google:masterfrom
burrows99:fix-attestations-cursor-pagination

Conversation

@burrows99

Copy link
Copy Markdown

The list-attestations endpoints (GET /users/{username}/attestations/{subject_digest}, /orgs/{org}/..., /repos/{owner}/{repo}/...) page with before/after cursors; the OpenAPI description has per_page, before, after and no page. ListAttestations takes *ListOptions, so:

  • a caller cannot ask for any page after the first (the API ignores page=2 and returns page 1 again), and
  • ListAttestationsIter stops after one page, because the Link header carries after=..., never a page number.

This switches the three methods to *ListCursorOptions, as ListConcurrencyGroups and ListOrganizationCopilotSpaces already do for cursor-paged endpoints, and regenerates the iterators (they now follow resp.After). This is a breaking change: callers passing &github.ListOptions{PerPage: n} change it to &github.ListCursorOptions{PerPage: n}; nil still works.

flowchart TD
    A[List attestations for a digest with per_page 1] --> B{Second page}
    B -->|Before| C[Iterator stops after one attestation]
    B -->|After| D[Iterator sends after cursor and gets both]
Loading

Narrated recording, before then after (sound on):

evidence.mp4

The demo calls the real API (read-only) for a gh 2.106.0 release asset in cli/cli, which has two attestations, and logs each request:

Commands and output

master:

$ go run . deb 1
  GET /repos/cli/cli/attestations/sha256:31c0befe386f...?per_page=1
  attestation 72398006
total: 1
$ go run . deb 0
  GET /repos/cli/cli/attestations/sha256:31c0befe386f...
  attestation 72398006
  attestation 72397360
total: 2

this branch:

$ go run . deb 1
  GET /repos/cli/cli/attestations/sha256:31c0befe386f...?per_page=1
  attestation 72398006
  GET /repos/cli/cli/attestations/sha256:31c0befe386f...?after=72398006&per_page=1
  attestation 72397360
total: 2
$ go run . deb 1 org
  GET /orgs/cli/attestations/sha256:31c0befe386f...?per_page=1
  attestation 72398006
  GET /orgs/cli/attestations/sha256:31c0befe386f...?after=72398006&per_page=1
  attestation 72397360
total: 2
$ go run . deb 0
  GET /repos/cli/cli/attestations/sha256:31c0befe386f...
  attestation 72398006
  attestation 72397360
total: 2
$ go run . checksums 1
  GET /repos/cli/cli/attestations/sha256:1822d8b8c11a...?per_page=1
  attestation 72398006
total: 1

Edge cases and unchanged behaviour checked (against the real API in the demo): the org endpoint pages the same way, the default page size (nil opts) still returns both, and a digest with a single attestation returns one.

Tests: go test -run Attestation ./github passes; the updated unit tests check that after and per_page are sent. On master the same cursor Link header makes ListAttestationsIter return 3 of 7 items (checked with a throwaway test; the updated tests do not compile against master's signature). script/lint.sh passes. I did not run the full script/test.sh.

AI assistance: Claude Code found the bug and wrote the change, the test updates and the demo.

🤖 Generated with Claude Code

The list-attestations endpoints for users, organizations and
repositories page with `before`/`after` cursors and ignore `page`.
ListAttestations took ListOptions, so callers could not reach any page
after the first, and ListAttestationsIter stopped after one page
because the Link header never carries a page number.

Take ListCursorOptions instead, as other cursor-paginated endpoints do,
and regenerate the iterators.

BREAKING CHANGE: `ListAttestations` and `ListAttestationsIter` on
`OrganizationsService`, `RepositoriesService` and `UsersService` now
take `*ListCursorOptions` instead of `*ListOptions`.
@gmlewis gmlewis added NeedsReview PR is awaiting a review before merging. Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). labels Dec 2, 2026
@codecov

codecov Bot commented Dec 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.63%. Comparing base (db78161) to head (d13670f).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4755   +/-   ##
=======================================
  Coverage   98.63%   98.63%           
=======================================
  Files         204      204           
  Lines       19165    19165           
=======================================
  Hits        18904    18904           
  Misses        261      261           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). NeedsReview PR is awaiting a review before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants