Skip to content

Add Netlify build plugin to cache docforge API responses#957

Open
klocke-io wants to merge 3 commits intomasterfrom
feature/docforge-cache-netlify-plugin
Open

Add Netlify build plugin to cache docforge API responses#957
klocke-io wants to merge 3 commits intomasterfrom
feature/docforge-cache-netlify-plugin

Conversation

@klocke-io
Copy link
Copy Markdown
Member

@klocke-io klocke-io commented Apr 30, 2026

/kind enhancement

What this PR does / why we need it:

Deploy preview builds are hitting GitHub API rate limits because docforge fetches documentation content from 35+ repositories on every build. With multiple concurrent deploy previews triggered by PRs, the shared GITHUB_OAUTH_TOKEN exhausts its 5,000 requests/hour budget.

This adds a local Netlify build plugin that uses the built-in utils.cache utility to persist docforge's HTTP disk cache (httpcache/diskv) between deploy preview builds. Cached responses use ETags for conditional requests — 304 Not Modified responses don't count against the rate limit.

Key behaviors:

  • Deploy previews: Cache is restored before build and saved after — drastically reducing API calls
  • Production builds (master): Cache is never used — always pulls fresh from GitHub
  • Invalidation on config change: Cache is invalidated when any .docforge/**/*.yaml file changes (via digests)
  • Daily expiry: Cache has a 24-hour TTL so stale content doesn't persist indefinitely

No changes to docforge itself — uses the existing --cache-dir flag.

Which issue(s) this PR fixes:
Fixes GitHub API rate limiting on Netlify deploy previews.

Special notes for your reviewer:

  • The build.command in netlify.toml may already be configured via the Netlify dashboard UI — if so, the [build] section here will override it
  • The plugin is ESM (import/export) matching the repo's "type": "module" in package.json

Summary by CodeRabbit

  • New Features

    • Implemented build caching to improve deployment performance on Netlify.
  • Chores

    • Updated build configuration and version control settings to support cache management across deployments.

Deploy preview builds hit GitHub API rate limits because docforge
fetches content from 35+ repos on every build. This local Netlify
plugin uses the built-in cache utility to persist docforge's HTTP
disk cache between deploy preview builds.

- Production builds always pull fresh (no cache)
- Cache invalidates when any .docforge/*.yaml config changes
- Cache expires after 24 hours (TTL)
@klocke-io klocke-io requested a review from a team as a code owner April 30, 2026 12:00
@gardener-prow gardener-prow Bot added the kind/enhancement Enhancement, improvement, extension label Apr 30, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 30, 2026

Deploy Preview for gardener-docs ready!

Name Link
🔨 Latest commit 6139d8a
🔍 Latest deploy log https://app.netlify.com/projects/gardener-docs/deploys/69f34e41c02d9200088ff974
😎 Deploy Preview https://deploy-preview-957--gardener-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@gardener-prow
Copy link
Copy Markdown

gardener-prow Bot commented Apr 30, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign kostov6 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@klocke-io has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 51 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d17c21d2-42cd-40e8-8918-ce012d137fc7

📥 Commits

Reviewing files that changed from the base of the PR and between a6464ec and 6139d8a.

📒 Files selected for processing (1)
  • plugins/netlify-plugin-docforge-cache/index.js
📝 Walkthrough

Walkthrough

A new Netlify plugin manages Docforge cache artifacts across CI/CD builds by restoring caches before builds and saving them afterward. Supporting configuration updates enable explicit cache directories in the build system and exclude cache files from version control.

Changes

Cohort / File(s) Summary
Git & Build Configuration
.gitignore, Makefile
Excludes .docforge-cache from version control and configures the build system to use an explicit cache directory via --cache-dir argument.
Netlify Deployment Config
netlify.toml
Adds the local Netlify plugin for cache management, updates build commands to use make ci-build for standard and preview contexts, and normalizes header configuration structure.
Netlify Cache Plugin
plugins/netlify-plugin-docforge-cache/index.js, plugins/netlify-plugin-docforge-cache/manifest.yml
Implements a new plugin with onPreBuild and onPostBuild hooks to restore cache before builds and scan/save Docforge artifact digests with 24-hour TTL after builds, with conditional behavior for production contexts.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • HeckEK
  • n-boshnakov

Poem

🐰 A cache so clever, built with care,
Pre and post hooks dance in air,
Docforge digests, saved with glee,
TTL'd for efficiency!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding a Netlify build plugin to cache docforge API responses, which is the primary objective of this PR.
Description check ✅ Passed The description comprehensively covers all required template sections with detailed context about the problem, solution, key behaviors, and special notes for reviewers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/docforge-cache-netlify-plugin

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 17 minutes and 51 seconds.

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

@gardener-prow gardener-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 30, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@plugins/netlify-plugin-docforge-cache/index.js`:
- Around line 7-15: The collectDigests function should be hardened: replace the
use of readdir(..., {withFileTypes: true, recursive: true}) and entry.parentPath
(Node 22-only) with a manual, synchronous or async recursive directory walk that
builds file paths via path.join(baseDir, relativePath) and only uses entry.name
and entry.isFile(); ensure you skip non-existent directories by wrapping the
top-level call to collectDigests in a try/catch that ignores ENOENT (or let
collectDigests itself catch and return [] on ENOENT). Update references to
collectDigests(...) and the internals of collectDigests to use the manual
recursion and path.join(dir, subpath) construction so Node 20 compatibility and
missing .docforge directory resilience are ensured.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fe2278a0-4329-4778-bb5e-c219ae508a9c

📥 Commits

Reviewing files that changed from the base of the PR and between 71eeeb1 and a6464ec.

📒 Files selected for processing (5)
  • .gitignore
  • Makefile
  • netlify.toml
  • plugins/netlify-plugin-docforge-cache/index.js
  • plugins/netlify-plugin-docforge-cache/manifest.yml

Comment thread plugins/netlify-plugin-docforge-cache/index.js Outdated
Replace recursive readdir with manual directory walk to avoid
dependency on entry.parentPath (Node 21.4+). Also handle ENOENT
gracefully when .docforge/ directory doesn't exist.
@gardener-prow gardener-prow Bot added the cla: yes Indicates the PR's author has signed the cla-assistant.io CLA. label Apr 30, 2026
Production builds should simply ignore the cache, not delete it.
The cache is shared across contexts — removing it during prod
would force the next deploy preview to rebuild from scratch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Indicates the PR's author has signed the cla-assistant.io CLA. kind/enhancement Enhancement, improvement, extension size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant