Skip to content

Commit 4ed4950

Browse files
naveed949cursoragentmaria-rcks
authored
fix(client): reject incomplete GitHub owner paths before lookup (#23024)
Co-authored-by: Cursor <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 5e19105 commit 4ed4950

4 files changed

Lines changed: 72 additions & 0 deletions

File tree

‎apps/mobile/src/features/projects/AddProjectScreen.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
getNewProjectPublishTarget,
2424
getNewProjectPublishTargets,
2525
getNewProjectRepository,
26+
githubIncompleteOwnerRepositoryMessage,
2627
defaultHostCloneUrl,
2728
normalizePastedCloneUrl,
2829
parseAddProjectRemoteSource,
@@ -823,6 +824,11 @@ export function AddProjectRepositoryScreen(props: {
823824

824825
const lookupRepository = async () => {
825826
if (!environment || repositoryInput.trim().length === 0 || isSubmitting) return;
827+
const incompleteOwnerMessage = githubIncompleteOwnerRepositoryMessage(source, repositoryInput);
828+
if (incompleteOwnerMessage) {
829+
setError(incompleteOwnerMessage);
830+
return;
831+
}
826832
setError(null);
827833
setIsSubmitting(true);
828834
const provider = addProjectRemoteSourceProvider(source);

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
getNewProjectPublishTarget,
1717
getNewProjectPublishTargets,
1818
getNewProjectRepository,
19+
githubIncompleteOwnerRepositoryMessage,
1920
normalizePastedCloneUrl,
2021
addProjectRemoteSourceLabel,
2122
addProjectRemoteSourcePathHint,
@@ -1940,6 +1941,21 @@ function OpenCommandPaletteDialog(props: {
19401941
return;
19411942
}
19421943

1944+
const incompleteOwnerMessage = githubIncompleteOwnerRepositoryMessage(
1945+
addProjectCloneFlow.source,
1946+
rawRepository,
1947+
);
1948+
if (incompleteOwnerMessage) {
1949+
toastManager.add(
1950+
stackedThreadToast({
1951+
type: "error",
1952+
title: "Repository name incomplete",
1953+
description: incompleteOwnerMessage,
1954+
}),
1955+
);
1956+
return;
1957+
}
1958+
19431959
const provider = addProjectRemoteSourceProvider(addProjectCloneFlow.source);
19441960
if (!provider) {
19451961
const destinationPath = getCloneDestinationPath(

‎packages/client-runtime/src/operations/projects.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,42 @@ import {
66
findExistingAddProject,
77
getCloneDirectoryName,
88
getDefaultCloneUrl,
9+
githubIncompleteOwnerRepositoryMessage,
910
normalizePastedCloneUrl,
1011
} from "./projects.ts";
1112
import type { EnvironmentProject } from "../state/models.ts";
1213

1314
describe("add project shared logic", () => {
15+
it("asks for a repository name when GitHub input is only an owner path", () => {
16+
const github = SourceControlProviderKind.make("github");
17+
expect(githubIncompleteOwnerRepositoryMessage(github, "pingdotgg/")).toBe(
18+
"Enter the full owner/repository name.",
19+
);
20+
expect(githubIncompleteOwnerRepositoryMessage(github, " pingdotgg// ")).toBe(
21+
"Enter the full owner/repository name.",
22+
);
23+
expect(githubIncompleteOwnerRepositoryMessage(github, "mona-cat_octo/")).toBe(
24+
"Enter the full owner/repository name.",
25+
);
26+
27+
for (const input of [
28+
"pingdotgg/t3code",
29+
"mona-cat_octo/repo",
30+
"pingdotgg",
31+
"https://github.com/pingdotgg/t3code.git",
32+
"[email protected]:pingdotgg/t3code.git",
33+
]) {
34+
expect(githubIncompleteOwnerRepositoryMessage(github, input)).toBeNull();
35+
}
36+
expect(
37+
githubIncompleteOwnerRepositoryMessage(SourceControlProviderKind.make("gitlab"), "group/"),
38+
).toBeNull();
39+
expect(githubIncompleteOwnerRepositoryMessage("url", "owner/")).toBeNull();
40+
expect(
41+
githubIncompleteOwnerRepositoryMessage(SourceControlProviderKind.make("forgejo"), "owner/"),
42+
).toBeNull();
43+
});
44+
1445
it("routes owner/repository shorthand to GitHub over HTTPS", () => {
1546
expect(normalizePastedCloneUrl("imputnet/helium")).toBe(
1647
"https://github.com/imputnet/helium.git",

‎packages/client-runtime/src/operations/projects.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,25 @@ export function defaultHostCloneUrl(repository: string): string | null {
106106
: `git@${definition.publicHost}:${path}`;
107107
}
108108

109+
/** Owner present, repository name missing: `owner/` or `owner//`. */
110+
const INCOMPLETE_GITHUB_OWNER_PATH = /^[A-Za-z0-9](?:[A-Za-z0-9_-]{0,38})\/+$/;
111+
112+
const INCOMPLETE_GITHUB_OWNER_REPOSITORY_MESSAGE = "Enter the full owner/repository name.";
113+
114+
/**
115+
* Message to show when a GitHub add-project field is only `owner/`.
116+
* Lookup would send that to GitHub and come back as a generic failure.
117+
* Returns null for complete names, bare repo names, URLs, and other sources.
118+
*/
119+
export function githubIncompleteOwnerRepositoryMessage(
120+
source: AddProjectRemoteSource,
121+
input: string,
122+
): string | null {
123+
if (source !== "github") return null;
124+
if (!INCOMPLETE_GITHUB_OWNER_PATH.test(input.trim())) return null;
125+
return INCOMPLETE_GITHUB_OWNER_REPOSITORY_MESSAGE;
126+
}
127+
109128
export function normalizePastedCloneUrl(input: string): string {
110129
const trimmed = input.trim();
111130
return REPOSITORY_SHORTHAND.test(trimmed) ? (defaultHostCloneUrl(trimmed) ?? trimmed) : trimmed;

0 commit comments

Comments
 (0)