Open History to see the last commit
1import type { ElementType } from "react";
2import type { SourceControlProviderInfo } from "@t3tools/contracts";
3import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
4import type {
5 ChangeRequestTerminology,
6 SourceControlClientDefinition,
7} from "@t3tools/client-runtime/source-control-clients";
8import {
9 AzureDevOpsIcon,
10 BitbucketIcon,
11 ForgejoIcon,
12 GitCafeIcon,
13 GitHubIcon,
14 GitLabIcon,
15} from "./components/Icons";
16import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
17
18export type { ChangeRequestTerminology } from "@t3tools/client-runtime/source-control-clients";
19
20type SourceControlIcon = ElementType<{ className?: string }>;
21
22const SOURCE_CONTROL_ICONS: Partial<Record<string, SourceControlIcon>> = {
23 github: GitHubIcon,
24 gitlab: GitLabIcon,
25 forgejo: ForgejoIcon,
26 bitbucket: BitbucketIcon,
27 "azure-devops": AzureDevOpsIcon,
28 gitcafe: GitCafeIcon,
29};
30
31export function sourceControlIcon(definition: SourceControlClientDefinition): SourceControlIcon {
32 return SOURCE_CONTROL_ICONS[definition.icon] ?? PullRequestGlyph.pullRequest;
33}
34
35export interface SourceControlPresentation {
36 readonly definition: SourceControlClientDefinition;
37 readonly providerName: string;
38 readonly terminology: ChangeRequestTerminology;
39 readonly Icon: SourceControlIcon;
40}
41
42function presentDefinition(
43 definition: SourceControlClientDefinition,
44 providerName: string,
45): SourceControlPresentation {
46 return {
47 definition,
48 providerName,
49 terminology: definition.changeRequest,
50 Icon: sourceControlIcon(definition),
51 };
52}
53
54export function getSourceControlPresentation(
55 provider: SourceControlProviderInfo | null | undefined,
56): SourceControlPresentation {
57 const definition = sourceControlClients.get(provider?.kind);
58 return presentDefinition(definition, provider?.name || definition.label);
59}
60
61export function getSourceControlPresentationForKind(kind: string): SourceControlPresentation {
62 const definition = sourceControlClients.get(kind);
63 return presentDefinition(definition, definition.label);
64}