Open History to see the last commit
1import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
2import { changeRequestTermKind } from "../../../lib/changeRequestTerm";
3import { SymbolView } from "../../../components/ui/AppSymbol";
4import { msg, plural, part, select } from "gt-react-native";
5import type { ComponentProps } from "react";
6import { View } from "react-native";
7import { Button } from "../../../components/ui/Button";
8import type { MessageResolver } from "../../../i18n/messages";
9
10export function SheetActionButton(props: {
11 readonly icon: ComponentProps<typeof SymbolView>["name"];
12 readonly label: string;
13 readonly disabled?: boolean;
14 readonly tone?: "primary" | "secondary" | "danger";
15 readonly onPress: () => void;
16}) {
17 return (
18 <View className="flex-1">
19 <Button {...props} fullWidth />
20 </View>
21 );
22}
23
24export function menuItemIconName(
25 icon: "commit" | "push" | "pr",
26): ComponentProps<typeof SymbolView>["name"] {
27 if (icon === "commit") return "checkmark.circle";
28 if (icon === "push") return "arrow.up.circle";
29 return "arrow.up.right.circle";
30}
31
32export function statusSummary(
33 gitStatus: {
34 readonly isRepo?: boolean;
35 readonly hasWorkingTreeChanges?: boolean;
36 readonly workingTree?: { readonly files: readonly { readonly path: string }[] };
37 readonly aheadCount?: number;
38 readonly behindCount?: number;
39 readonly pr?: { readonly state?: string; readonly number?: number } | null;
40 readonly sourceControlProvider?: { readonly kind: string } | null;
41 } | null,
42 resolve: MessageResolver,
43): string {
44 if (!gitStatus) {
45 return resolve(msg("Loading branch status\u2026"));
46 }
47
48 if (!gitStatus.isRepo) {
49 return resolve(msg("Not a git repository"));
50 }
51
52 const parts: string[] = [];
53 if (gitStatus.hasWorkingTreeChanges) {
54 const fileCount = gitStatus.workingTree?.files.length ?? 0;
55 parts.push(
56 resolve(
57 msg`${plural(
58 { count: fileCount },
59 {
60 one: part`${{ count: fileCount }} file changed`,
61 other: part`${{ count: fileCount }} files changed`,
62 },
63 )}`,
64 ),
65 );
66 } else {
67 parts.push(resolve(msg({ context: "git working tree has no changes" })`Clean`));
68 }
69 if ((gitStatus.aheadCount ?? 0) > 0) {
70 parts.push(
71 resolve(
72 msg`${plural(
73 { count: gitStatus.aheadCount ?? 0 },
74 {
75 one: part`${{ count: gitStatus.aheadCount ?? 0 }} ahead`,
76 other: part`${{ count: gitStatus.aheadCount ?? 0 }} ahead`,
77 },
78 )}`,
79 ),
80 );
81 }
82 if ((gitStatus.behindCount ?? 0) > 0) {
83 parts.push(
84 resolve(
85 msg`${plural(
86 { count: gitStatus.behindCount ?? 0 },
87 {
88 one: part`${{ count: gitStatus.behindCount ?? 0 }} behind`,
89 other: part`${{ count: gitStatus.behindCount ?? 0 }} behind`,
90 },
91 )}`,
92 ),
93 );
94 }
95 if (gitStatus.pr?.state === "open") {
96 const term = changeRequestTermKind(
97 sourceControlClients.get(gitStatus.sourceControlProvider?.kind).changeRequest,
98 );
99 parts.push(
100 resolve(
101 msg`${select(
102 { term },
103 {
104 mr: part`MR #${{ number: gitStatus.pr.number }} open`,
105 cr: part`change request #${{ number: gitStatus.pr.number }} open`,
106 other: part`PR #${{ number: gitStatus.pr.number }} open`,
107 },
108 )}`,
109 ),
110 );
111 }
112
113 return parts.join(" \u00b7 ");
114}