Skip to content

One-click Post to GitHub (GitHub App) - #14

Merged
HumbleBee14 merged 1 commit into
mainfrom
feature/post-to-github
Jul 13, 2026
Merged

One-click Post to GitHub (GitHub App)#14
HumbleBee14 merged 1 commit into
mainfrom
feature/post-to-github

Conversation

@HumbleBee14

Copy link
Copy Markdown
Member

What

Adds a Post to GitHub button in /write. One click → a PR with the full post folder is opened on this repo. No user login, no forks. The existing Download post flow is untouched (now shown as a secondary button).

How

  • Client (src/write/publish/github.ts) assembles the post files (index.mdx, .write-source.json, images, cover, component files) and POSTs them to /api/create-pr.
  • Cloudflare Pages Function (functions/api/create-pr.ts) authenticates as our installed GitHub App (private key from env → JWT → installation token), then creates a branch off the latest main, commits the files, and opens the PR. The App token never leaves the server.
  • Gated by SITE.githubPostEnabled (button hidden until true) + an Origin check on the endpoint.

Required setup (not in code)

GitHub App (Org → Settings → Developer settings → GitHub Apps → New):

  • Permissions: Contents: R/W, Pull requests: R/W
  • Install on MLSysDev/mlsystems.dev
  • Note App ID + Installation ID, generate a private key

Cloudflare Pages → Settings → Environment variables:

  • GH_APP_ID, GH_APP_INSTALLATION_ID, GH_APP_PRIVATE_KEY (paste the .pem)
  • (optional) ALLOWED_ORIGIN, GH_REPO

Then set SITE.githubPostEnabled = true and redeploy.

Notes

  • The Function deploys automatically with the site (Pages Functions) — no separate worker.
  • Turnstile anti-spam intentionally deferred; an origin check is in place and Turnstile is easy to add later.

Not merging — for review + setup.

A Cloudflare Pages Function authenticates as our installed GitHub App
(private key in env), then creates a branch, commits the post folder, and
opens a PR directly on the repo — always off the latest main. The client
just assembles the files (index.mdx, sidecar, images, cover) and POSTs them.
Writers click one button; the ZIP download stays as the fallback. Gated by
SITE.githubPostEnabled + an origin check on the endpoint.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mlsystems with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7dbae58
Status: ✅  Deploy successful!
Preview URL: https://e95ddbdd.mlsystems.pages.dev
Branch Preview URL: https://feature-post-to-github.mlsystems.pages.dev

View logs

@HumbleBee14 HumbleBee14 changed the title One-click Post to GitHub (GitHub App, no login/forks) One-click Post to GitHub (GitHub App) Jul 13, 2026
@HumbleBee14
HumbleBee14 merged commit cd5a1ff into main Jul 13, 2026
2 checks passed
@HumbleBee14
HumbleBee14 deleted the feature/post-to-github branch July 13, 2026 23:06
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.

1 participant