-
Notifications
You must be signed in to change notification settings - Fork 0
feat: use --name as repository domain in repo create and init #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
aeb446a
ba8a947
ad84956
6607b4f
a371fcc
ec80744
b65a47a
10dd57b
525298c
4d1e26a
b163f83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { getAdapter } from "../adapters"; | |
| import { createLoginSession, getHost, getToken } from "../auth"; | ||
| import { getCustomTypes, getSlices } from "../clients/custom-types"; | ||
| import { getProfile } from "../clients/user"; | ||
| import { checkIsDomainAvailable } from "../clients/wroom"; | ||
| import { DEFAULT_PRISMIC_HOST } from "../env"; | ||
| import { openBrowser } from "../lib/browser"; | ||
| import { CommandError, createCommand, type CommandConfig } from "../lib/command"; | ||
|
|
@@ -20,7 +21,7 @@ import { | |
| UnknownProjectRootError, | ||
| } from "../project"; | ||
| import { checkIsTypeBuilderEnabled, TypeBuilderRequiredError } from "../project"; | ||
| import { createRepo } from "./repo-create"; | ||
| import { createRepo, repositoryNameSchema } from "./repo-create"; | ||
|
|
||
| const config = { | ||
| name: "prismic init", | ||
|
|
@@ -34,7 +35,7 @@ const config = { | |
| migrated. | ||
| `, | ||
| options: { | ||
| repo: { type: "string", short: "r", description: "Repository name" }, | ||
| repo: { type: "string", short: "r", description: "Repository name (created if it doesn't exist)" }, | ||
| "no-browser": { | ||
| type: "boolean", | ||
| description: "Skip opening the browser automatically during login", | ||
|
|
@@ -96,15 +97,28 @@ export default createCommand(config, async ({ values }) => { | |
| } | ||
| } | ||
|
|
||
| let repo = explicitRepo ?? legacySliceMachineConfig?.repositoryName; | ||
| if (repo) { | ||
| const hasRepoAccess = profile.repositories.some((repository) => repository.domain === repo); | ||
| if (!hasRepoAccess) { | ||
| let repo = (explicitRepo ?? legacySliceMachineConfig?.repositoryName)?.toLowerCase(); | ||
| if (!repo) { | ||
| throw new CommandError( | ||
| "Missing --repo. Provide the repository to connect to (or to create if it doesn't exist).", | ||
| ); | ||
| } | ||
|
|
||
| const hasRepoAccess = profile.repositories.some((repository) => repository.domain === repo); | ||
| if (!hasRepoAccess) { | ||
| const parsed = repositoryNameSchema.safeParse(repo); | ||
| if (!parsed.success) { | ||
| throw new CommandError( | ||
| `Repository "${repo}" not found in your account. Check the name or request access to the repository.`, | ||
| `Invalid repository name "${repo}": ${parsed.error.issues[0]?.message ?? "Invalid value"}`, | ||
| ); | ||
| } | ||
|
|
||
| const available = await checkIsDomainAvailable({ domain: repo, token, host }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant domain availability check in init flowLow Severity When Additional Locations (1)Reviewed by Cursor Bugbot for commit b163f83. Configure here. |
||
| if (!available) { | ||
| throw new CommandError( | ||
| `Repository "${repo}" is not in your account. Request access, or choose a different name.`, | ||
| ); | ||
| } | ||
| } else { | ||
| const isTypeBuilderEnabled = await checkIsTypeBuilderEnabled(repo, { token, host }); | ||
| if (!isTypeBuilderEnabled) { | ||
| throw new TypeBuilderRequiredError(); | ||
|
|
@@ -113,8 +127,8 @@ export default createCommand(config, async ({ values }) => { | |
|
|
||
| const adapter = await getAdapter(); | ||
|
|
||
| if (!repo) { | ||
| repo = await createRepo({ token, host }); | ||
| if (!hasRepoAccess) { | ||
| repo = await createRepo({ name: repo, token, host }); | ||
| console.info(`Created repository: ${repo}`); | ||
| } | ||
|
|
||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.