One-click Post to GitHub (GitHub App) - #14
Merged
Conversation
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.
Deploying mlsystems with
|
| Latest commit: |
7dbae58
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e95ddbdd.mlsystems.pages.dev |
| Branch Preview URL: | https://feature-post-to-github.mlsystems.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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.functions/api/create-pr.ts) authenticates as our installed GitHub App (private key from env → JWT → installation token), then creates a branch off the latestmain, commits the files, and opens the PR. The App token never leaves the server.SITE.githubPostEnabled(button hidden until true) + anOrigincheck on the endpoint.Required setup (not in code)
GitHub App (Org → Settings → Developer settings → GitHub Apps → New):
MLSysDev/mlsystems.devCloudflare Pages → Settings → Environment variables:
GH_APP_ID,GH_APP_INSTALLATION_ID,GH_APP_PRIVATE_KEY(paste the .pem)ALLOWED_ORIGIN,GH_REPOThen set
SITE.githubPostEnabled = trueand redeploy.Notes
Not merging — for review + setup.