Skip to content

fix: use Cloudflare Pages API default per_page for pagination#305

Merged
Aureliolo merged 2 commits intomainfrom
fix/cloudflare-pagination-per-page
Mar 11, 2026
Merged

fix: use Cloudflare Pages API default per_page for pagination#305
Aureliolo merged 2 commits intomainfrom
fix/cloudflare-pagination-per-page

Conversation

@Aureliolo
Copy link
Copy Markdown
Owner

Summary

  • Cloudflare Pages deployments API rejects per_page=100 when combined with the page parameter (HTTP 400: "Invalid list options provided")
  • Changes pagination to use per_page=25 (Cloudflare's documented default) via a PER_PAGE variable
  • Updates the pagination break check to use the variable instead of hardcoded 100

Context: The pagination was added in #304 to handle PRs with >100 deployments. The cleanup job failed on first run because per_page=100&page=1 is rejected by the Cloudflare API. This was correctly surfaced as exit 1 (previously would have been silently swallowed).

Test plan

  • Cleanup Preview job succeeds on PR close (no HTTP 400 from Cloudflare)
  • Pagination still works correctly for PRs with >25 deployments

Cloudflare Pages deployments API rejects per_page=100 when combined
with the page parameter. Use per_page=25 (the documented default)
to stay within API limits while still paginating correctly.
Copilot AI review requested due to automatic review settings March 11, 2026 20:15
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Note

Gemini is unable to generate a summary for this pull request due to the file types involved not being currently supported.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 11, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e0c15e6a-f1ea-4603-a5db-17ad3f56135f

📥 Commits

Reviewing files that changed from the base of the PR and between d35cc43 and 290e983.

📒 Files selected for processing (1)
  • .github/workflows/pages-preview.yml
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Deploy Preview
  • GitHub Check: Analyze (python)
🔇 Additional comments (2)
.github/workflows/pages-preview.yml (2)

265-273: LGTM!

The introduction of the PER_PAGE variable with accompanying documentation comment is a clean fix. Using a variable rather than hardcoding improves maintainability, and the comment provides helpful context about the Cloudflare API behavior for future maintainers.


307-307: LGTM!

The pagination termination condition correctly references $PER_PAGE for consistency with the API request parameter.


📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Adjusted preview deployment pagination to use the API's default page size and consistent end-of-page logic, improving reliability of preview listings and reducing API load during deployment previews.

Walkthrough

Updates the GitHub Actions workflow for Cloudflare Pages previews to introduce a configurable PER_PAGE=25, using per_page=${PER_PAGE} in API requests and updating the pagination termination check to compare against PER_PAGE; adds a clarifying comment about Cloudflare Pages API behavior.

Changes

Cohort / File(s) Summary
GitHub Actions Workflow Configuration
​.github/workflows/pages-preview.yml
Adds PER_PAGE=25, changes Cloudflare deployments request to per_page=${PER_PAGE}, updates loop break condition to use PER_PAGE instead of hardcoded 100, and adds explanatory comment about Pages API pagination.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title directly and clearly summarizes the main change: using Cloudflare Pages API's default per_page value for pagination instead of a hardcoded value.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the API limitation, the fix, and providing context about the issue and test plan.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/cloudflare-pagination-per-page
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/cloudflare-pagination-per-page

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 11, 2026

Greptile Summary

This PR is a targeted bug fix for the cleanup-preview job in .github/workflows/pages-preview.yml. It replaces the hardcoded per_page=100 query parameter (rejected by the Cloudflare Pages API with HTTP 400 when the page parameter is also present) with per_page=25, stored in a PER_PAGE shell variable. The pagination break condition is updated to reference the variable instead of the old literal, keeping the two values in sync.

Key changes:

  • Introduces PER_PAGE=25 variable (Cloudflare's documented default page size) to fix the HTTP 400 error that broke the first run of the cleanup job after pagination was added in fix: correct deploy-pages SHA and improve preview cleanup reliability #304.
  • Updates the break condition from [ "$PAGE_COUNT" -lt 100 ] to [ "$PAGE_COUNT" -lt "$PER_PAGE" ], eliminating the previously inconsistent hardcoded literal.
  • Adds an inline comment explaining why 25 is used, which aids future maintainability.

The fix is minimal, correct, and low-risk. The trade-off is that per_page=25 requires up to 4× more API requests compared to per_page=100 for large deployment sets, but for a one-time PR-close cleanup this has no practical impact. It is worth noting that the Cloudflare Pages API may accept values between 25 and 100 (e.g., 50) — if a higher limit is ever confirmed, PER_PAGE can be updated in a single place.

Confidence Score: 4/5

  • This PR is safe to merge — the fix directly resolves a confirmed HTTP 400 API rejection with a minimal, well-scoped change.
  • The change is confined to two lines in a single shell script block, is internally consistent (variable defined once, used in both the URL and the break condition), and addresses a documented API constraint. No logic is restructured and no new failure modes are introduced.
  • No files require special attention.

Important Files Changed

Filename Overview
.github/workflows/pages-preview.yml Introduces PER_PAGE=25 variable to fix HTTP 400 from Cloudflare Pages API when using per_page=100 with the page query parameter; updates pagination break condition to use the variable instead of a hardcoded literal.

Sequence Diagram

sequenceDiagram
    participant GHA as GitHub Actions<br/>(cleanup-preview job)
    participant CF as Cloudflare Pages API

    GHA->>GHA: Set PER_PAGE=25, PAGE=1, DEPLOYMENTS=""
    loop Until page is incomplete
        GHA->>CF: GET /deployments?per_page=25&page=PAGE
        CF-->>GHA: HTTP 200 + JSON body
        GHA->>GHA: Extract matching deployment IDs for branch
        GHA->>GHA: PAGE_COUNT = length of .result
        alt PAGE_COUNT < PER_PAGE (25)
            GHA->>GHA: break (last page reached)
        else PAGE_COUNT == PER_PAGE
            GHA->>GHA: PAGE++, continue
        end
    end
    loop For each deployment ID
        GHA->>CF: DELETE /deployments/{id}?force=true
        CF-->>GHA: HTTP 200 (or 4xx for most-recent-deployment restriction)
    end
    GHA->>GHA: echo "Deleted N preview deployments"
Loading

Last reviewed commit: 290e983

Copy link
Copy Markdown

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

Updates the Cloudflare Pages preview cleanup workflow pagination to avoid an API 400 error caused by combining page with per_page=100, aligning the request with Cloudflare’s documented default page size.

Changes:

  • Introduces a PER_PAGE=25 variable for Cloudflare Pages deployments pagination.
  • Updates the list deployments request to use per_page=${PER_PAGE} instead of 100.
  • Adjusts the pagination termination condition to use PER_PAGE rather than a hardcoded value.

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


# Paginate through all deployments for this branch
# Note: Cloudflare prevents deleting the most recent deployment per project — that one will remain
# Cloudflare Pages API rejects per_page=100 with page param; use default (25)
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

The new comment says we “use default (25)”, but the script still explicitly sets per_page=${PER_PAGE}. Consider rewording to clarify that we’re explicitly using Cloudflare’s documented default value (25), not omitting the parameter (the actual API default behavior).

Suggested change
# Cloudflare Pages API rejects per_page=100 with page param; use default (25)
# Cloudflare Pages API rejects per_page=100 with page param; explicitly use documented default page size (25)

Copilot uses AI. Check for mistakes.
@Aureliolo Aureliolo merged commit 9fec245 into main Mar 11, 2026
14 of 15 checks passed
@Aureliolo Aureliolo deleted the fix/cloudflare-pagination-per-page branch March 11, 2026 20:28
Aureliolo added a commit that referenced this pull request Mar 11, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.1.1](v0.1.0...v0.1.1)
(2026-03-11)


### Features

* add PR preview deployments via Cloudflare Pages
([#302](#302))
([b73c45a](b73c45a))


### Bug Fixes

* correct deploy-pages SHA and improve preview cleanup reliability
([#304](#304))
([584d64a](584d64a))
* harden API key hashing with HMAC-SHA256 and clean up legacy changelog
([#292](#292))
([5e85353](5e85353))
* upgrade upload-pages-artifact to v4 and add zizmor workflow linting
([#299](#299))
([2eac571](2eac571))
* use Cloudflare Pages API default per_page for pagination
([#305](#305))
([9fec245](9fec245))


### Documentation

* remove milestone references and rebrand to SynthOrg
([#289](#289))
([57a03e0](57a03e0))
* set up documentation site, release CI, and sandbox hardening
([#298](#298))
([0dec9da](0dec9da))
* split DESIGN_SPEC.md into 7 focused design pages
([#308](#308))
([9ea0788](9ea0788))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Signed-off-by: Aurelio <19254254+Aureliolo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants