Skip to content

fix: handle GitHub monorepo URLs in apply flow#132

Merged
bryantgillespie merged 3 commits into
mainfrom
bry/fix-122-github-template-apply
May 13, 2026
Merged

fix: handle GitHub monorepo URLs in apply flow#132
bryantgillespie merged 3 commits into
mainfrom
bry/fix-122-github-template-apply

Conversation

@bryantgillespie

Copy link
Copy Markdown
Collaborator

Closes #122.

Summary

  • Users entering a monorepo root URL (e.g. https://github.com/directus-labs/starters/) previously hit TypeError: Cannot read properties of null (reading 'templateName'). Now the CLI walks nested dirs and either auto-selects the single template found, prompts the user to pick when multiple exist, or errors clearly when none.
  • transformGitHubUrl hardened: tolerates trailing slashes, .git suffix, preserves /tree/<ref>/... branch refs (previously silently discarded), throws on unparseable input instead of returning the literal string "Invalid URL".
  • Programmatic mode (-p --templateType=github) gets an actionable error listing copy-pasteable --templateLocation="..." URLs for each discovered template. Single-nested case auto-descends with a warning suggesting the user pin the full URL to avoid surprises if more templates are added to the repo later.

What changed

  • src/lib/utils/transform-github-url.ts — extracted parseGitHubUrl helper; hardened regex.
  • src/lib/utils/get-template.ts — new getInteractiveGithubTemplate returning Template[]; getGithubTemplate now uses shared download helper and emits actionable errors.
  • src/commands/apply.ts — new selectGithubTemplate method mirroring selectLocalTemplate pattern.

Test plan

  • pnpm tsc --noEmit passes
  • Interactive apply against https://github.com/directus-labs/starters/ — shows picker with CMS / CMS - i18n
  • Interactive apply against .../tree/main/cms/directus/template — auto-selects single template
  • Interactive apply against URL with trailing slash / .git — handled
  • Programmatic apply -p --templateType=github --templateLocation="https://github.com/directus-labs/starters/" — errors with copy-pasteable list
  • Garbage URL — clean Invalid GitHub URL error

Resolves #122. transformGitHubUrl now tolerates trailing slashes, .git
suffix, and preserves branch refs. When a GitHub URL points at a repo
without a templateName package.json at its root, walk nested dirs to
discover templates. Interactive flow prompts user to pick; programmatic
mode errors with copy-pasteable --templateLocation lines.
@bryantgillespie bryantgillespie requested a review from Copilot May 13, 2026 15:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Improves the CLI “apply” flow for GitHub-hosted templates by correctly handling monorepo root URLs and preserving branch refs, preventing null-template crashes and providing actionable selection/error paths.

Changes:

  • Added robust GitHub URL parsing and ref/subpath preservation (trailing slash / .git tolerant).
  • Enhanced GitHub template discovery by walking nested directories and producing clearer outcomes for 0/1/many templates.
  • Added interactive GitHub template selection in apply, mirroring the local template selection UX.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/lib/utils/transform-github-url.ts Adds parseGitHubUrl and updates URL transformation to preserve /tree/<ref>/... and reject invalid inputs.
src/lib/utils/get-template.ts Adds shared GitHub download helper, nested template discovery behavior, and a new interactive GitHub template getter.
src/commands/apply.ts Introduces interactive template selection for GitHub URLs via selectGithubTemplate.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/commands/apply.ts
Comment thread src/lib/utils/transform-github-url.ts Outdated
Comment thread src/lib/utils/get-template.ts
Comment thread src/lib/utils/get-template.ts
@bryantgillespie bryantgillespie merged commit 3358531 into main May 13, 2026
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.

The apply command doesn't let you use a Github repo as source of template

2 participants