Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

git.ts

167 lines5.4 KB

1import { Schema } from "effect";
2import { NonNegativeInt, PositiveInt, TrimmedNonEmptyString } from "./baseSchemas";
3​
4const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
5​
6// Domain Types
7​
8export const GitStackedAction = Schema.Literals(["commit", "commit_push", "commit_push_pr"]);
9export type GitStackedAction = typeof GitStackedAction.Type;
10export const GitCommitStepStatus = Schema.Literals(["created", "skipped_no_changes"]);
11export const GitPushStepStatus = Schema.Literals([
12 "pushed",
13 "skipped_not_requested",
14 "skipped_up_to_date",
15]);
16export const GitPrStepStatus = Schema.Literals([
17 "created",
18 "opened_existing",
19 "skipped_not_requested",
20]);
21export const GitStatusPrState = Schema.Literals(["open", "closed", "merged"]);
22export type GitStatusPrState = typeof GitStatusPrState.Type;
23​
24export const GitBranch = Schema.Struct({
25 name: TrimmedNonEmptyStringSchema,
26 current: Schema.Boolean,
27 isDefault: Schema.Boolean,
28 worktreePath: TrimmedNonEmptyStringSchema.pipe(Schema.NullOr),
29});
30export type GitBranch = typeof GitBranch.Type;
31​
32export const GitWorktree = Schema.Struct({
33 path: TrimmedNonEmptyStringSchema,
34 branch: TrimmedNonEmptyStringSchema,
35});
36export type GitWorktree = typeof GitWorktree.Type;
37​
38// RPC Inputs
39​
40export const GitStatusInput = Schema.Struct({
41 cwd: TrimmedNonEmptyStringSchema,
42});
43export type GitStatusInput = typeof GitStatusInput.Type;
44​
45export const GitPullInput = Schema.Struct({
46 cwd: TrimmedNonEmptyStringSchema,
47});
48export type GitPullInput = typeof GitPullInput.Type;
49​
50export const GitRunStackedActionInput = Schema.Struct({
51 cwd: TrimmedNonEmptyStringSchema,
52 action: GitStackedAction,
53 commitMessage: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(10_000))),
54});
55export type GitRunStackedActionInput = typeof GitRunStackedActionInput.Type;
56​
57export const GitListBranchesInput = Schema.Struct({
58 cwd: TrimmedNonEmptyStringSchema,
59});
60export type GitListBranchesInput = typeof GitListBranchesInput.Type;
61​
62export const GitCreateWorktreeInput = Schema.Struct({
63 cwd: TrimmedNonEmptyStringSchema,
64 branch: TrimmedNonEmptyStringSchema,
65 newBranch: TrimmedNonEmptyStringSchema,
66 path: Schema.NullOr(TrimmedNonEmptyStringSchema),
67});
68export type GitCreateWorktreeInput = typeof GitCreateWorktreeInput.Type;
69​
70export const GitRemoveWorktreeInput = Schema.Struct({
71 cwd: TrimmedNonEmptyStringSchema,
72 path: TrimmedNonEmptyStringSchema,
73 force: Schema.optional(Schema.Boolean),
74});
75export type GitRemoveWorktreeInput = typeof GitRemoveWorktreeInput.Type;
76​
77export const GitCreateBranchInput = Schema.Struct({
78 cwd: TrimmedNonEmptyStringSchema,
79 branch: TrimmedNonEmptyStringSchema,
80});
81export type GitCreateBranchInput = typeof GitCreateBranchInput.Type;
82​
83export const GitCheckoutInput = Schema.Struct({
84 cwd: TrimmedNonEmptyStringSchema,
85 branch: TrimmedNonEmptyStringSchema,
86});
87export type GitCheckoutInput = typeof GitCheckoutInput.Type;
88​
89export const GitInitInput = Schema.Struct({
90 cwd: TrimmedNonEmptyStringSchema,
91});
92export type GitInitInput = typeof GitInitInput.Type;
93​
94// RPC Results
95​
96export const GitStatusPr = Schema.Struct({
97 number: PositiveInt,
98 title: TrimmedNonEmptyStringSchema,
99 url: Schema.String,
100 baseBranch: TrimmedNonEmptyStringSchema,
101 headBranch: TrimmedNonEmptyStringSchema,
102 state: GitStatusPrState,
103});
104export type GitStatusPr = typeof GitStatusPr.Type;
105​
106export const GitStatusResult = Schema.Struct({
107 branch: TrimmedNonEmptyStringSchema.pipe(Schema.NullOr),
108 hasWorkingTreeChanges: Schema.Boolean,
109 workingTree: Schema.Struct({
110 files: Schema.Array(
111 Schema.Struct({
112 path: TrimmedNonEmptyStringSchema,
113 insertions: NonNegativeInt,
114 deletions: NonNegativeInt,
115 }),
116 ),
117 insertions: NonNegativeInt,
118 deletions: NonNegativeInt,
119 }),
120 hasUpstream: Schema.Boolean,
121 aheadCount: NonNegativeInt,
122 behindCount: NonNegativeInt,
123 pr: Schema.NullOr(GitStatusPr),
124});
125export type GitStatusResult = typeof GitStatusResult.Type;
126​
127export const GitListBranchesResult = Schema.Struct({
128 branches: Schema.Array(GitBranch),
129 isRepo: Schema.Boolean,
130});
131export type GitListBranchesResult = typeof GitListBranchesResult.Type;
132​
133export const GitCreateWorktreeResult = Schema.Struct({
134 worktree: GitWorktree,
135});
136export type GitCreateWorktreeResult = typeof GitCreateWorktreeResult.Type;
137​
138export const GitRunStackedActionResult = Schema.Struct({
139 action: GitStackedAction,
140 commit: Schema.Struct({
141 status: GitCommitStepStatus,
142 commitSha: Schema.optional(TrimmedNonEmptyStringSchema),
143 subject: Schema.optional(TrimmedNonEmptyStringSchema),
144 }),
145 push: Schema.Struct({
146 status: GitPushStepStatus,
147 branch: Schema.optional(TrimmedNonEmptyStringSchema),
148 upstreamBranch: Schema.optional(TrimmedNonEmptyStringSchema),
149 setUpstream: Schema.optional(Schema.Boolean),
150 }),
151 pr: Schema.Struct({
152 status: GitPrStepStatus,
153 url: Schema.optional(Schema.String),
154 number: Schema.optional(PositiveInt),
155 baseBranch: Schema.optional(TrimmedNonEmptyStringSchema),
156 headBranch: Schema.optional(TrimmedNonEmptyStringSchema),
157 title: Schema.optional(TrimmedNonEmptyStringSchema),
158 }),
159});
160export type GitRunStackedActionResult = typeof GitRunStackedActionResult.Type;
161​
162export const GitPullResult = Schema.Struct({
163 status: Schema.Literals(["pulled", "skipped_up_to_date"]),
164 branch: TrimmedNonEmptyStringSchema,
165 upstreamBranch: TrimmedNonEmptyStringSchema.pipe(Schema.NullOr),
166});
167export type GitPullResult = typeof GitPullResult.Type;