Add source control settings discovery
This commit is contained in:
1 parent
128b432bee
commit
dc2e2654e9
14 files changed
+644
-3
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { Effect, Layer } from "effect";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
import { VcsProcessSpawnError } from "@t3tools/contracts";
|
||||
|
||||
import { ServerConfig } from "../config.ts";
|
||||
import * as VcsProcess from "../vcs/VcsProcess.ts";
|
||||
import { SourceControlDiscovery, layer } from "./SourceControlDiscovery.ts";
|
||||
|
||||
const processOutput = (stdout: string): VcsProcess.VcsProcessOutput => ({
|
||||
exitCode: ChildProcessSpawner.ExitCode(0),
|
||||
stdout,
|
||||
stderr: "",
|
||||
stdoutTruncated: false,
|
||||
stderrTruncated: false,
|
||||
});
|
||||
|
||||
it.effect("reports implemented tools separately from locally available CLIs", () => {
|
||||
const testLayer = layer.pipe(
|
||||
Layer.provide(
|
||||
ServerConfig.layerTest(process.cwd(), { prefix: "t3-source-control-discovery-" }),
|
||||
),
|
||||
Layer.provide(
|
||||
Layer.mock(VcsProcess.VcsProcess)({
|
||||
run: (input) => {
|
||||
if (input.command === "git") {
|
||||
return Effect.succeed(processOutput("git version 2.51.0\n"));
|
||||
}
|
||||
if (input.command === "gh") {
|
||||
return Effect.succeed(processOutput("gh version 2.83.0\n"));
|
||||
}
|
||||
return Effect.fail(
|
||||
new VcsProcessSpawnError({
|
||||
operation: input.operation,
|
||||
command: input.command,
|
||||
cwd: input.cwd,
|
||||
cause: new Error(`${input.command} not found`),
|
||||
}),
|
||||
);
|
||||
},
|
||||
}),
|
||||
),
|
||||
Layer.provideMerge(NodeServices.layer),
|
||||
);
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const discovery = yield* SourceControlDiscovery;
|
||||
const result = yield* discovery.discover;
|
||||
|
||||
assert.deepStrictEqual(
|
||||
result.versionControlSystems.map((item) => ({
|
||||
kind: item.kind,
|
||||
implemented: item.implemented,
|
||||
status: item.status,
|
||||
})),
|
||||
[
|
||||
{ kind: "git", implemented: true, status: "available" },
|
||||
{ kind: "jj", implemented: false, status: "missing" },
|
||||
{ kind: "sapling", implemented: false, status: "missing" },
|
||||
],
|
||||
);
|
||||
assert.deepStrictEqual(
|
||||
result.sourceControlProviders.map((item) => ({
|
||||
kind: item.kind,
|
||||
implemented: item.implemented,
|
||||
status: item.status,
|
||||
})),
|
||||
[
|
||||
{ kind: "github", implemented: true, status: "available" },
|
||||
{ kind: "gitlab", implemented: false, status: "missing" },
|
||||
{ kind: "azure-devops", implemented: false, status: "missing" },
|
||||
{ kind: "bitbucket", implemented: false, status: "missing" },
|
||||
],
|
||||
);
|
||||
}).pipe(Effect.provide(testLayer));
|
||||
});
|
||||
@@ -0,0 +1,178 @@
|
||||
import {
|
||||
type SourceControlDiscoveryResult,
|
||||
type SourceControlProviderDiscoveryItem,
|
||||
type SourceControlProviderKind,
|
||||
type VcsDiscoveryItem,
|
||||
type VcsDriverKind,
|
||||
} from "@t3tools/contracts";
|
||||
import { Context, Effect, Layer, Option } from "effect";
|
||||
|
||||
import { ServerConfig } from "../config.ts";
|
||||
import * as VcsProcess from "../vcs/VcsProcess.ts";
|
||||
|
||||
interface DiscoveryProbe {
|
||||
readonly label: string;
|
||||
readonly executable: string;
|
||||
readonly versionArgs: ReadonlyArray<string>;
|
||||
readonly implemented: boolean;
|
||||
readonly installHint: string;
|
||||
}
|
||||
|
||||
type VcsProbe = DiscoveryProbe & {
|
||||
readonly kind: VcsDriverKind;
|
||||
};
|
||||
|
||||
type ProviderProbe = DiscoveryProbe & {
|
||||
readonly kind: SourceControlProviderKind;
|
||||
};
|
||||
|
||||
const VCS_PROBES: ReadonlyArray<VcsProbe> = [
|
||||
{
|
||||
kind: "git",
|
||||
label: "Git",
|
||||
executable: "git",
|
||||
versionArgs: ["--version"],
|
||||
implemented: true,
|
||||
installHint: "Install Git from https://git-scm.com/downloads or with your package manager.",
|
||||
},
|
||||
{
|
||||
kind: "jj",
|
||||
label: "Jujutsu",
|
||||
executable: "jj",
|
||||
versionArgs: ["--version"],
|
||||
implemented: false,
|
||||
installHint: "Install Jujutsu with `brew install jj` or from https://github.com/jj-vcs/jj.",
|
||||
},
|
||||
{
|
||||
kind: "sapling",
|
||||
label: "Sapling",
|
||||
executable: "sl",
|
||||
versionArgs: ["--version"],
|
||||
implemented: false,
|
||||
installHint: "Install Sapling (`sl`) from https://sapling-scm.com/.",
|
||||
},
|
||||
];
|
||||
|
||||
const SOURCE_CONTROL_PROVIDER_PROBES: ReadonlyArray<ProviderProbe> = [
|
||||
{
|
||||
kind: "github",
|
||||
label: "GitHub",
|
||||
executable: "gh",
|
||||
versionArgs: ["--version"],
|
||||
implemented: true,
|
||||
installHint: "Install GitHub CLI with `brew install gh` or from https://cli.github.com/.",
|
||||
},
|
||||
{
|
||||
kind: "gitlab",
|
||||
label: "GitLab",
|
||||
executable: "glab",
|
||||
versionArgs: ["--version"],
|
||||
implemented: false,
|
||||
installHint:
|
||||
"Install GitLab CLI with `brew install glab` or from https://gitlab.com/gitlab-org/cli.",
|
||||
},
|
||||
{
|
||||
kind: "azure-devops",
|
||||
label: "Azure DevOps",
|
||||
executable: "az",
|
||||
versionArgs: ["--version"],
|
||||
implemented: false,
|
||||
installHint:
|
||||
"Install Azure CLI with `brew install azure-cli`, then add Azure DevOps support with `az extension add --name azure-devops`.",
|
||||
},
|
||||
{
|
||||
kind: "bitbucket",
|
||||
label: "Bitbucket",
|
||||
executable: "bb",
|
||||
versionArgs: ["--version"],
|
||||
implemented: false,
|
||||
installHint: "Install a Bitbucket CLI (`bb`) and authenticate it for your Bitbucket workspace.",
|
||||
},
|
||||
];
|
||||
|
||||
function firstNonEmptyLine(text: string): Option.Option<string> {
|
||||
const line = text
|
||||
.split(/\r?\n/)
|
||||
.map((entry) => entry.trim())
|
||||
.find((entry) => entry.length > 0);
|
||||
return line === undefined ? Option.none() : Option.some(line);
|
||||
}
|
||||
|
||||
function detailFromCause(cause: unknown): Option.Option<string> {
|
||||
if (cause instanceof Error && cause.message.trim().length > 0) {
|
||||
return Option.some(cause.message.trim());
|
||||
}
|
||||
return Option.none();
|
||||
}
|
||||
|
||||
export interface SourceControlDiscoveryShape {
|
||||
readonly discover: Effect.Effect<SourceControlDiscoveryResult>;
|
||||
}
|
||||
|
||||
export class SourceControlDiscovery extends Context.Service<
|
||||
SourceControlDiscovery,
|
||||
SourceControlDiscoveryShape
|
||||
>()("t3/source-control/SourceControlDiscovery") {}
|
||||
|
||||
export const layer = Layer.effect(
|
||||
SourceControlDiscovery,
|
||||
Effect.gen(function* () {
|
||||
const config = yield* ServerConfig;
|
||||
const process = yield* VcsProcess.VcsProcess;
|
||||
|
||||
const probe = <Kind extends VcsDriverKind | SourceControlProviderKind>(
|
||||
input: DiscoveryProbe & { readonly kind: Kind },
|
||||
) =>
|
||||
process
|
||||
.run({
|
||||
operation: "source-control.discovery.probe",
|
||||
command: input.executable,
|
||||
args: input.versionArgs,
|
||||
cwd: config.cwd,
|
||||
timeoutMs: 5_000,
|
||||
maxOutputBytes: 8_000,
|
||||
truncateOutputAtMaxBytes: true,
|
||||
})
|
||||
.pipe(
|
||||
Effect.map((result) => ({
|
||||
kind: input.kind,
|
||||
label: input.label,
|
||||
executable: input.executable,
|
||||
implemented: input.implemented,
|
||||
status: "available" as const,
|
||||
version: Option.orElse(firstNonEmptyLine(result.stdout), () =>
|
||||
firstNonEmptyLine(result.stderr),
|
||||
),
|
||||
installHint: input.installHint,
|
||||
detail: Option.none<string>(),
|
||||
})),
|
||||
Effect.catch((cause) =>
|
||||
Effect.succeed({
|
||||
kind: input.kind,
|
||||
label: input.label,
|
||||
executable: input.executable,
|
||||
implemented: input.implemented,
|
||||
status: "missing" as const,
|
||||
version: Option.none<string>(),
|
||||
installHint: input.installHint,
|
||||
detail: detailFromCause(cause),
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
return SourceControlDiscovery.of({
|
||||
discover: Effect.all({
|
||||
versionControlSystems: Effect.all(
|
||||
VCS_PROBES.map((entry) => probe(entry)) as ReadonlyArray<Effect.Effect<VcsDiscoveryItem>>,
|
||||
{ concurrency: "unbounded" },
|
||||
),
|
||||
sourceControlProviders: Effect.all(
|
||||
SOURCE_CONTROL_PROVIDER_PROBES.map((entry) => probe(entry)) as ReadonlyArray<
|
||||
Effect.Effect<SourceControlProviderDiscoveryItem>
|
||||
>,
|
||||
{ concurrency: "unbounded" },
|
||||
),
|
||||
}),
|
||||
});
|
||||
}),
|
||||
);
|
||||
+15
-1
@@ -53,6 +53,8 @@ import { ProjectSetupScriptRunner } from "./project/Services/ProjectSetupScriptR
|
||||
import { RepositoryIdentityResolver } from "./project/Services/RepositoryIdentityResolver.ts";
|
||||
import { ServerEnvironment } from "./environment/Services/ServerEnvironment.ts";
|
||||
import { ServerAuth } from "./auth/Services/ServerAuth.ts";
|
||||
import * as SourceControlDiscoveryLayer from "./sourceControl/SourceControlDiscovery.ts";
|
||||
import * as VcsProcess from "./vcs/VcsProcess.ts";
|
||||
import {
|
||||
BootstrapCredentialService,
|
||||
type BootstrapCredentialChange,
|
||||
@@ -149,6 +151,7 @@ const makeWsRpcLayer = (currentSessionId: AuthSessionId) =>
|
||||
const repositoryIdentityResolver = yield* RepositoryIdentityResolver;
|
||||
const serverEnvironment = yield* ServerEnvironment;
|
||||
const serverAuth = yield* ServerAuth;
|
||||
const sourceControlDiscovery = yield* SourceControlDiscoveryLayer.SourceControlDiscovery;
|
||||
const bootstrapCredentials = yield* BootstrapCredentialService;
|
||||
const sessions = yield* SessionCredentialService;
|
||||
const serverCommandId = (tag: string) =>
|
||||
@@ -781,6 +784,14 @@ const makeWsRpcLayer = (currentSessionId: AuthSessionId) =>
|
||||
"rpc.aggregate": "server",
|
||||
},
|
||||
),
|
||||
[WS_METHODS.serverDiscoverSourceControl]: (_input) =>
|
||||
observeRpcEffect(
|
||||
WS_METHODS.serverDiscoverSourceControl,
|
||||
sourceControlDiscovery.discover,
|
||||
{
|
||||
"rpc.aggregate": "server",
|
||||
},
|
||||
),
|
||||
[WS_METHODS.projectsSearchEntries]: (input) =>
|
||||
observeRpcEffect(
|
||||
WS_METHODS.projectsSearchEntries,
|
||||
@@ -1084,7 +1095,10 @@ export const websocketRpcRouteLayer = Layer.unwrap(
|
||||
},
|
||||
}).pipe(
|
||||
Effect.provide(
|
||||
makeWsRpcLayer(session.sessionId).pipe(Layer.provideMerge(RpcSerialization.layerJson)),
|
||||
makeWsRpcLayer(session.sessionId).pipe(
|
||||
Layer.provideMerge(RpcSerialization.layerJson),
|
||||
Layer.provide(SourceControlDiscoveryLayer.layer.pipe(Layer.provide(VcsProcess.layer))),
|
||||
),
|
||||
),
|
||||
);
|
||||
return yield* Effect.acquireUseRelease(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useCallback, type ComponentType } from "react";
|
||||
import { ArchiveIcon, ArrowLeftIcon, Link2Icon, Settings2Icon } from "lucide-react";
|
||||
import { ArchiveIcon, ArrowLeftIcon, GitBranchIcon, Link2Icon, Settings2Icon } from "lucide-react";
|
||||
import { useCanGoBack, useNavigate } from "@tanstack/react-router";
|
||||
|
||||
import {
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
|
||||
export type SettingsSectionPath =
|
||||
| "/settings/general"
|
||||
| "/settings/source-control"
|
||||
| "/settings/connections"
|
||||
| "/settings/archived";
|
||||
|
||||
@@ -24,6 +25,7 @@ export const SETTINGS_NAV_ITEMS: ReadonlyArray<{
|
||||
icon: ComponentType<{ className?: string }>;
|
||||
}> = [
|
||||
{ label: "General", to: "/settings/general", icon: Settings2Icon },
|
||||
{ label: "Source Control", to: "/settings/source-control", icon: GitBranchIcon },
|
||||
{ label: "Connections", to: "/settings/connections", icon: Link2Icon },
|
||||
{ label: "Archive", to: "/settings/archived", icon: ArchiveIcon },
|
||||
];
|
||||
|
||||
@@ -0,0 +1,262 @@
|
||||
import { ChevronDownIcon, GitBranchIcon, GitPullRequestIcon, RefreshCwIcon } from "lucide-react";
|
||||
import { Option } from "effect";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import type {
|
||||
SourceControlDiscoveryItem,
|
||||
SourceControlDiscoveryResult,
|
||||
SourceControlProviderDiscoveryItem,
|
||||
VcsDiscoveryItem,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
import { ensureLocalApi } from "../../localApi";
|
||||
import { cn } from "../../lib/utils";
|
||||
import { Badge } from "../ui/badge";
|
||||
import { Button } from "../ui/button";
|
||||
import { Collapsible, CollapsibleContent } from "../ui/collapsible";
|
||||
import { Switch } from "../ui/switch";
|
||||
import { SettingsPageContainer, SettingsSection } from "./settingsLayout";
|
||||
|
||||
type DiscoveryLoadState =
|
||||
| { readonly status: "loading"; readonly result: SourceControlDiscoveryResult | null }
|
||||
| { readonly status: "ready"; readonly result: SourceControlDiscoveryResult }
|
||||
| {
|
||||
readonly status: "error";
|
||||
readonly result: SourceControlDiscoveryResult | null;
|
||||
readonly message: string;
|
||||
};
|
||||
|
||||
const EMPTY_DISCOVERY_RESULT: SourceControlDiscoveryResult = {
|
||||
versionControlSystems: [],
|
||||
sourceControlProviders: [],
|
||||
};
|
||||
|
||||
function optionLabel(value: Option.Option<string>): string | null {
|
||||
return Option.getOrNull(value);
|
||||
}
|
||||
|
||||
function statusPresentation(item: SourceControlDiscoveryItem): {
|
||||
readonly label: string;
|
||||
readonly badge: "success" | "warning" | "outline";
|
||||
readonly dot: string;
|
||||
} {
|
||||
if (item.implemented && item.status === "available") {
|
||||
return {
|
||||
label: "Ready",
|
||||
badge: "success",
|
||||
dot: "bg-success",
|
||||
};
|
||||
}
|
||||
if (item.implemented) {
|
||||
return {
|
||||
label: "CLI missing",
|
||||
badge: "warning",
|
||||
dot: "bg-warning",
|
||||
};
|
||||
}
|
||||
if (item.status === "available") {
|
||||
return {
|
||||
label: "Detected",
|
||||
badge: "outline",
|
||||
dot: "bg-muted-foreground/60",
|
||||
};
|
||||
}
|
||||
return {
|
||||
label: "Placeholder",
|
||||
badge: "outline",
|
||||
dot: "bg-muted-foreground/40",
|
||||
};
|
||||
}
|
||||
|
||||
function DiscoveryItemRow({
|
||||
item,
|
||||
expanded,
|
||||
onExpandedChange,
|
||||
}: {
|
||||
readonly item: VcsDiscoveryItem | SourceControlProviderDiscoveryItem;
|
||||
readonly expanded: boolean;
|
||||
readonly onExpandedChange: (expanded: boolean) => void;
|
||||
}) {
|
||||
const status = statusPresentation(item);
|
||||
const version = optionLabel(item.version);
|
||||
const detail = optionLabel(item.detail);
|
||||
const enabled = item.implemented && item.status === "available";
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"border-t border-border/60 first:border-t-0",
|
||||
!item.implemented && "opacity-80",
|
||||
)}
|
||||
>
|
||||
<div className="px-4 py-3.5 sm:px-5">
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="min-w-0 flex-1 space-y-1">
|
||||
<div className="flex min-w-0 flex-wrap items-center gap-2">
|
||||
<span className={cn("size-2 rounded-full", status.dot)} aria-hidden />
|
||||
<h3 className="truncate text-[13px] font-semibold tracking-[-0.01em] text-foreground">
|
||||
{item.label}
|
||||
</h3>
|
||||
<Badge variant={status.badge} size="sm">
|
||||
{status.label}
|
||||
</Badge>
|
||||
{!item.implemented ? (
|
||||
<Badge variant="outline" size="sm">
|
||||
Not in this branch
|
||||
</Badge>
|
||||
) : null}
|
||||
</div>
|
||||
<p className="flex min-w-0 flex-wrap items-center gap-x-1 text-xs text-muted-foreground">
|
||||
<span>CLI</span>
|
||||
<code className="rounded-sm bg-muted px-1 py-0.5 font-mono text-[11px] text-foreground/80">
|
||||
{item.executable}
|
||||
</code>
|
||||
{version ? <span>- {version}</span> : null}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex w-full shrink-0 items-center gap-2 sm:w-auto sm:justify-end">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-7 px-2 text-xs text-muted-foreground hover:text-foreground"
|
||||
onClick={() => onExpandedChange(!expanded)}
|
||||
aria-label={`Toggle ${item.label} details`}
|
||||
>
|
||||
<ChevronDownIcon
|
||||
className={cn("size-3.5 transition-transform", expanded && "rotate-180")}
|
||||
/>
|
||||
</Button>
|
||||
<Switch checked={enabled} disabled aria-label={`${item.label} availability`} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Collapsible open={expanded} onOpenChange={onExpandedChange}>
|
||||
<CollapsibleContent>
|
||||
<div className="border-t border-border/60 px-4 py-3 text-xs sm:px-5">
|
||||
<dl className="grid gap-3 sm:grid-cols-[8rem_minmax(0,1fr)]">
|
||||
<dt className="text-muted-foreground">Command</dt>
|
||||
<dd className="min-w-0 font-mono text-foreground">{item.executable}</dd>
|
||||
<dt className="text-muted-foreground">Version</dt>
|
||||
<dd className="min-w-0 text-foreground">{version ?? "Not detected"}</dd>
|
||||
<dt className="text-muted-foreground">Install</dt>
|
||||
<dd className="min-w-0 leading-relaxed text-foreground">{item.installHint}</dd>
|
||||
<dt className="text-muted-foreground">Build</dt>
|
||||
<dd className="min-w-0 leading-relaxed text-foreground">
|
||||
{item.implemented
|
||||
? "Enabled in this branch and available for repository routing when the CLI is present."
|
||||
: "Placeholder only in this branch. The matching driver/provider PR enables this row."}
|
||||
</dd>
|
||||
{detail ? (
|
||||
<>
|
||||
<dt className="text-muted-foreground">Probe</dt>
|
||||
<dd className="min-w-0 break-words text-muted-foreground">{detail}</dd>
|
||||
</>
|
||||
) : null}
|
||||
</dl>
|
||||
</div>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function SourceControlSettingsPanel() {
|
||||
const [loadState, setLoadState] = useState<DiscoveryLoadState>({
|
||||
status: "loading",
|
||||
result: null,
|
||||
});
|
||||
const latestResultRef = useRef<SourceControlDiscoveryResult | null>(null);
|
||||
const [expanded, setExpanded] = useState<Readonly<Record<string, boolean>>>({});
|
||||
|
||||
const refresh = useCallback((options?: { readonly signal?: AbortSignal }) => {
|
||||
const previous = latestResultRef.current;
|
||||
setLoadState({ status: "loading", result: previous });
|
||||
|
||||
ensureLocalApi()
|
||||
.server.discoverSourceControl()
|
||||
.then((result) => {
|
||||
if (!options?.signal?.aborted) {
|
||||
latestResultRef.current = result;
|
||||
setLoadState({ status: "ready", result });
|
||||
}
|
||||
})
|
||||
.catch((cause: unknown) => {
|
||||
if (!options?.signal?.aborted) {
|
||||
setLoadState({
|
||||
status: "error",
|
||||
result: previous,
|
||||
message:
|
||||
cause instanceof Error ? cause.message : "Failed to discover source control tools.",
|
||||
});
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const controller = new AbortController();
|
||||
refresh({ signal: controller.signal });
|
||||
return () => controller.abort();
|
||||
}, [refresh]);
|
||||
|
||||
const result = loadState.result ?? EMPTY_DISCOVERY_RESULT;
|
||||
const statusText = useMemo(() => {
|
||||
if (loadState.status === "loading") return "Scanning installed tools...";
|
||||
if (loadState.status === "error") return loadState.message;
|
||||
return "Detected source control tools on this system.";
|
||||
}, [loadState]);
|
||||
|
||||
const setItemExpanded = (key: string, value: boolean) => {
|
||||
setExpanded((current) => ({ ...current, [key]: value }));
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingsPageContainer>
|
||||
<div className="space-y-1 px-1">
|
||||
<h1 className="text-lg font-semibold tracking-[-0.01em] text-foreground">Source Control</h1>
|
||||
<p className="text-sm text-muted-foreground">{statusText}</p>
|
||||
</div>
|
||||
|
||||
<SettingsSection
|
||||
title="Version Control"
|
||||
icon={<GitBranchIcon className="size-3.5" />}
|
||||
headerAction={
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-7 gap-1.5 px-2 text-xs"
|
||||
onClick={() => refresh()}
|
||||
disabled={loadState.status === "loading"}
|
||||
>
|
||||
<RefreshCwIcon
|
||||
className={cn("size-3.5", loadState.status === "loading" && "animate-spin")}
|
||||
/>
|
||||
Scan
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{result.versionControlSystems.map((item) => (
|
||||
<DiscoveryItemRow
|
||||
key={`vcs:${item.kind}`}
|
||||
item={item}
|
||||
expanded={expanded[`vcs:${item.kind}`] ?? false}
|
||||
onExpandedChange={(value) => setItemExpanded(`vcs:${item.kind}`, value)}
|
||||
/>
|
||||
))}
|
||||
</SettingsSection>
|
||||
|
||||
<SettingsSection
|
||||
title="Source Control Providers"
|
||||
icon={<GitPullRequestIcon className="size-3.5" />}
|
||||
>
|
||||
{result.sourceControlProviders.map((item) => (
|
||||
<DiscoveryItemRow
|
||||
key={`provider:${item.kind}`}
|
||||
item={item}
|
||||
expanded={expanded[`provider:${item.kind}`] ?? false}
|
||||
onExpandedChange={(value) => setItemExpanded(`provider:${item.kind}`, value)}
|
||||
/>
|
||||
))}
|
||||
</SettingsSection>
|
||||
</SettingsPageContainer>
|
||||
);
|
||||
}
|
||||
@@ -115,6 +115,7 @@ export function createLocalApi(rpcClient: WsRpcClient): LocalApi {
|
||||
upsertKeybinding: rpcClient.server.upsertKeybinding,
|
||||
getSettings: rpcClient.server.getSettings,
|
||||
updateSettings: rpcClient.server.updateSettings,
|
||||
discoverSourceControl: rpcClient.server.discoverSourceControl,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import { Route as PairRouteImport } from './routes/pair'
|
||||
import { Route as ChatRouteImport } from './routes/_chat'
|
||||
import { Route as ChatIndexRouteImport } from './routes/_chat.index'
|
||||
import { Route as SettingsGeneralRouteImport } from './routes/settings.general'
|
||||
import { Route as SettingsSourceControlRouteImport } from './routes/settings.source-control'
|
||||
import { Route as SettingsConnectionsRouteImport } from './routes/settings.connections'
|
||||
import { Route as SettingsArchivedRouteImport } from './routes/settings.archived'
|
||||
import { Route as ChatDraftDraftIdRouteImport } from './routes/_chat.draft.$draftId'
|
||||
@@ -43,6 +44,11 @@ const SettingsGeneralRoute = SettingsGeneralRouteImport.update({
|
||||
path: '/general',
|
||||
getParentRoute: () => SettingsRoute,
|
||||
} as any)
|
||||
const SettingsSourceControlRoute = SettingsSourceControlRouteImport.update({
|
||||
id: '/source-control',
|
||||
path: '/source-control',
|
||||
getParentRoute: () => SettingsRoute,
|
||||
} as any)
|
||||
const SettingsConnectionsRoute = SettingsConnectionsRouteImport.update({
|
||||
id: '/connections',
|
||||
path: '/connections',
|
||||
@@ -72,6 +78,7 @@ export interface FileRoutesByFullPath {
|
||||
'/settings/archived': typeof SettingsArchivedRoute
|
||||
'/settings/connections': typeof SettingsConnectionsRoute
|
||||
'/settings/general': typeof SettingsGeneralRoute
|
||||
'/settings/source-control': typeof SettingsSourceControlRoute
|
||||
'/$environmentId/$threadId': typeof ChatEnvironmentIdThreadIdRoute
|
||||
'/draft/$draftId': typeof ChatDraftDraftIdRoute
|
||||
}
|
||||
@@ -81,6 +88,7 @@ export interface FileRoutesByTo {
|
||||
'/settings/archived': typeof SettingsArchivedRoute
|
||||
'/settings/connections': typeof SettingsConnectionsRoute
|
||||
'/settings/general': typeof SettingsGeneralRoute
|
||||
'/settings/source-control': typeof SettingsSourceControlRoute
|
||||
'/': typeof ChatIndexRoute
|
||||
'/$environmentId/$threadId': typeof ChatEnvironmentIdThreadIdRoute
|
||||
'/draft/$draftId': typeof ChatDraftDraftIdRoute
|
||||
@@ -93,6 +101,7 @@ export interface FileRoutesById {
|
||||
'/settings/archived': typeof SettingsArchivedRoute
|
||||
'/settings/connections': typeof SettingsConnectionsRoute
|
||||
'/settings/general': typeof SettingsGeneralRoute
|
||||
'/settings/source-control': typeof SettingsSourceControlRoute
|
||||
'/_chat/': typeof ChatIndexRoute
|
||||
'/_chat/$environmentId/$threadId': typeof ChatEnvironmentIdThreadIdRoute
|
||||
'/_chat/draft/$draftId': typeof ChatDraftDraftIdRoute
|
||||
@@ -106,6 +115,7 @@ export interface FileRouteTypes {
|
||||
| '/settings/archived'
|
||||
| '/settings/connections'
|
||||
| '/settings/general'
|
||||
| '/settings/source-control'
|
||||
| '/$environmentId/$threadId'
|
||||
| '/draft/$draftId'
|
||||
fileRoutesByTo: FileRoutesByTo
|
||||
@@ -115,6 +125,7 @@ export interface FileRouteTypes {
|
||||
| '/settings/archived'
|
||||
| '/settings/connections'
|
||||
| '/settings/general'
|
||||
| '/settings/source-control'
|
||||
| '/'
|
||||
| '/$environmentId/$threadId'
|
||||
| '/draft/$draftId'
|
||||
@@ -126,6 +137,7 @@ export interface FileRouteTypes {
|
||||
| '/settings/archived'
|
||||
| '/settings/connections'
|
||||
| '/settings/general'
|
||||
| '/settings/source-control'
|
||||
| '/_chat/'
|
||||
| '/_chat/$environmentId/$threadId'
|
||||
| '/_chat/draft/$draftId'
|
||||
@@ -188,6 +200,13 @@ declare module '@tanstack/react-router' {
|
||||
preLoaderRoute: typeof SettingsArchivedRouteImport
|
||||
parentRoute: typeof SettingsRoute
|
||||
}
|
||||
'/settings/source-control': {
|
||||
id: '/settings/source-control'
|
||||
path: '/source-control'
|
||||
fullPath: '/settings/source-control'
|
||||
preLoaderRoute: typeof SettingsSourceControlRouteImport
|
||||
parentRoute: typeof SettingsRoute
|
||||
}
|
||||
'/_chat/draft/$draftId': {
|
||||
id: '/_chat/draft/$draftId'
|
||||
path: '/draft/$draftId'
|
||||
@@ -223,12 +242,14 @@ interface SettingsRouteChildren {
|
||||
SettingsArchivedRoute: typeof SettingsArchivedRoute
|
||||
SettingsConnectionsRoute: typeof SettingsConnectionsRoute
|
||||
SettingsGeneralRoute: typeof SettingsGeneralRoute
|
||||
SettingsSourceControlRoute: typeof SettingsSourceControlRoute
|
||||
}
|
||||
|
||||
const SettingsRouteChildren: SettingsRouteChildren = {
|
||||
SettingsArchivedRoute: SettingsArchivedRoute,
|
||||
SettingsConnectionsRoute: SettingsConnectionsRoute,
|
||||
SettingsGeneralRoute: SettingsGeneralRoute,
|
||||
SettingsSourceControlRoute: SettingsSourceControlRoute,
|
||||
}
|
||||
|
||||
const SettingsRouteWithChildren = SettingsRoute._addFileChildren(
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
|
||||
import { SourceControlSettingsPanel } from "../components/settings/SourceControlSettings";
|
||||
|
||||
export const Route = createFileRoute("/settings/source-control")({
|
||||
component: SourceControlSettingsPanel,
|
||||
});
|
||||
@@ -119,6 +119,9 @@ export interface WsRpcClient {
|
||||
readonly updateSettings: (
|
||||
patch: ServerSettingsPatch,
|
||||
) => ReturnType<RpcUnaryMethod<typeof WS_METHODS.serverUpdateSettings>>;
|
||||
readonly discoverSourceControl: RpcUnaryNoArgMethod<
|
||||
typeof WS_METHODS.serverDiscoverSourceControl
|
||||
>;
|
||||
readonly subscribeConfig: RpcStreamMethod<typeof WS_METHODS.subscribeServerConfig>;
|
||||
readonly subscribeLifecycle: RpcStreamMethod<typeof WS_METHODS.subscribeServerLifecycle>;
|
||||
readonly subscribeAuthAccess: RpcStreamMethod<typeof WS_METHODS.subscribeAuthAccess>;
|
||||
@@ -224,6 +227,8 @@ export function createWsRpcClient(transport: WsTransport): WsRpcClient {
|
||||
getSettings: () => transport.request((client) => client[WS_METHODS.serverGetSettings]({})),
|
||||
updateSettings: (patch) =>
|
||||
transport.request((client) => client[WS_METHODS.serverUpdateSettings]({ patch })),
|
||||
discoverSourceControl: () =>
|
||||
transport.request((client) => client[WS_METHODS.serverDiscoverSourceControl]({})),
|
||||
subscribeConfig: (listener, options) =>
|
||||
transport.subscribe(
|
||||
(client) => client[WS_METHODS.subscribeServerConfig]({}),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { SourceControlProviderInfo } from "@t3tools/contracts";
|
||||
|
||||
export interface ChangeRequestPresentation {
|
||||
readonly icon: "github" | "gitlab" | "azure-devops" | "change-request";
|
||||
readonly icon: "github" | "gitlab" | "azure-devops" | "bitbucket" | "change-request";
|
||||
readonly providerName: string;
|
||||
readonly shortName: string;
|
||||
readonly longName: string;
|
||||
@@ -44,6 +44,17 @@ const AZURE_DEVOPS_CHANGE_REQUEST_PRESENTATION: ChangeRequestPresentation = {
|
||||
urlExample: "https://dev.azure.com/org/project/_git/repo/pullrequest/42",
|
||||
};
|
||||
|
||||
const BITBUCKET_CHANGE_REQUEST_PRESENTATION: ChangeRequestPresentation = {
|
||||
icon: "bitbucket",
|
||||
providerName: "Bitbucket",
|
||||
shortName: "PR",
|
||||
longName: "pull request",
|
||||
pluralLongName: "pull requests",
|
||||
providerLongName: "Bitbucket pull request",
|
||||
checkoutCommandExample: "bb pr checkout 123",
|
||||
urlExample: "https://bitbucket.org/workspace/repo/pull-requests/42",
|
||||
};
|
||||
|
||||
const GENERIC_CHANGE_REQUEST_PRESENTATION: ChangeRequestPresentation = {
|
||||
icon: "change-request",
|
||||
providerName: "source control",
|
||||
@@ -66,6 +77,8 @@ export function resolveChangeRequestPresentation(
|
||||
return GITLAB_CHANGE_REQUEST_PRESENTATION;
|
||||
case "azure-devops":
|
||||
return AZURE_DEVOPS_CHANGE_REQUEST_PRESENTATION;
|
||||
case "bitbucket":
|
||||
return BITBUCKET_CHANGE_REQUEST_PRESENTATION;
|
||||
case "unknown":
|
||||
return GENERIC_CHANGE_REQUEST_PRESENTATION;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ import type {
|
||||
import type { EnvironmentId } from "./baseSchemas.ts";
|
||||
import { EditorId } from "./editor.ts";
|
||||
import { ServerSettings, type ClientSettings, type ServerSettingsPatch } from "./settings.ts";
|
||||
import type { SourceControlDiscoveryResult } from "./sourceControl.ts";
|
||||
|
||||
export interface ContextMenuItem<T extends string = string> {
|
||||
id: T;
|
||||
@@ -227,6 +228,7 @@ export interface LocalApi {
|
||||
upsertKeybinding: (input: ServerUpsertKeybindingInput) => Promise<ServerUpsertKeybindingResult>;
|
||||
getSettings: () => Promise<ServerSettings>;
|
||||
updateSettings: (patch: ServerSettingsPatch) => Promise<ServerSettings>;
|
||||
discoverSourceControl: () => Promise<SourceControlDiscoveryResult>;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ import {
|
||||
ServerUpsertKeybindingResult,
|
||||
} from "./server.ts";
|
||||
import { ServerSettings, ServerSettingsError, ServerSettingsPatch } from "./settings.ts";
|
||||
import { SourceControlDiscoveryResult } from "./sourceControl.ts";
|
||||
|
||||
export const WS_METHODS = {
|
||||
// Project registry methods
|
||||
@@ -121,6 +122,7 @@ export const WS_METHODS = {
|
||||
serverUpsertKeybinding: "server.upsertKeybinding",
|
||||
serverGetSettings: "server.getSettings",
|
||||
serverUpdateSettings: "server.updateSettings",
|
||||
serverDiscoverSourceControl: "server.discoverSourceControl",
|
||||
|
||||
// Streaming subscriptions
|
||||
subscribeVcsStatus: "subscribeVcsStatus",
|
||||
@@ -167,6 +169,11 @@ export const WsServerUpdateSettingsRpc = Rpc.make(WS_METHODS.serverUpdateSetting
|
||||
error: ServerSettingsError,
|
||||
});
|
||||
|
||||
export const WsServerDiscoverSourceControlRpc = Rpc.make(WS_METHODS.serverDiscoverSourceControl, {
|
||||
payload: Schema.Struct({}),
|
||||
success: SourceControlDiscoveryResult,
|
||||
});
|
||||
|
||||
export const WsProjectsSearchEntriesRpc = Rpc.make(WS_METHODS.projectsSearchEntries, {
|
||||
payload: ProjectSearchEntriesInput,
|
||||
success: ProjectSearchEntriesResult,
|
||||
@@ -372,6 +379,7 @@ export const WsRpcGroup = RpcGroup.make(
|
||||
WsServerUpsertKeybindingRpc,
|
||||
WsServerGetSettingsRpc,
|
||||
WsServerUpdateSettingsRpc,
|
||||
WsServerDiscoverSourceControlRpc,
|
||||
WsProjectsSearchEntriesRpc,
|
||||
WsProjectsWriteFileRpc,
|
||||
WsShellOpenInEditorRpc,
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { Schema } from "effect";
|
||||
import { PositiveInt, TrimmedNonEmptyString } from "./baseSchemas.ts";
|
||||
import { VcsDriverKind } from "./vcs.ts";
|
||||
|
||||
export const SourceControlProviderKind = Schema.Literals([
|
||||
"github",
|
||||
"gitlab",
|
||||
"azure-devops",
|
||||
"bitbucket",
|
||||
"unknown",
|
||||
]);
|
||||
export type SourceControlProviderKind = typeof SourceControlProviderKind.Type;
|
||||
@@ -41,6 +43,43 @@ export const SourceControlRepositoryCloneUrls = Schema.Struct({
|
||||
});
|
||||
export type SourceControlRepositoryCloneUrls = typeof SourceControlRepositoryCloneUrls.Type;
|
||||
|
||||
export const SourceControlDiscoveryStatus = Schema.Literals(["available", "missing"]);
|
||||
export type SourceControlDiscoveryStatus = typeof SourceControlDiscoveryStatus.Type;
|
||||
|
||||
const SourceControlDiscoveryItemFields = {
|
||||
label: TrimmedNonEmptyString,
|
||||
executable: TrimmedNonEmptyString,
|
||||
implemented: Schema.Boolean,
|
||||
status: SourceControlDiscoveryStatus,
|
||||
version: Schema.Option(TrimmedNonEmptyString),
|
||||
installHint: TrimmedNonEmptyString,
|
||||
detail: Schema.Option(TrimmedNonEmptyString),
|
||||
} as const;
|
||||
|
||||
export const SourceControlDiscoveryItem = Schema.Struct({
|
||||
kind: Schema.String,
|
||||
...SourceControlDiscoveryItemFields,
|
||||
});
|
||||
export type SourceControlDiscoveryItem = typeof SourceControlDiscoveryItem.Type;
|
||||
|
||||
export const VcsDiscoveryItem = Schema.Struct({
|
||||
kind: VcsDriverKind,
|
||||
...SourceControlDiscoveryItemFields,
|
||||
});
|
||||
export type VcsDiscoveryItem = typeof VcsDiscoveryItem.Type;
|
||||
|
||||
export const SourceControlProviderDiscoveryItem = Schema.Struct({
|
||||
kind: SourceControlProviderKind,
|
||||
...SourceControlDiscoveryItemFields,
|
||||
});
|
||||
export type SourceControlProviderDiscoveryItem = typeof SourceControlProviderDiscoveryItem.Type;
|
||||
|
||||
export const SourceControlDiscoveryResult = Schema.Struct({
|
||||
versionControlSystems: Schema.Array(VcsDiscoveryItem),
|
||||
sourceControlProviders: Schema.Array(SourceControlProviderDiscoveryItem),
|
||||
});
|
||||
export type SourceControlDiscoveryResult = typeof SourceControlDiscoveryResult.Type;
|
||||
|
||||
export class SourceControlProviderError extends Schema.TaggedErrorClass<SourceControlProviderError>()(
|
||||
"SourceControlProviderError",
|
||||
{
|
||||
|
||||
@@ -38,6 +38,10 @@ function isAzureDevOpsHost(host: string): boolean {
|
||||
return host === "dev.azure.com" || host.endsWith(".visualstudio.com");
|
||||
}
|
||||
|
||||
function isBitbucketHost(host: string): boolean {
|
||||
return host === "bitbucket.org" || host.includes("bitbucket");
|
||||
}
|
||||
|
||||
export function detectSourceControlProviderFromRemoteUrl(
|
||||
remoteUrl: string,
|
||||
): SourceControlProviderInfo | null {
|
||||
@@ -70,6 +74,14 @@ export function detectSourceControlProviderFromRemoteUrl(
|
||||
};
|
||||
}
|
||||
|
||||
if (isBitbucketHost(host)) {
|
||||
return {
|
||||
kind: "bitbucket",
|
||||
name: host === "bitbucket.org" ? "Bitbucket" : "Bitbucket Self-Hosted",
|
||||
baseUrl: toBaseUrl(host),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
kind: "unknown",
|
||||
name: host,
|
||||
|
||||
Reference in new issue
Block a user