feat: port fromRepo/fromGist to Octokit (fixes #38) - #215
Draft
claude[bot] wants to merge 1 commit into
Draft
Conversation
Load fiddles from GitHub repositories and gists through the GitHub REST API (@octokit/rest) instead of cloning with simple-git. This fixes loading repos and gists whose default branch is `main`: fromRepo no longer hardcodes `master`. When no checkout is supplied it resolves the repository's actual default branch via the API; an explicit checkout is still honored. - fromGist now fetches gist files directly via the Gists API. - fromRepo parses the GitHub URL, resolves the ref, and fetches file contents via the API, routing gist URLs to fromGist. - An optional GitHub token is read from FIDDLE_CORE_GITHUB_TOKEN and passed to Octokit for better rate limits; unauthenticated access still works. - fromEntries accepts an optional source label so repo/gist provenance is preserved on the resulting Fiddle. - Drops the simple-git dependency. Closes #38
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
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.
Requested by Samuel Attard · Slack thread
What changed
Before: loading a fiddle from a GitHub repo or gist defaulted to checking out the
masterbranch, so any repo/gist that defaults tomainfailed to load (#38).After:
fromReporesolves the repository's actual default branch when no checkout is given, so bothmaster- andmain-defaulting repos load correctly. An explicitcheckoutargument still wins. Loading now goes through the GitHub API instead of a git clone.Fixes #38.
How
simple-gitwith@octokit/rest(@octokit/rest@^22.0.1added,simple-gitremoved).src/octokit.ts:getOctokit()returns a shared Octokit client, authenticating withprocess.env.FIDDLE_CORE_GITHUB_TOKENwhen set (re-created if the env token changes at runtime), unauthenticated otherwise.src/fiddle.ts:fromRepo(url, checkout?)parses the GitHub URL, resolves the repo'sdefault_branchviarepos.getwhen nocheckoutis passed, lists root files viarepos.getContent, fetches and base64-decodes each file, and writes them throughfromEntries. Gist URLs route tofromGist, which now uses the Gists API directly. AddedparseRepoUrl/parseGistUrlhelpers;fromEntriesgained an optionalsourceparam to preserve repo/gist provenance.nockto mock the GitHub API: covers default-branch resolution (bothmainandmaster), explicit checkout, and the token-auth path.Notes
fromRepo'scheckoutdefault changed from'master'to dynamic resolution — backward-compatible for callers passing an explicit checkout; callers relying on the implicit'master'now get the repo's real default branch (the intended fix).setGithubToken/removeGithubTokenconvenience exports from the earlier stale PR feat: replace simple-git with octokit to load fiddle #50 — the env-var mechanism covers the requirement; can add if maintainers want them.Verification
yarn build(tsc) — clean.yarn lint(oxfmt + oxlint) — 0 warnings, 0 errors.yarn test(vitest) — 86 passed, 2 skipped.Generated by Claude Code