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:
t3-code[bot]andmaria authored and GitHub committed 2026-08-21 04:55:14 -04:00
1 parent 9f12eab383
commit 549201fcfd
4 files changed
+68 -4

No files matched your search

@@ -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> {