fix(clients): default GitHub clones to HTTPS (#7760)
Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: maria <[email protected]>
This commit is contained in:
1 parent
9f12eab383
commit
549201fcfd
4 files changed
+68
-4
No files matched your search
@@ -10,6 +10,8 @@ import {
|
||||
getCloneDestinationBrowsePath,
|
||||
getCloneDestinationPath,
|
||||
getCloneDirectoryName,
|
||||
getDefaultCloneUrl,
|
||||
normalizePastedCloneUrl,
|
||||
resolveAddProjectPath,
|
||||
sortAddProjectProviderSources,
|
||||
type AddProjectRemoteSource,
|
||||
@@ -662,7 +664,7 @@ export function AddProjectRepositoryScreen(props: {
|
||||
setIsSubmitting(true);
|
||||
const provider = addProjectRemoteSourceProvider(source);
|
||||
if (!provider) {
|
||||
const remoteUrl = repositoryInput.trim();
|
||||
const remoteUrl = normalizePastedCloneUrl(repositoryInput);
|
||||
navigation.dispatch(
|
||||
StackActions.push("AddProjectDestination", {
|
||||
environmentId: environment.environmentId,
|
||||
@@ -691,7 +693,7 @@ export function AddProjectRepositoryScreen(props: {
|
||||
StackActions.push("AddProjectDestination", {
|
||||
environmentId: environment.environmentId,
|
||||
source,
|
||||
remoteUrl: repository.sshUrl,
|
||||
remoteUrl: getDefaultCloneUrl(repository),
|
||||
repositoryTitle: repository.nameWithOwner,
|
||||
repositoryName: getCloneDirectoryName(repository.nameWithOwner),
|
||||
}),
|
||||
|
||||
@@ -6,6 +6,8 @@ import {
|
||||
getCloneDestinationBrowsePath,
|
||||
getCloneDestinationPath,
|
||||
getCloneDirectoryName,
|
||||
getDefaultCloneUrl,
|
||||
normalizePastedCloneUrl,
|
||||
} from "@t3tools/client-runtime/operations/projects";
|
||||
import { connectionStatusText } from "@t3tools/client-runtime/connection";
|
||||
import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
|
||||
@@ -1874,7 +1876,7 @@ function OpenCommandPaletteDialog(props: {
|
||||
source: addProjectCloneFlow.source,
|
||||
repositoryInput: rawRepository,
|
||||
repository: null,
|
||||
remoteUrl: rawRepository,
|
||||
remoteUrl: normalizePastedCloneUrl(rawRepository),
|
||||
});
|
||||
setHighlightedItemValue(null);
|
||||
setQuery(destinationPath);
|
||||
@@ -1914,7 +1916,7 @@ function OpenCommandPaletteDialog(props: {
|
||||
source: addProjectCloneFlow.source,
|
||||
repositoryInput: rawRepository,
|
||||
repository,
|
||||
remoteUrl: repository.sshUrl,
|
||||
remoteUrl: getDefaultCloneUrl(repository),
|
||||
});
|
||||
setHighlightedItemValue(null);
|
||||
setQuery(destinationPath);
|
||||
|
||||
@@ -16,6 +16,8 @@ import {
|
||||
getCloneDestinationBrowsePath,
|
||||
getCloneDestinationPath,
|
||||
getCloneDirectoryName,
|
||||
getDefaultCloneUrl,
|
||||
normalizePastedCloneUrl,
|
||||
resolveAddProjectPath,
|
||||
sortAddProjectProviderSources,
|
||||
} from "./projects.ts";
|
||||
@@ -46,6 +48,46 @@ describe("add project shared logic", () => {
|
||||
expect(getCloneDirectoryName(null)).toBe("");
|
||||
});
|
||||
|
||||
it("routes owner/repository shorthand to GitHub over HTTPS", () => {
|
||||
expect(normalizePastedCloneUrl("imputnet/helium")).toBe(
|
||||
"https://github.com/imputnet/helium.git",
|
||||
);
|
||||
expect(normalizePastedCloneUrl(" pingdotgg/t3code ")).toBe(
|
||||
"https://github.com/pingdotgg/t3code.git",
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps explicit clone URLs and local paths unchanged", () => {
|
||||
expect(normalizePastedCloneUrl("https://gitlab.com/group/project.git")).toBe(
|
||||
"https://gitlab.com/group/project.git",
|
||||
);
|
||||
expect(normalizePastedCloneUrl("[email protected]:owner/repo.git")).toBe(
|
||||
"[email protected]:owner/repo.git",
|
||||
);
|
||||
expect(normalizePastedCloneUrl("group/subgroup/project")).toBe("group/subgroup/project");
|
||||
expect(normalizePastedCloneUrl("/srv/git/repo.git")).toBe("/srv/git/repo.git");
|
||||
});
|
||||
|
||||
it("uses HTTPS for repositories selected through a provider", () => {
|
||||
expect(
|
||||
getDefaultCloneUrl({
|
||||
provider: "github",
|
||||
url: "https://github.com/imputnet/helium",
|
||||
sshUrl: "[email protected]:imputnet/helium.git",
|
||||
}),
|
||||
).toBe("https://github.com/imputnet/helium");
|
||||
});
|
||||
|
||||
it("preserves existing clone transport behavior for other providers", () => {
|
||||
expect(
|
||||
getDefaultCloneUrl({
|
||||
provider: "gitlab",
|
||||
url: "https://gitlab.com/group/project.git",
|
||||
sshUrl: "[email protected]:group/project.git",
|
||||
}),
|
||||
).toBe("[email protected]:group/project.git");
|
||||
});
|
||||
|
||||
it("derives the clone folder name from any pasted clone URL", () => {
|
||||
expect(getCloneDirectoryName("https://github.com/owner/repo.git")).toBe("repo");
|
||||
expect(getCloneDirectoryName("https://github.com/owner/repo")).toBe("repo");
|
||||
|
||||
@@ -106,6 +106,24 @@ export function addProjectRemoteSourceProvider(
|
||||
return source === "url" ? null : source;
|
||||
}
|
||||
|
||||
const GITHUB_REPOSITORY_SHORTHAND =
|
||||
/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})\/[A-Za-z0-9._-]+(?:\.git)?$/;
|
||||
|
||||
/** Treat the common owner/repository shorthand as a public GitHub HTTPS URL. */
|
||||
export function normalizePastedCloneUrl(input: string): string {
|
||||
const trimmed = input.trim();
|
||||
if (!GITHUB_REPOSITORY_SHORTHAND.test(trimmed)) return trimmed;
|
||||
const repository = trimmed.endsWith(".git") ? trimmed : `${trimmed}.git`;
|
||||
return `https://github.com/${repository}`;
|
||||
}
|
||||
|
||||
/** GitHub defaults to HTTPS; other providers retain their existing SSH default. */
|
||||
export function getDefaultCloneUrl(
|
||||
repository: Pick<SourceControlRepositoryInfo, "provider" | "url" | "sshUrl">,
|
||||
): string {
|
||||
return repository.provider === "github" ? repository.url : repository.sshUrl;
|
||||
}
|
||||
|
||||
export function sortAddProjectProviderSources(
|
||||
readinessBySource: AddProjectRemoteSourceReadiness,
|
||||
): ReadonlyArray<AddProjectRemoteProviderKind> {
|
||||
|
||||
Reference in new issue
Block a user