Skip to content

feat: port fromRepo/fromGist to Octokit (fixes #38) - #215

Draft
claude[bot] wants to merge 1 commit into
mainfrom
octokit-fromRepo-port
Draft

feat: port fromRepo/fromGist to Octokit (fixes #38)#215
claude[bot] wants to merge 1 commit into
mainfrom
octokit-fromRepo-port

Conversation

@claude

@claude claude Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Requested by Samuel Attard · Slack thread

What changed

Before: loading a fiddle from a GitHub repo or gist defaulted to checking out the master branch, so any repo/gist that defaults to main failed to load (#38).

After: fromRepo resolves the repository's actual default branch when no checkout is given, so both master- and main-defaulting repos load correctly. An explicit checkout argument still wins. Loading now goes through the GitHub API instead of a git clone.

Fixes #38.

How

  • Replaced simple-git with @octokit/rest (@octokit/rest@^22.0.1 added, simple-git removed).
  • New src/octokit.ts: getOctokit() returns a shared Octokit client, authenticating with process.env.FIDDLE_CORE_GITHUB_TOKEN when 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's default_branch via repos.get when no checkout is passed, lists root files via repos.getContent, fetches and base64-decodes each file, and writes them through fromEntries. Gist URLs route to fromGist, which now uses the Gists API directly. Added parseRepoUrl/parseGistUrl helpers; fromEntries gained an optional source param to preserve repo/gist provenance.
  • Tests rewritten with nock to mock the GitHub API: covers default-branch resolution (both main and master), explicit checkout, and the token-auth path.

Notes

  • fromRepo's checkout default 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).
  • Loading fetches the repo root's files (matching how fiddles are structured); subdirectories aren't recursed.
  • Did not add the setGithubToken/removeGithubToken convenience 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

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
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​octokit/​rest@​22.0.1991009081100

View full report

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.

Can't Load Gist

1 participant