fix: handle GitHub monorepo URLs in apply flow#132
Merged
Conversation
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.
There was a problem hiding this comment.
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 /
.gittolerant). - 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.
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.
Closes #122.
Summary
https://github.com/directus-labs/starters/) previously hitTypeError: 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.transformGitHubUrlhardened: tolerates trailing slashes,.gitsuffix, preserves/tree/<ref>/...branch refs (previously silently discarded), throws on unparseable input instead of returning the literal string"Invalid URL".-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— extractedparseGitHubUrlhelper; hardened regex.src/lib/utils/get-template.ts— newgetInteractiveGithubTemplatereturningTemplate[];getGithubTemplatenow uses shared download helper and emits actionable errors.src/commands/apply.ts— newselectGithubTemplatemethod mirroringselectLocalTemplatepattern.Test plan
pnpm tsc --noEmitpassesapplyagainsthttps://github.com/directus-labs/starters/— shows picker with CMS / CMS - i18napplyagainst.../tree/main/cms/directus/template— auto-selects single templateapplyagainst URL with trailing slash /.git— handledapply -p --templateType=github --templateLocation="https://github.com/directus-labs/starters/"— errors with copy-pasteable listInvalid GitHub URLerror