TypeScript
refactor(web): host presentation and behavior come from client definitions (#17757)
Julius Marminge579159d6c6e9
diff --git a/apps/web/src/components/CommandPalette.tsx b/apps/web/src/components/CommandPalette.tsxindex b85b0ca2cdc..472e15b98c4 100644--- a/apps/web/src/components/CommandPalette.tsx+++ b/apps/web/src/components/CommandPalette.tsx@@ -14,7 +14,15 @@ import {getNewProjectGitHubTarget,getNewProjectPathPreview,normalizePastedCloneUrl,+ addProjectRemoteSourceLabel,+ addProjectRemoteSourcePathHint,+ addProjectRemoteSourceProvider,+ buildAddProjectRemoteSourceReadiness,+ sortAddProjectProviderSources,+ type AddProjectRemoteSource,+ type AddProjectRemoteSourceReadiness,} from "@t3tools/client-runtime/operations/projects";+import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";import { connectionStatusText } from "@t3tools/client-runtime/connection";import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";import { resolveThreadReferenceCopyTarget } from "@t3tools/shared/threadReference";@@ -187,14 +195,8 @@ import {CommandPaletteVirtualizedResults,scrollCommandPaletteRowIntoView,} from "./CommandPaletteResults";-import {- AzureDevOpsIcon,- BitbucketIcon,- GitCafeIcon,- GitHubIcon,- GitLabIcon,- ForgejoIcon,-} from "./Icons";+import { GitHubIcon } from "./Icons";+import { sourceControlIcon } from "~/sourceControlPresentation";import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";import { Checkbox } from "./ui/checkbox";import { ProjectFavicon } from "./ProjectFavicon";@@ -257,15 +259,6 @@ interface AddProjectEnvironmentOption {readonly status: string;}-type AddProjectRemoteProviderKind =- | "github"- | "gitlab"- | "forgejo"- | "bitbucket"- | "azure-devops"- | "gitcafe";-type AddProjectRemoteSource = AddProjectRemoteProviderKind | "url";-type AddProjectCloneFlow =| {readonly step: "repository";@@ -281,83 +274,10 @@ type AddProjectCloneFlow =readonly remoteUrl: string;};-const REMOTE_PROJECT_SOURCES: ReadonlyArray<AddProjectRemoteSource> = [- "url",- "github",- "gitlab",- "forgejo",- "bitbucket",- "azure-devops",- "gitcafe",-];-const REMOTE_PROJECT_PROVIDER_SOURCES: ReadonlyArray<AddProjectRemoteProviderKind> = [- "github",- "gitlab",- "forgejo",- "bitbucket",- "azure-devops",- "gitcafe",-];--function remoteProjectSourceLabel(source: AddProjectRemoteSource): string {- switch (source) {- case "github":- return "GitHub";- case "forgejo":- return "Forgejo / Gitea";- case "gitlab":- return "GitLab";- case "bitbucket":- return "Bitbucket";- case "azure-devops":- return "Azure DevOps";- case "gitcafe":- return "GitCafe";- case "url":- return "Git URL";- }-}--function remoteProjectSourcePathHint(source: AddProjectRemoteSource): string {- switch (source) {- case "forgejo":- case "github":- case "gitcafe":- return "owner/repo";- case "gitlab":- return "group/project";- case "bitbucket":- return "workspace/repository";- case "azure-devops":- return "project/repository";- case "url":- return "URL";- }-}--function remoteProjectSourceProvider(- source: AddProjectRemoteSource,-): AddProjectRemoteProviderKind | null {- return source === "url" ? null : source;-}-function remoteProjectSourceIcon(source: AddProjectRemoteSource, className: string): ReactNode {- switch (source) {- case "github":- return <GitHubIcon className={className} />;- case "forgejo":- return <ForgejoIcon className={className} />;- case "gitlab":- return <GitLabIcon className={className} />;- case "bitbucket":- return <BitbucketIcon className={className} />;- case "azure-devops":- return <AzureDevOpsIcon className={className} />;- case "gitcafe":- return <GitCafeIcon className={className} />;- case "url":- return <LinkIcon className={className} />;- }+ if (source === "url") return <LinkIcon className={className} />;+ const Icon = sourceControlIcon(sourceControlClients.get(source));+ return <Icon className={className} />;}function projectFaviconIcon(project: Project): ReactNode {@@ -370,82 +290,26 @@ function remoteProjectInputPlaceholder(flow: AddProjectCloneFlow | null): stringif (flow.source === "url") {return "Enter Git clone URL";}- return `Enter ${remoteProjectSourceLabel(flow.source)} repository (${remoteProjectSourcePathHint(flow.source)})`;-}--function sourceProviderKind(source: AddProjectRemoteSource): AddProjectRemoteProviderKind | null {- return source === "url" ? null : source;-}--function sortAddProjectProviderSources(- readinessBySource: AddProjectRemoteSourceReadiness,-): ReadonlyArray<AddProjectRemoteProviderKind> {- return REMOTE_PROJECT_PROVIDER_SOURCES.toSorted((left, right) => {- const leftReady = readinessBySource[left].ready;- const rightReady = readinessBySource[right].ready;- if (leftReady !== rightReady) {- return leftReady ? -1 : 1;- }- return remoteProjectSourceLabel(left).localeCompare(remoteProjectSourceLabel(right));- });+ return `Enter ${addProjectRemoteSourceLabel(flow.source)} repository (${addProjectRemoteSourcePathHint(flow.source)})`;}-type AddProjectRemoteSourceReadiness = Record<- AddProjectRemoteSource,- { readonly ready: boolean; readonly hint: string | null }->;--function buildAddProjectRemoteSourceReadiness(+/** The palette's readiness, pointing at Settings by its menu path. */+function buildPaletteRemoteSourceReadiness(discovery: SourceControlDiscoveryResult | null,): AddProjectRemoteSourceReadiness {- const unavailable = {- ready: false,- hint: "Provider status unavailable. Open Settings -> Source Control and rescan.",- } as const;- const defaultReadiness: AddProjectRemoteSourceReadiness = {- url: { ready: true, hint: null },- github: unavailable,- gitlab: unavailable,- forgejo: unavailable,- bitbucket: unavailable,- "azure-devops": unavailable,- gitcafe: unavailable,+ const readiness = buildAddProjectRemoteSourceReadiness(discovery);+ return (source) => {+ const entry = readiness(source);+ return entry.hint === null+ ? entry+ : {+ ...entry,+ hint: entry.hint.replace(+ "Open Source Control settings",+ "Open Settings -> Source Control",+ ),+ };};-- if (!discovery) {- return defaultReadiness;- }-- const providerByKind = new Map(- discovery.sourceControlProviders.map((provider) => [provider.kind, provider]),- );- const readiness = { ...defaultReadiness };-- for (const source of REMOTE_PROJECT_SOURCES) {- const kind = sourceProviderKind(source);- if (!kind) continue;- const provider = providerByKind.get(SourceControlProviderKind.make(kind));- if (!provider) {- readiness[source] = unavailable;- continue;- }- if (provider.status !== "available") {- readiness[source] = { ready: false, hint: provider.installHint };- continue;- }- if (provider.auth.status === "unauthenticated") {- readiness[source] = {- ready: false,- hint:- Option.getOrNull(provider.auth.detail) ??- `${provider.label} is not authenticated. Open Settings -> Source Control for setup guidance.`,- };- continue;- }- readiness[source] = { ready: true, hint: null };- }-- return readiness;}function errorMessage(error: unknown): string {@@ -1673,13 +1537,13 @@ function OpenCommandPaletteDialog(props: {];for (const source of orderedSources) {- const label = remoteProjectSourceLabel(source);+ const label = addProjectRemoteSourceLabel(source);const title = source === "url" ? "Git URL" : `${label} repository`;const description =source === "url"? "Clone from a remote URL"- : `Clone ${label} ${remoteProjectSourcePathHint(source)}`;- const readiness = readinessBySource[source];+ : `Clone ${label} ${addProjectRemoteSourcePathHint(source)}`;+ const readiness = readinessBySource(source);const disabledHint = readiness.hint;const titleTrailingContent = readiness.ready ? undefined : (@@ -1767,7 +1631,7 @@ function OpenCommandPaletteDialog(props: {addonIcon: <FolderPlusIcon className={ADDON_ICON_CLASS} />,groups: buildAddProjectSourceGroups(environmentId,- buildAddProjectRemoteSourceReadiness(+ buildPaletteRemoteSourceReadiness(browseEnvironmentId === environmentId ? sourceControlDiscovery.data : null,),),@@ -2105,13 +1969,13 @@ function OpenCommandPaletteDialog(props: {"repository","repo","git",- "github",- "gitlab",- "forgejo",- "bitbucket",- "azure",- "devops",- "gitcafe",+ // Every host's name, spelled as a word: "azure devops" searches as `azure` and `devops`.+ ...sourceControlClients.definitions.flatMap((definition) =>+ definition.pickerLabel+ .toLowerCase()+ .split(/[^a-z0-9]+/u)+ .filter(Boolean),+ ),"url","environment",],@@ -2356,7 +2220,7 @@ function OpenCommandPaletteDialog(props: {currentView.groups[0]?.value === sourceSelectionViewValue? buildAddProjectSourceGroups(addProjectEnvironmentId,- buildAddProjectRemoteSourceReadiness(sourceControlDiscovery.data),+ buildPaletteRemoteSourceReadiness(sourceControlDiscovery.data),): currentView?.groups[0]?.value === "themes"? changeThemeItem.groups@@ -2606,7 +2470,7 @@ function OpenCommandPaletteDialog(props: {return;}- const provider = remoteProjectSourceProvider(addProjectCloneFlow.source);+ const provider = addProjectRemoteSourceProvider(addProjectCloneFlow.source);if (!provider) {const destinationPath = getCloneDestinationPath(getDefaultCloneParentPath(addProjectCloneFlow.environmentId),@@ -2631,7 +2495,7 @@ function OpenCommandPaletteDialog(props: {const lookupResult = await lookupRepository({environmentId: addProjectCloneFlow.environmentId,input: {- provider: SourceControlProviderKind.make(provider),+ provider,repository: rawRepository,},});diff --git a/apps/web/src/components/GitActionsControl.logic.ts b/apps/web/src/components/GitActionsControl.logic.tsindex 5422628825a..af6206625c4 100644--- a/apps/web/src/components/GitActionsControl.logic.ts+++ b/apps/web/src/components/GitActionsControl.logic.ts@@ -4,11 +4,8 @@ import type {VcsStatusResult,} from "@t3tools/contracts";import { isTemporaryWorktreeBranch } from "@t3tools/shared/git";-import {- DEFAULT_CHANGE_REQUEST_TERMINOLOGY,- getChangeRequestTerminology,- type ChangeRequestTerminology,-} from "../sourceControlPresentation";+import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";+import type { ChangeRequestTerminology } from "@t3tools/client-runtime/source-control-clients";export type GitActionIconName = "commit" | "push" | "pr";@@ -68,9 +65,7 @@ export function resolveGitActionResultToastTiming(function resolveChangeRequestTerminology(gitStatus: VcsStatusResult | null,): ChangeRequestTerminology {- return gitStatus?.sourceControlProvider- ? getChangeRequestTerminology(gitStatus.sourceControlProvider)- : DEFAULT_CHANGE_REQUEST_TERMINOLOGY;+ return sourceControlClients.get(gitStatus?.sourceControlProvider?.kind).changeRequest;}export function resolveGitActionProgressPresentation(input: {@@ -129,7 +124,7 @@ export function buildGitActionProgressStages(input: {shouldPushBeforePr?: boolean;terminology?: ChangeRequestTerminology;}): string[] {- const terminology = input.terminology ?? DEFAULT_CHANGE_REQUEST_TERMINOLOGY;+ const terminology = input.terminology ?? sourceControlClients.get(undefined).changeRequest;const branchStages = input.featureBranch ? ["Preparing feature ref..."] : [];const pushStage = input.pushTarget ? `Pushing to ${input.pushTarget}...` : "Pushing...";const prStages = [@@ -406,7 +401,7 @@ export function resolveDefaultBranchActionDialogCopy(input: {}): DefaultBranchActionDialogCopy {const branchLabel = input.branchName;const suffix = ` on "${branchLabel}". You can continue on this ref or create a feature ref and run the same action there.`;- const terminology = input.terminology ?? DEFAULT_CHANGE_REQUEST_TERMINOLOGY;+ const terminology = input.terminology ?? sourceControlClients.get(undefined).changeRequest;if (input.action === "push" || input.action === "commit_push") {if (input.includesCommit) {diff --git a/apps/web/src/components/GitActionsControl.tsx b/apps/web/src/components/GitActionsControl.tsxindex 703694ce165..494a841e8f2 100644--- a/apps/web/src/components/GitActionsControl.tsx+++ b/apps/web/src/components/GitActionsControl.tsx@@ -44,14 +44,6 @@ import {GlobeIcon,} from "lucide-react";import { Radio as RadioPrimitive } from "@base-ui/react/radio";-import {- AzureDevOpsIcon,- BitbucketIcon,- GitHubIcon,- GitLabIcon,- ForgejoIcon,- GitCafeIcon,-} from "~/components/Icons";import { RadioGroup } from "~/components/ui/radio-group";import { Spinner } from "~/components/ui/spinner";import { Toggle, ToggleGroup } from "~/components/ui/toggle-group";@@ -131,7 +123,8 @@ import {THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS,THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS,} from "./chat/threadDetailsPanelStyles";-import { getSourceControlPresentation } from "~/sourceControlPresentation";+import { getSourceControlPresentation, sourceControlIcon } from "~/sourceControlPresentation";+import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";import { useOpenLink } from "~/browser/useOpenLink";interface GitActionsControlProps {@@ -158,14 +151,6 @@ interface PendingDefaultBranchAction {filePaths?: string[];}-type PublishProviderKind =- | "github"- | "gitlab"- | "forgejo"- | "bitbucket"- | "azure-devops"- | "gitcafe";-type GitActionToastId = ReturnType<typeof toastManager.add>;interface RunGitActionWithToastInput {@@ -203,77 +188,25 @@ function requestVcsStatusRefresh(}const RUNNING_SOURCE_CONTROL_ACTIONS = ["runStackedAction", "pull", "publishRepository"] as const;-const PUBLISH_PROVIDER_OPTIONS = [- {- value: "forgejo",- label: "Forgejo / Gitea",- description: "Your signed-in server",- host: "your server",- pathPlaceholder: "owner/repo",- Icon: ForgejoIcon,- },- {- value: "github",- label: "GitHub",- description: "github.com",- host: "github.com",- pathPlaceholder: "owner/repo",- Icon: GitHubIcon,- },- {- value: "gitlab",- label: "GitLab",- description: "gitlab.com",- host: "gitlab.com",- pathPlaceholder: "group/project",- Icon: GitLabIcon,- },- {- value: "bitbucket",- label: "Bitbucket",- description: "bitbucket.org",- host: "bitbucket.org",- pathPlaceholder: "workspace/repository",- Icon: BitbucketIcon,- },- {- value: "azure-devops",- label: "Azure DevOps",- description: "dev.azure.com",- host: "dev.azure.com",- pathPlaceholder: "project/repository",- Icon: AzureDevOpsIcon,- },- {- value: "gitcafe",- label: "GitCafe",- description: "git.cafe",- host: "git.cafe",- pathPlaceholder: "owner/repo",- Icon: GitCafeIcon,- },-] as const satisfies ReadonlyArray<{- readonly value: PublishProviderKind;- readonly label: string;- readonly description: string;- readonly host: string;- readonly pathPlaceholder: string;- readonly Icon: typeof GitHubIcon;-}>;--function publishProviderOption(provider: PublishProviderKind) {+/** Every built-in host, in the order the built-in definitions list them. */+const PUBLISH_PROVIDER_OPTIONS = sourceControlClients.definitions.map((definition) => ({+ value: definition.kind,+ label: definition.pickerLabel,+ description: definition.publishDescription,+ pathPlaceholder: definition.repositoryPathHint,+ definition,+ Icon: sourceControlIcon(definition),+}));++function publishProviderOption(provider: SourceControlProviderKind) {return (PUBLISH_PROVIDER_OPTIONS.find((option) => option.value === provider) ??- PUBLISH_PROVIDER_OPTIONS[0]+ PUBLISH_PROVIDER_OPTIONS[0]!);}-function isPublishProviderKind(provider: string): provider is PublishProviderKind {- return PUBLISH_PROVIDER_OPTIONS.some((option) => option.value === provider);-}-function getPublishProviderReadiness(input: {- provider: PublishProviderKind;+ provider: SourceControlProviderKind;sourceControlProviders: ReadonlyArray<SourceControlProviderDiscoveryItem>;}): { readonly ready: boolean; readonly hint: string | null } {const discovered = input.sourceControlProviders.find(@@ -553,7 +486,7 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {}),);const [selectedPublishProvider, setSelectedPublishProvider] =- useState<PublishProviderKind | null>(null);+ useState<SourceControlProviderKind | null>(null);const [publishRepositoryOverride, setPublishRepositoryOverride] = useState<string | null>(null);const [publishVisibility, setPublishVisibility] =useState<SourceControlRepositoryVisibility>("private");@@ -574,43 +507,32 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {);const publishRepositoryAction = useSourceControlPublishRepositoryAction(sourceControlScope);const publishAccountByProvider = useMemo(() => {- const accounts: Record<PublishProviderKind, string | null> = {- github: null,- gitlab: null,- forgejo: null,- bitbucket: null,- "azure-devops": null,- gitcafe: null,- };+ const accounts = new Map<string, string | null>();for (const provider of sourceControlDiscovery.data?.sourceControlProviders ?? []) {- const kind: string = provider.kind;- if (isPublishProviderKind(kind)) {- accounts[kind] = Option.getOrNull(provider.auth.account);- }+ accounts.set(provider.kind, Option.getOrNull(provider.auth.account));}return accounts;}, [sourceControlDiscovery.data]);const publishProviderReadiness = useMemo(() => {const sourceControlProviders = sourceControlDiscovery.data?.sourceControlProviders ?? [];- return Object.fromEntries(+ const readiness = new Map(PUBLISH_PROVIDER_OPTIONS.map((option) => [option.value,- getPublishProviderReadiness({- provider: option.value,- sourceControlProviders,- }),+ getPublishProviderReadiness({ provider: option.value, sourceControlProviders }),]),- ) as Record<PublishProviderKind, { readonly ready: boolean; readonly hint: string | null }>;+ );+ return (provider: SourceControlProviderKind) =>+ readiness.get(provider) ?? { ready: false, hint: null };}, [sourceControlDiscovery.data]);const hasReadyPublishProvider = useMemo(- () => PUBLISH_PROVIDER_OPTIONS.some((option) => publishProviderReadiness[option.value].ready),+ () => PUBLISH_PROVIDER_OPTIONS.some((option) => publishProviderReadiness(option.value).ready),[publishProviderReadiness],);const sortedPublishProviderOptions = useMemo(() =>PUBLISH_PROVIDER_OPTIONS.toSorted((left, right) => {- const leftReady = publishProviderReadiness[left.value].ready;- const rightReady = publishProviderReadiness[right.value].ready;+ const leftReady = publishProviderReadiness(left.value).ready;+ const rightReady = publishProviderReadiness(right.value).ready;if (leftReady !== rightReady) {return leftReady ? -1 : 1;}@@ -619,26 +541,26 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {[publishProviderReadiness],);const firstReadyPublishProvider = sortedPublishProviderOptions.find(- (option) => publishProviderReadiness[option.value].ready,+ (option) => publishProviderReadiness(option.value).ready,)?.value;const publishProvider =- selectedPublishProvider !== null && publishProviderReadiness[selectedPublishProvider].ready+ selectedPublishProvider !== null && publishProviderReadiness(selectedPublishProvider).ready? selectedPublishProvider- : (firstReadyPublishProvider ?? selectedPublishProvider ?? "github");- const selectedPublishProviderReadiness = publishProviderReadiness[publishProvider];- const publishRepositoryPrefill = publishAccountByProvider[publishProvider]- ? `${publishAccountByProvider[publishProvider]}/`- : "";+ : (firstReadyPublishProvider ??+ selectedPublishProvider ??+ sourceControlClients.get(undefined).kind);+ const selectedPublishProviderReadiness = publishProviderReadiness(publishProvider);+ const publishAccount = publishAccountByProvider.get(publishProvider) ?? null;+ const publishRepositoryPrefill = publishAccount ? `${publishAccount}/` : "";const publishRepository = publishRepositoryOverride ?? publishRepositoryPrefill;const currentPublishProvider = publishProviderOption(publishProvider);- const publishHost =- publishProvider === "forgejo"- ? (Option.getOrNull(- sourceControlDiscovery.data?.sourceControlProviders.find(- (provider) => provider.kind === "forgejo",- )?.auth.host ?? Option.none(),- ) ?? currentPublishProvider.host)- : currentPublishProvider.host;+ const publishHost = currentPublishProvider.definition.publishHost(+ Option.getOrNull(+ sourceControlDiscovery.data?.sourceControlProviders.find(+ (provider) => provider.kind === publishProvider,+ )?.auth.host ?? Option.none(),+ ),+ );const publishPathPlaceholder = currentPublishProvider.pathPlaceholder;const publishProviderLabel = currentPublishProvider.label;const publishWizardSteps = ["Provider", "Repository", "Summary"] as const;@@ -672,7 +594,7 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {void (async () => {const result = await publishRepositoryAction.run({- provider: SourceControlProviderKind.make(publishProvider),+ provider: publishProvider,repository: publishRepository.trim(),visibility: publishVisibility,remoteName: publishRemoteName.trim() || "origin",@@ -757,14 +679,14 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {<RadioGroupvalue={publishProvider}onValueChange={(value) => {- setSelectedPublishProvider(value as PublishProviderKind);+ setSelectedPublishProvider(value as SourceControlProviderKind);setPublishRepositoryOverride(null);}}aria-labelledby="publish-provider-cards-label"className="grid grid-cols-2">{sortedPublishProviderOptions.map((option) => {- const readiness = publishProviderReadiness[option.value];+ const readiness = publishProviderReadiness(option.value);const isSelected = publishProvider === option.value && readiness.ready;if (!readiness.ready) {return (diff --git a/apps/web/src/components/ThreadStatusIndicators.tsx b/apps/web/src/components/ThreadStatusIndicators.tsxindex 146fac555c7..cab6f03f129 100644--- a/apps/web/src/components/ThreadStatusIndicators.tsx+++ b/apps/web/src/components/ThreadStatusIndicators.tsx@@ -6,14 +6,12 @@ import {import { useSupportsMultiplePullRequests } from "~/hooks/useSupportsMultiplePullRequests";import { pullRequestDetailToVcsStatus } from "@t3tools/client-runtime/state/pull-requests";-import { detectSourceControlProviderFromRemoteUrl } from "@t3tools/shared/sourceControl";import {resolveEnvironmentMachineKind,type EnvironmentId,type ThreadLinkedPullRequest,type ThreadPullRequestLink,type VcsStatusResult,- SourceControlProviderKind,} from "@t3tools/contracts";import { Atom } from "effect/reactivity";import { FolderGit2Icon, TerminalIcon } from "lucide-react";@@ -38,7 +36,7 @@ import { linkedPullRequestDetailAtom, useSharedPullRequestSummary } from "../staimport { useThreadRunningTerminalIds } from "../state/terminalSessions";import { vcsEnvironment } from "../state/vcs";import { useUiStateStore } from "../uiStateStore";-import { resolveChangeRequestPresentation } from "../sourceControlPresentation";+import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";import {resolveThreadLastVisitedAt,resolveThreadStatusPill,@@ -131,19 +129,10 @@ export function linkedPullRequestSnapshotStatus(): LinkedThreadPullRequestStatus | null {const snapshot = link.snapshot;if (snapshot === null) return null;- // GitCafe's `/pulls/` routes look like Forgejo's, so its two hosts are told apart first.- const kind =- detectSourceControlProviderFromRemoteUrl(link.url)?.kind === "gitcafe"- ? "gitcafe"- : link.url.includes("/-/merge_requests/")- ? "gitlab"- : link.url.includes("/pullrequest/")- ? "azure-devops"- : link.url.includes("/pull-requests/")- ? "bitbucket"- : link.url.includes("/pulls/")- ? "forgejo"- : "github";+ // A link records no host kind, so read it from the URL's change request path.+ const kind = (+ sourceControlClients.findByChangeRequestUrl(link.url) ?? sourceControlClients.get(undefined)+ ).kind;return {pr: {number: link.number,@@ -155,7 +144,7 @@ export function linkedPullRequestSnapshotStatus(baseRef: snapshot.baseBranch,...(snapshot.updatedAt === null ? {} : { updatedAt: snapshot.updatedAt }),},- sourceControlProvider: { kind: SourceControlProviderKind.make(kind), name: kind, baseUrl: "" },+ sourceControlProvider: { kind, name: kind, baseUrl: "" },};}@@ -442,12 +431,12 @@ export function prStatusIndicator(provider: VcsStatusResult["sourceControlProvider"] | null | undefined,): PrStatusIndicator | null {if (!pr) return null;- const presentation = resolveChangeRequestPresentation(provider);+ const { shortLabel } = sourceControlClients.get(provider?.kind).changeRequest;const state = resolvePullRequestState({ state: pr.state, isDraft: pr.isDraft === true });- const tooltipLead = `${presentation.shortName} #${pr.number} - ${state.label}`;+ const tooltipLead = `${shortLabel} #${pr.number} - ${state.label}`;return {- label: `${presentation.shortName} ${state.label.toLowerCase()}`,+ label: `${shortLabel} ${state.label.toLowerCase()}`,colorClass: state.toneClassName,Icon: state.Icon,tooltip: `${tooltipLead}: ${pr.title}`,diff --git a/apps/web/src/components/pullRequest/LinkPullRequestDialog.logic.test.ts b/apps/web/src/components/pullRequest/LinkPullRequestDialog.logic.test.tsindex 6d11ce7cd94..75dbc7ea461 100644--- a/apps/web/src/components/pullRequest/LinkPullRequestDialog.logic.test.ts+++ b/apps/web/src/components/pullRequest/LinkPullRequestDialog.logic.test.ts@@ -1,6 +1,11 @@import { describe, expect, it } from "vite-plus/test";-import { changeRequestWebUrl, resolveLinkPullRequestInput } from "./LinkPullRequestDialog";+import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";++import { resolveLinkPullRequestInput } from "./LinkPullRequestDialog";++const changeRequestWebUrl = (kind: string, host: string, repository: string, number: number) =>+ sourceControlClients.get(kind).changeRequestUrl({ host, repository, number });const project = {host: "github.com",diff --git a/apps/web/src/components/pullRequest/LinkPullRequestDialog.tsx b/apps/web/src/components/pullRequest/LinkPullRequestDialog.tsxindex 5ae5f8abd8b..dccb1f76e4e 100644--- a/apps/web/src/components/pullRequest/LinkPullRequestDialog.tsx+++ b/apps/web/src/components/pullRequest/LinkPullRequestDialog.tsx@@ -1,10 +1,5 @@-import { changeRequestUrlFor as changeRequestWebUrl } from "@t3tools/shared/changeRequestUrl";-export { changeRequestUrlFor as changeRequestWebUrl } from "@t3tools/shared/changeRequestUrl";-import {- pullRequestHostOf,- type ScopedThreadRef,- type SourceControlProviderKind,-} from "@t3tools/contracts";+import { pullRequestHostOf, type ScopedThreadRef } from "@t3tools/contracts";+import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";import { useAtomValue } from "@effect/atom-react";import { useCallback, useEffect, useMemo, useRef, useState } from "react";@@ -138,15 +133,19 @@ function LinkPullRequestDialog({identity.displayName ??(identity.owner && identity.name ? `${identity.owner}/${identity.name}` : null);if (repository === null) return null;- const kind = identity.provider as SourceControlProviderKind;- const host = pullRequestHostOf(identity, kind);+ const definition = sourceControlClients.get(identity.provider ?? "unknown");+ const host = pullRequestHostOf(identity, definition.kind);return {host,repository,webUrl: (number: number) =>- kind === "forgejo" && identity.webUrl- ? `${identity.webUrl.replace(/\/+$/, "")}/pulls/${number}`- : changeRequestWebUrl(kind, host, repository, number, identity.locator.remoteUrl),+ definition.changeRequestUrl({+ host,+ repository,+ number,+ remoteUrl: identity.locator.remoteUrl,+ webUrl: identity.webUrl,+ }),};}, [environmentProjects, projectId]);const linking = usePullRequestLinking(threadRef.environmentId);diff --git a/apps/web/src/components/pullRequest/PullRequestComposer.tsx b/apps/web/src/components/pullRequest/PullRequestComposer.tsxindex e00df846f39..f341f475e36 100644--- a/apps/web/src/components/pullRequest/PullRequestComposer.tsx+++ b/apps/web/src/components/pullRequest/PullRequestComposer.tsx@@ -1,3 +1,4 @@+import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";/*** The single floating control over a pull request. Commenting on the change and submitting the* review that carries the Code tab's line comments used to float as two buttons that crowded@@ -158,7 +159,9 @@ export function PullRequestComposer({environmentId={environmentId}reference={reference}verdicts={verdicts}- requestChangesSummaryRequired={detail.provider === "forgejo"}+ requestChangesSummaryRequired={sourceControlClients+ .get(detail.provider)+ .reviewSummaryRequired("request-changes")}textareaRef={reviewRef}pending={reviewPending}onPendingChange={setReviewPending}diff --git a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsxindex 137be41c960..e977c302be3 100644--- a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx+++ b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx@@ -83,6 +83,7 @@ import {} from "~/state/pullRequests";import { useAtomCommand } from "~/state/use-atom-command";import { PullRequestStackMenu } from "./PullRequestStackMenu";+import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";import { PullRequestThreadLinks } from "./PullRequestThreadLinks";import { vcsEnvironment } from "~/state/vcs";import { formatRelativeTimeLabel } from "~/timestampFormat";@@ -302,7 +303,7 @@ const openNumberContextMenu = (event.stopPropagation();void showPullRequestLinkContextMenu({url: detail.url,- openLabel: openOnHostLabel(detail.provider),+ openLabel: openOnHostLabel(sourceControlClients.get(detail.provider)),position: { x: event.clientX, y: event.clientY },});};@@ -732,16 +733,18 @@ export function PullRequestDetailPanel({if (detail?.autoMergeMethod !== undefined) setMergeMethod(detail.autoMergeMethod);}, [detail?.autoMergeMethod, pullRequestKey]);const repositoryUrl = detail === null ? null : changeRequestRepositoryUrl(detail.url);+ const hostClient = sourceControlClients.get(detail?.provider);const markdownContext = useMemo(- () => ({ repositoryUrl: detail?.provider === "github" ? repositoryUrl : null, threadRef }),- [detail?.provider, repositoryUrl, threadRef],+ () => ({+ repositoryUrl:+ repositoryUrl === null ? null : hostClient.referenceAutolinkRepositoryUrl(repositoryUrl),+ threadRef,+ }),+ [hostClient, repositoryUrl, threadRef],);const authorProfileUrl =- detail?.provider === "github" &&- detail.author !== null &&- !detail.author.login.endsWith("[bot]") &&- repositoryUrl !== null- ? new URL(`/${encodeURIComponent(detail.author.login)}`, repositoryUrl).toString()+ detail?.author && repositoryUrl !== null+ ? hostClient.authorProfileUrl(detail.author.login, repositoryUrl): null;const checkoutCommand = handoffSummary? pullRequestCheckoutCommand(@@ -1725,7 +1728,7 @@ export function PullRequestDetailPanel({</button>}/>- <TooltipPopup side="top">{openOnHostLabel(detail.provider)}</TooltipPopup>+ <TooltipPopup side="top">{openOnHostLabel(hostClient)}</TooltipPopup></Tooltip></>) : null}@@ -1780,7 +1783,7 @@ export function PullRequestDetailPanel({</button>}/>- <TooltipPopup side="top">{openOnHostLabel(detail.provider)}</TooltipPopup>+ <TooltipPopup side="top">{openOnHostLabel(hostClient)}</TooltipPopup></Tooltip><Tooltip><TooltipTrigger@@ -1806,6 +1809,7 @@ export function PullRequestDetailPanel({) : null}{nativeStack ? (<PullRequestStackMenu+ hostLabel={hostClient.label}stack={nativeStack}notice={nativeStackQuery.notice}onRetry={nativeStackQuery.error ? nativeStackQuery.refresh : undefined}@@ -2211,7 +2215,7 @@ export function PullRequestDetailPanel({) : null}<MenuItem onClick={() => void readLocalApi()?.shell.openExternal(detail.url)}><ArrowUpRightIcon className="size-3.5" />- {openOnHostLabel(detail.provider)}+ {openOnHostLabel(hostClient)}</MenuItem><MenuItem onClick={() => copyReference(detail.url, "PR link")}><LinkIcon className="size-3.5" />diff --git a/apps/web/src/components/pullRequest/PullRequestRow.tsx b/apps/web/src/components/pullRequest/PullRequestRow.tsxindex 63d249c7acf..a1467e79f05 100644--- a/apps/web/src/components/pullRequest/PullRequestRow.tsx+++ b/apps/web/src/components/pullRequest/PullRequestRow.tsx@@ -1,3 +1,4 @@+import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";import { SearchIcon } from "lucide-react";import { PullRequestStackPopover } from "./PullRequestStackPopover";import {@@ -158,7 +159,7 @@ function PullRequestRowImpl({event.stopPropagation();void showPullRequestLinkContextMenu({url: entry.url,- openLabel: openOnHostLabel(entry.provider),+ openLabel: openOnHostLabel(sourceControlClients.get(entry.provider)),position: { x: event.clientX, y: event.clientY },});}}diff --git a/apps/web/src/components/pullRequest/PullRequestStackMenu.tsx b/apps/web/src/components/pullRequest/PullRequestStackMenu.tsxindex ff8e886d14a..125b71f5020 100644--- a/apps/web/src/components/pullRequest/PullRequestStackMenu.tsx+++ b/apps/web/src/components/pullRequest/PullRequestStackMenu.tsx@@ -28,6 +28,7 @@ import { PullRequestStackLayerContent } from "./PullRequestStackLayerContent";import { PullRequestGlyph } from "./pullRequestIcons";export function PullRequestStackMenu({+ hostLabel,stack,reference,environmentId,@@ -39,6 +40,8 @@ export function PullRequestStackMenu({notice,onRetry,}: {+ /** The host's name, which reports what it did with the stack. */+ hostLabel: string;notice?: string | null;onRetry?: (() => void) | undefined;stack: PullRequestStack;@@ -117,7 +120,7 @@ export function PullRequestStackMenu({title: action === "merge" ? "Stack merge request completed" : "Stack rebased",description:action === "merge"- ? "GitHub merged the stack or added it to its merge queue."+ ? `${hostLabel} merged the stack or added it to its merge queue.`: undefined,});}@@ -232,7 +235,7 @@ export function PullRequestStackMenu({</DialogTitle><DialogDescription>{confirmation === "merge"- ? `Merge #${reference.number} and its unmerged layers below into ${stack.base} using ${mergeMethod}. GitHub checks their rules before merging or queueing them and rebases the remaining stack after merging.`+ ? `Merge #${reference.number} and its unmerged layers below into ${stack.base} using ${mergeMethod}. ${hostLabel} checks their rules before merging or queueing them and rebases the remaining stack after merging.`: `Rebase the remote branches from bottom to top onto ${stack.base}. This rewrites branch history and may restart checks. If a layer fails, earlier updates remain.`}</DialogDescription></DialogHeader>diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsxindex 9fae094ce56..bfda1209f9c 100644--- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx+++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx@@ -1,3 +1,4 @@+import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";import { useAtomCommand } from "~/state/use-atom-command";import type {EnvironmentId,@@ -83,10 +84,9 @@ function CommentIdentity({detail: PullRequestDetailView;}) {const actor = comment.author;- const profileUrl =- detail.provider === "github" && actor && !actor.login.endsWith("[bot]")- ? new URL(`/${encodeURIComponent(actor.login)}`, detail.url).toString()- : null;+ const profileUrl = actor+ ? sourceControlClients.get(detail.provider).authorProfileUrl(actor.login, detail.url)+ : null;return (<div className="flex min-w-0 flex-1 flex-wrap items-center gap-x-2 gap-y-1 text-xs"><PullRequestActorLabel actor={actor} profileUrl={profileUrl} className="max-w-full" />diff --git a/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx b/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsxindex 237528702b4..62924fe0a9d 100644--- a/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx+++ b/apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx@@ -1,5 +1,6 @@import type { ProjectId, ScopedThreadRef, ThreadPullRequestLink } from "@t3tools/contracts";import { detectSourceControlProviderFromRemoteUrl } from "@t3tools/shared/sourceControl";+import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";import {resolveThreadPullRequestChains,visibleThreadPullRequests,@@ -210,7 +211,7 @@ function LinkRow({</TooltipTrigger><TooltipPopup>{stack.kind === "native"- ? `GitHub stack of ${stack.size}: merging a layer lands the ones below it.`+ ? `${sourceControlClients.hostLabelForChangeRequestUrl(link.url)} stack of ${stack.size}: merging a layer lands the ones below it.`: `${stack.size} pull requests chained by base branch.`}</TooltipPopup></Tooltip>diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.tsindex 0a367768a2d..cd9d2522064 100644--- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts+++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts@@ -1,3 +1,4 @@+import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";import * as Schema from "effect/Schema";import {@@ -68,9 +69,6 @@ export function resolvePullRequestMergeMethod(return allowed[0] ?? "merge";}-const safeShellArgument = /^[A-Za-z0-9._/@+=,-]+$/;-const bitbucketRepositoryName = /^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/;-export type PullRequestPrimaryControl =| "resolve"| "ready"@@ -117,32 +115,9 @@ export function pullRequestCheckoutCommand(headRepositoryNameWithOwner?: string | null,repositoryUrl?: string | null,): string | null {- switch (provider) {- case "github":- return `gh pr checkout ${number}`;- case "gitlab":- return `glab mr checkout ${number}`;- case "forgejo":- return repositoryUrl- ? `git fetch '${repositoryUrl.replaceAll("'", "'\\''")}' refs/pull/${number}/head && git checkout -B pulls/${number} FETCH_HEAD`- : null;- case "azure-devops":- return `az repos pr checkout --id ${number}`;- case "gitcafe":- return `cafe pr checkout ${number}`;- case "bitbucket": {- if (- !headRepositoryNameWithOwner ||- !bitbucketRepositoryName.test(headRepositoryNameWithOwner) ||- !safeShellArgument.test(headBranch)- ) {- return null;- }- return `git clone --single-branch --branch ${headBranch} https://bitbucket.org/${headRepositoryNameWithOwner}.git t3code-pr-${number}`;- }- default:- return null;- }+ return sourceControlClients+ .get(provider)+ .checkoutCommand({ number, headBranch, headRepositoryNameWithOwner, repositoryUrl });}/** Build a checkout command from identity metadata while the detail request is still pending. */@@ -151,15 +126,23 @@ export function loadingPullRequestCheckoutCommand(identity: RepositoryIdentity | null | undefined,): string | null {const host = reference.host?.trim().toLowerCase();- const provider =- identity?.provider ??- (host === "github.com" ? "github" : host === "gitlab.com" ? "gitlab" : null);- if (provider !== "github" && provider !== "gitlab" && provider !== "azure-devops") return null;- const kind = SourceControlProviderKind.make(provider);- if (identity?.provider !== undefined && host && pullRequestHostOf(identity, kind) !== host) {+ // Before the detail loads, only the number is known, so only hosts whose command needs nothing+ // else qualify. Without an identity, only a public hostname names the host.+ const definition = identity?.provider+ ? sourceControlClients.find(identity.provider)+ : host+ ? sourceControlClients.findByPublicHost(host)+ : undefined;+ const command = definition?.checkoutCommand({ number: reference.number, headBranch: "" });+ if (!definition || !command) return null;+ if (+ identity?.provider !== undefined &&+ host &&+ pullRequestHostOf(identity, definition.kind) !== host+ ) {return null;}- return pullRequestCheckoutCommand(kind, reference.number, "");+ return command;}/** Activity changes only when the same host resource reports a newer revision. */@@ -967,7 +950,9 @@ export function buildFixFindingsHandoff(input: {? ["Failing checks:", ...includedChecks.map((check) => `> ${check}`)]: []),...(input.commentsTruncated- ? ["The conversation was truncated; more review comments may exist on GitHub."]+ ? [+ `The conversation was truncated; more review comments may exist on ${sourceControlClients.hostLabelForChangeRequestUrl(input.url)}.`,+ ]: []),...(omitted > 0 ? [`${omitted} further findings were omitted.`] : []),...(includedThreads.length === 0 &&diff --git a/apps/web/src/components/pullRequest/pullRequestLinkContextMenu.ts b/apps/web/src/components/pullRequest/pullRequestLinkContextMenu.tsindex 6b673ad9832..7789f6062cb 100644--- a/apps/web/src/components/pullRequest/pullRequestLinkContextMenu.ts+++ b/apps/web/src/components/pullRequest/pullRequestLinkContextMenu.ts@@ -1,4 +1,8 @@import type { ContextMenuItem } from "@t3tools/contracts";+import {+ type SourceControlClientDefinition,+ UNKNOWN_SOURCE_CONTROL_CLIENT,+} from "@t3tools/client-runtime/source-control-clients";import { writeTextToClipboard } from "~/hooks/useCopyToClipboard";import { readLocalApi } from "~/localApi";@@ -8,17 +12,8 @@ import { toastManager } from "../ui/toast";export type PullRequestLinkContextMenuAction = "copy-link" | "open-external";/** Named for the host rather than "externally": the point is where you will land. */-const OPEN_ON_HOST_LABELS: Partial<Record<string, string>> = {- github: "Open on GitHub",- gitlab: "Open on GitLab",- forgejo: "Open on Forgejo",- bitbucket: "Open on Bitbucket",- gitcafe: "Open on GitCafe",- "azure-devops": "Open on Azure DevOps",-};--export const openOnHostLabel = (provider: string): string =>- OPEN_ON_HOST_LABELS[provider] ?? "Open on host";+export const openOnHostLabel = (host: SourceControlClientDefinition): string =>+ host === UNKNOWN_SOURCE_CONTROL_CLIENT ? "Open on host" : `Open on ${host.label}`;/** Copy first: it is the reason to right-click a number rather than click it. */function pullRequestLinkContextMenuItems(diff --git a/apps/web/src/components/settings/SourceControlSettings.tsx b/apps/web/src/components/settings/SourceControlSettings.tsxindex ec408ad97cd..db7836054ee 100644--- a/apps/web/src/components/settings/SourceControlSettings.tsx+++ b/apps/web/src/components/settings/SourceControlSettings.tsx@@ -5,7 +5,6 @@ import * as Option from "effect/Option";import { useEffect, useState, type ReactNode } from "react";import type {BackgroundActivitySettings,- SourceControlProviderKind,SourceControlDiscoveryResult,SourceControlProviderAuth,SourceControlProviderDiscoveryItem,@@ -46,17 +45,7 @@ import {import { Switch } from "../ui/switch";import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";-import {- AzureDevOpsIcon,- BitbucketIcon,- GitCafeIcon,- GitHubIcon,- GitIcon,- GitLabIcon,- ForgejoIcon,- JujutsuIcon,- type Icon,-} from "../Icons";+import { GitIcon, JujutsuIcon, type Icon } from "../Icons";import { BitbucketCredentialsSettings } from "./BitbucketCredentialsSettings";import { GitHubAccountSettings } from "./GitHubAccountSettings";import { GitHubTokenSettings } from "./GitHubTokenSettings";@@ -72,21 +61,14 @@ import {} from "./settingsLayout";import { searchableSetting } from "./settingsSearch";import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";+import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";+import { sourceControlIcon } from "~/sourceControlPresentation";const EMPTY_DISCOVERY_RESULT: SourceControlDiscoveryResult = {versionControlSystems: [],sourceControlProviders: [],};-const SOURCE_CONTROL_PROVIDER_ICONS: Partial<Record<string, Icon>> = {- github: GitHubIcon,- gitlab: GitLabIcon,- forgejo: ForgejoIcon,- "azure-devops": AzureDevOpsIcon,- bitbucket: BitbucketIcon,- gitcafe: GitCafeIcon,-};-const VCS_ICONS: Partial<Record<VcsDriverKind, Icon>> = {git: GitIcon,jj: JujutsuIcon,@@ -185,8 +167,9 @@ function SourceControlItemMark({readonly item: VcsDiscoveryItem | SourceControlProviderDiscoveryItem;}) {const dotClassName = itemStatusDot(item);+ const host = isProviderDiscoveryItem(item) ? sourceControlClients.find(item.kind) : undefined;const Icon = isProviderDiscoveryItem(item)- ? SOURCE_CONTROL_PROVIDER_ICONS[item.kind]+ ? host && sourceControlIcon(host): VCS_ICONS[item.kind];if (!Icon) {diff --git a/apps/web/src/sourceControlPresentation.ts b/apps/web/src/sourceControlPresentation.tsindex 61a1befd609..5ac72012c2d 100644--- a/apps/web/src/sourceControlPresentation.ts+++ b/apps/web/src/sourceControlPresentation.ts@@ -1,17 +1,10 @@import type { ElementType } from "react";-import type { SourceControlProviderInfo, SourceControlProviderKind } from "@t3tools/contracts";-export {- DEFAULT_CHANGE_REQUEST_TERMINOLOGY,- getChangeRequestTerminology,- resolveChangeRequestPresentation,- type ChangeRequestPresentation,- type ChangeRequestTerminology,-} from "@t3tools/shared/sourceControl";-import {- getChangeRequestTerminology,- resolveChangeRequestPresentation,- type ChangeRequestTerminology,-} from "@t3tools/shared/sourceControl";+import type { SourceControlProviderInfo } from "@t3tools/contracts";+import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";+import type {+ ChangeRequestTerminology,+ SourceControlClientDefinition,+} from "@t3tools/client-runtime/source-control-clients";import {AzureDevOpsIcon,BitbucketIcon,@@ -22,65 +15,53 @@ import {} from "./components/Icons";import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";+export type { ChangeRequestTerminology } from "@t3tools/client-runtime/source-control-clients";++type SourceControlIcon = ElementType<{ className?: string }>;++/** Web art for each definition `icon` key; a key without art draws the change request glyph. */+const SOURCE_CONTROL_ICONS: Partial<Record<string, SourceControlIcon>> = {+ github: GitHubIcon,+ gitlab: GitLabIcon,+ forgejo: ForgejoIcon,+ bitbucket: BitbucketIcon,+ "azure-devops": AzureDevOpsIcon,+ gitcafe: GitCafeIcon,+};++export function sourceControlIcon(definition: SourceControlClientDefinition): SourceControlIcon {+ return SOURCE_CONTROL_ICONS[definition.icon] ?? PullRequestGlyph.pullRequest;+}+export interface SourceControlPresentation {+ readonly definition: SourceControlClientDefinition;readonly providerName: string;readonly terminology: ChangeRequestTerminology;- readonly Icon: ElementType<{ className?: string }>;+ readonly Icon: SourceControlIcon;}+function presentDefinition(+ definition: SourceControlClientDefinition,+ providerName: string,+): SourceControlPresentation {+ return {+ definition,+ providerName,+ terminology: definition.changeRequest,+ Icon: sourceControlIcon(definition),+ };+}++/** Named as the server reported the host, e.g. "GitHub Self-Hosted", when it reported one. */export function getSourceControlPresentation(provider: SourceControlProviderInfo | null | undefined,): SourceControlPresentation {- const presentation = resolveChangeRequestPresentation(provider);- switch (presentation.icon) {- case "github":- return {- providerName: provider?.name || presentation.providerName,- terminology: getChangeRequestTerminology(provider),- Icon: GitHubIcon,- };- case "forgejo":- return {- providerName: provider?.name || presentation.providerName,- terminology: getChangeRequestTerminology(provider),- Icon: ForgejoIcon,- };- case "gitlab":- return {- providerName: provider?.name || presentation.providerName,- terminology: getChangeRequestTerminology(provider),- Icon: GitLabIcon,- };- case "azure-devops":- return {- providerName: provider?.name || presentation.providerName,- terminology: getChangeRequestTerminology(provider),- Icon: AzureDevOpsIcon,- };- case "bitbucket":- return {- providerName: provider?.name || presentation.providerName,- terminology: getChangeRequestTerminology(provider),- Icon: BitbucketIcon,- };- case "gitcafe":- return {- providerName: provider?.name || presentation.providerName,- terminology: getChangeRequestTerminology(provider),- Icon: GitCafeIcon,- };- case "change-request":- return {- providerName: provider?.name || presentation.providerName,- terminology: getChangeRequestTerminology(provider),- Icon: PullRequestGlyph.pullRequest,- };- }+ const definition = sourceControlClients.get(provider?.kind);+ return presentDefinition(definition, provider?.name || definition.label);}/** For surfaces that know only the host kind, such as a change request row or filter. */-export function getSourceControlPresentationForKind(- kind: SourceControlProviderKind,-): SourceControlPresentation {- return getSourceControlPresentation({ kind, name: "", baseUrl: "" });+export function getSourceControlPresentationForKind(kind: string): SourceControlPresentation {+ const definition = sourceControlClients.get(kind);+ return presentDefinition(definition, definition.label);}diff --git a/packages/client-runtime/src/sourceControlClients.ts b/packages/client-runtime/src/sourceControlClients.tsindex 108644a04b4..52a2b2d4d29 100644--- a/packages/client-runtime/src/sourceControlClients.ts+++ b/packages/client-runtime/src/sourceControlClients.ts@@ -12,6 +12,7 @@ import * as Bitbucket from "@t3tools/source-control-bitbucket/client/definition"import { makeSourceControlClientRegistry } from "@t3tools/source-control-core/client/definition";export {+ UNKNOWN_SOURCE_CONTROL_CLIENT,type ChangeRequestTerminology,type SourceControlClientDefinition,} from "@t3tools/source-control-core/client/definition";diff --git a/packages/shared/src/sourceControl.ts b/packages/shared/src/sourceControl.tsindex f8c1f99c5d3..eee0c817cb0 100644--- a/packages/shared/src/sourceControl.ts+++ b/packages/shared/src/sourceControl.ts@@ -24,11 +24,6 @@ export interface ChangeRequestTerminology {readonly singular: string;}-export const DEFAULT_CHANGE_REQUEST_TERMINOLOGY: ChangeRequestTerminology = {- shortLabel: "PR",- singular: "pull request",-};-const GITHUB_CHANGE_REQUEST_PRESENTATION: ChangeRequestPresentation = {icon: "github",providerName: "GitHub",@@ -132,20 +127,6 @@ function resolveChangeRequestPresentationForKind(return resolveChangeRequestPresentation({ kind, name: "", baseUrl: "" });}-export function getChangeRequestTerminology(- provider: SourceControlProviderInfo | null | undefined,-): ChangeRequestTerminology {- if (!provider) {- return DEFAULT_CHANGE_REQUEST_TERMINOLOGY;- }-- const presentation = resolveChangeRequestPresentation(provider);- return {- shortLabel: presentation.shortName,- singular: presentation.longName,- };-}-export function getChangeRequestTerminologyForKind(kind: SourceControlProviderKind,): ChangeRequestTerminology {diff --git a/packages/source-control-core/src/client/definition.ts b/packages/source-control-core/src/client/definition.tsindex 8db86cfcaf4..22bb0995708 100644--- a/packages/source-control-core/src/client/definition.ts+++ b/packages/source-control-core/src/client/definition.ts@@ -101,7 +101,7 @@ export function defineSourceControlClient<const Definition extends SourceControl}/** What clients show for a host they ship no definition for, including `unknown`. */-const UNKNOWN_SOURCE_CONTROL_CLIENT: SourceControlClientDefinition = {+export const UNKNOWN_SOURCE_CONTROL_CLIENT: SourceControlClientDefinition = {kind: SourceControlProviderKind.make("unknown"),label: "source control",pickerLabel: "source control",