Skip to content

Commit 916ee86

Browse files
refactor(client-runtime): add project clone sources come from host definitions
The Add Project helpers in client-runtime, and mobile's screens on top of them, listed the five hosts by hand: the source union, its label and path hint switches, the default clone transport, a readiness record keyed by host, and route-param guards in two mobile screens. They now read from `sourceControlClients`, so a new host's definition puts it in the picker. Readiness is a lookup function instead of a fixed record. Mobile's PR accessibility label and its icon read from the definition too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c554ca2 commit 916ee86

6 files changed

Lines changed: 122 additions & 136 deletions

File tree

‎apps/mobile/src/components/SourceControlIcon.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import { withUniwind } from "uniwind";
33

44
const ThemedSvg = withUniwind(Svg);
55

6-
export type SourceControlIconKind = "github" | "gitlab" | "forgejo" | "bitbucket" | "azure-devops";
7-
6+
/** Draws a host's glyph by its client definition's `icon` key; null for a key it has no art for. */
87
export function SourceControlIcon(props: {
9-
readonly kind: SourceControlIconKind;
8+
readonly kind: string;
109
readonly size?: number;
1110
readonly color?: string;
1211
readonly colorClassName?: string;
@@ -252,5 +251,7 @@ export function SourceControlIcon(props: {
252251
/>
253252
</Svg>
254253
);
254+
default:
255+
return null;
255256
}
256257
}

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { StaticScreenProps } from "@react-navigation/native";
22
import { NativeStackScreenOptions } from "../../native/StackHeader";
3-
import { addProjectRemoteSourceLabel } from "@t3tools/client-runtime/operations/projects";
3+
import {
4+
addProjectRemoteSourceLabel,
5+
parseAddProjectRemoteSource,
6+
} from "@t3tools/client-runtime/operations/projects";
47

58
import { AddProjectRepositoryScreen } from "./AddProjectScreen";
69

@@ -14,14 +17,7 @@ export function AddProjectRepositoryRoute({
1417
}: StaticScreenProps<AddProjectRepositoryRouteParams>) {
1518
const params = route.params ?? {};
1619
const source = Array.isArray(params.source) ? params.source[0] : params.source;
17-
const title =
18-
source === "github" ||
19-
source === "gitlab" ||
20-
source === "forgejo" ||
21-
source === "bitbucket" ||
22-
source === "azure-devops"
23-
? addProjectRemoteSourceLabel(source)
24-
: "Git URL";
20+
const title = addProjectRemoteSourceLabel(parseAddProjectRemoteSource(source));
2521

2622
return (
2723
<>

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { SourceControlProviderKind } from "@t3tools/contracts";
21
import { MaterialListRow } from "../../components/MaterialListRow";
32
import { SettingsScreen } from "../settings/components/SettingsScreen";
43
import { ScreenScrollView as ScrollView } from "../../components/ScreenScrollView";
@@ -20,6 +19,7 @@ import {
2019
getNewProjectGitHubTarget,
2120
getNewProjectPathPreview,
2221
normalizePastedCloneUrl,
22+
parseAddProjectRemoteSource,
2323
resolveAddProjectPath,
2424
sortAddProjectProviderSources,
2525
type AddProjectRemoteSource,
@@ -49,6 +49,7 @@ import {
4949
type EnvironmentMachineKind,
5050
ProjectId,
5151
resolveEnvironmentMachineKind,
52+
SourceControlProviderKind,
5253
} from "@t3tools/contracts";
5354
import { CommonActions, StackActions, useNavigation } from "@react-navigation/native";
5455
import { SymbolView } from "../../components/AppSymbol";
@@ -71,6 +72,7 @@ import { AppText as Text, AppTextInput as TextInput } from "../../components/App
7172
import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol";
7273
import { ErrorBanner } from "../../components/ErrorBanner";
7374
import { SourceControlIcon } from "../../components/SourceControlIcon";
75+
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
7476
import { ThemedSwitch } from "../../components/ThemedSwitch";
7577
import { uuidv4 } from "../../lib/uuid";
7678
import { useAtomCommand } from "../../state/use-atom-command";
@@ -123,18 +125,7 @@ function stringParam(value: string | string[] | undefined): string | null {
123125
}
124126

125127
function sourceFromParam(value: string | string[] | undefined): AddProjectRemoteSource {
126-
const source = stringParam(value);
127-
if (
128-
source === "url" ||
129-
source === "github" ||
130-
source === "gitlab" ||
131-
source === "forgejo" ||
132-
source === "bitbucket" ||
133-
source === "azure-devops"
134-
) {
135-
return source;
136-
}
137-
return "url";
128+
return parseAddProjectRemoteSource(stringParam(value));
138129
}
139130

140131
function SectionTitle(props: { readonly children: string }) {
@@ -499,7 +490,7 @@ function SourceControlRow(props: {
499490
/>
500491
) : (
501492
<SourceControlIcon
502-
kind={props.source}
493+
kind={sourceControlClients.get(props.source).icon}
503494
size={Platform.OS === "android" ? 24 : 18}
504495
colorClassName="accent-icon"
505496
/>
@@ -659,13 +650,13 @@ export function AddProjectSourceScreen() {
659650
key={candidate}
660651
source={candidate}
661652
selectedEnvironmentId={selectedEnvironment.environmentId}
662-
ready={canCloneProject && readiness[candidate].ready}
653+
ready={canCloneProject && readiness(candidate).ready}
663654
hint={
664655
!canCloneProject
665656
? "This connection cannot clone projects."
666-
: readiness[candidate].ready
657+
: readiness(candidate).ready
667658
? addProjectRemoteSourcePathHint(candidate)
668-
: (readiness[candidate].hint ?? "")
659+
: (readiness(candidate).hint ?? "")
669660
}
670661
isFirst={false}
671662
/>
@@ -813,7 +804,7 @@ export function AddProjectRepositoryScreen(props: {
813804
const result = await lookupRepositoryQuery({
814805
environmentId: environment.environmentId,
815806
input: {
816-
provider: SourceControlProviderKind.make(provider),
807+
provider,
817808
repository: repositoryInput.trim(),
818809
},
819810
});
@@ -1153,7 +1144,7 @@ export function AddProjectNewScreen(props: { readonly environmentId?: string | s
11531144
}
11541145
icon={
11551146
<SourceControlIcon
1156-
kind="github"
1147+
kind={sourceControlClients.get("github").icon}
11571148
size={Platform.OS === "android" ? 24 : 18}
11581149
colorClassName="accent-icon"
11591150
/>

‎apps/mobile/src/state/thread-pr-presentation.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
ThreadPullRequestLink,
55
VcsStatusResult,
66
} from "@t3tools/contracts";
7-
import { resolveChangeRequestPresentation } from "@t3tools/shared/sourceControl";
7+
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
88

99
import {
1010
resolveThreadCurrentPullRequestLink,
@@ -39,7 +39,7 @@ export function presentThreadPr(
3939
pr: ThreadPr,
4040
provider: VcsStatusResult["sourceControlProvider"] | null | undefined,
4141
): ThreadPrPresentation {
42-
const presentation = resolveChangeRequestPresentation(provider);
42+
const { changeRequest } = sourceControlClients.get(provider?.kind);
4343
const isDraft = pr.state === "open" && pr.isDraft === true;
4444
return {
4545
kind: "pull-request",
@@ -50,7 +50,7 @@ export function presentThreadPr(
5050
updatedAt: pr.updatedAt ?? null,
5151
url: pr.url,
5252
label: String(pr.number),
53-
accessibilityLabel: `#${pr.number} ${presentation.longName} ${isDraft ? "draft" : pr.state}`,
53+
accessibilityLabel: `#${pr.number} ${changeRequest.singular} ${isDraft ? "draft" : pr.state}`,
5454
textClassName: isDraft ? "text-foreground-muted" : PR_STATE_TEXT_CLASS[pr.state],
5555
};
5656
}

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

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
import * as Option from "effect/Option";
1010

1111
import {
12+
addProjectRemoteSourceLabel,
13+
addProjectRemoteSourcePathHint,
1214
buildAddProjectRemoteSourceReadiness,
1315
buildProjectCreateCommand,
1416
canCreateProjectInEnvironment,
@@ -19,6 +21,7 @@ import {
1921
getCloneDirectoryName,
2022
getDefaultCloneUrl,
2123
normalizePastedCloneUrl,
24+
parseAddProjectRemoteSource,
2225
resolveAddProjectPath,
2326
sortAddProjectProviderSources,
2427
} from "./projects.ts";
@@ -219,10 +222,23 @@ describe("add project shared logic", () => {
219222
};
220223

221224
const readiness = buildAddProjectRemoteSourceReadiness(discovery);
222-
expect(readiness.url.ready).toBe(true);
223-
expect(readiness.github.ready).toBe(true);
224-
expect(readiness.gitlab).toEqual({ ready: false, hint: "Run glab auth login" });
225-
expect(sortAddProjectProviderSources(readiness)[0]).toBe("github");
225+
expect(readiness("url").ready).toBe(true);
226+
expect(readiness(SourceControlProviderKind.make("github")).ready).toBe(true);
227+
expect(readiness(SourceControlProviderKind.make("gitlab"))).toEqual({
228+
ready: false,
229+
hint: "Run glab auth login",
230+
});
231+
expect(readiness(SourceControlProviderKind.make("bitbucket"))).toEqual({
232+
ready: false,
233+
hint: "Provider status unavailable. Open Source Control settings and rescan.",
234+
});
235+
expect(sortAddProjectProviderSources(readiness)).toEqual([
236+
"github",
237+
"azure-devops",
238+
"bitbucket",
239+
"forgejo",
240+
"gitlab",
241+
]);
226242
});
227243

228244
it("finds existing projects by normalized path in the target environment", () => {
@@ -276,3 +292,34 @@ describe("add project shared logic", () => {
276292
});
277293
});
278294
});
295+
296+
describe("add project remote sources", () => {
297+
it("labels each host the way the clone picker always has", () => {
298+
const sources = ["url", "github", "gitlab", "forgejo", "bitbucket", "azure-devops"] as const;
299+
const asSource = (source: (typeof sources)[number]) =>
300+
source === "url" ? source : SourceControlProviderKind.make(source);
301+
expect(sources.map((source) => addProjectRemoteSourceLabel(asSource(source)))).toEqual([
302+
"Git URL",
303+
"GitHub",
304+
"GitLab",
305+
"Forgejo / Gitea",
306+
"Bitbucket",
307+
"Azure DevOps",
308+
]);
309+
expect(sources.map((source) => addProjectRemoteSourcePathHint(asSource(source)))).toEqual([
310+
"URL",
311+
"owner/repo",
312+
"group/project",
313+
"owner/repo",
314+
"workspace/repository",
315+
"project/repository",
316+
]);
317+
});
318+
319+
it("reads route sources for shipped hosts only", () => {
320+
expect(parseAddProjectRemoteSource("gitlab")).toBe("gitlab");
321+
expect(parseAddProjectRemoteSource("url")).toBe("url");
322+
expect(parseAddProjectRemoteSource("gitcafe")).toBe("url");
323+
expect(parseAddProjectRemoteSource(null)).toBe("url");
324+
});
325+
});

0 commit comments

Comments
 (0)