Use the new Merge scheme for Patch

`merges` field has moved one level up, from `revisions` to `patch` itself

Signed-off-by: xphoniex <dj.2dixx@gmail.com>
This commit is contained in:
xphoniex
2023-05-29 12:14:17 +00:00
parent 39874d8d51
commit 824c719313
2 changed files with 29 additions and 13 deletions
+22 -8
View File
@@ -10,30 +10,44 @@ import {
optional,
strictObject,
string,
tuple,
union,
} from "zod";
export type PatchState =
| { status: "draft" }
| { status: "open" }
| { status: "open"; conflicts?: [string, string][] }
| { status: "archived" }
| { status: "merged" };
| { status: "merged"; revision: string; commit: string };
const patchStateSchema = union([
strictObject({ status: literal("draft") }),
strictObject({ status: literal("open") }),
strictObject({ status: literal("archived") }),
strictObject({ status: literal("merged") }),
strictObject({
status: literal("draft"),
}),
strictObject({
status: literal("open"),
conflicts: array(tuple([string(), string()])).optional(),
}),
strictObject({
status: literal("archived"),
}),
strictObject({
status: literal("merged"),
revision: string(),
commit: string(),
}),
]) satisfies ZodSchema<PatchState>;
export interface Merge {
author: { id: string; alias?: string };
revision: string;
commit: string;
timestamp: number;
}
const mergeSchema = strictObject({
author: strictObject({ id: string(), alias: string().optional() }),
revision: string(),
commit: string(),
timestamp: number(),
}) satisfies ZodSchema<Merge>;
@@ -94,7 +108,6 @@ export interface Revision {
refs: string[];
discussions: Comment[];
reviews: Review[];
merges: Merge[];
timestamp: number;
}
@@ -106,7 +119,6 @@ const revisionSchema = strictObject({
refs: array(string()),
discussions: array(commentSchema),
reviews: array(reviewSchema),
merges: array(mergeSchema),
timestamp: number(),
}) satisfies ZodSchema<Revision>;
@@ -118,6 +130,7 @@ export interface Patch {
state: PatchState;
target: string;
tags: string[];
merges: Merge[];
revisions: Revision[];
}
@@ -129,6 +142,7 @@ export const patchSchema = strictObject({
state: patchStateSchema,
target: string(),
tags: array(string()),
merges: array(mergeSchema),
revisions: array(revisionSchema),
}) satisfies ZodSchema<Patch>;
+7 -5
View File
@@ -158,11 +158,13 @@
type: "review",
inner: [rev.id, review.author.id, review],
})),
...rev.merges.map<TimelineMerge>(inner => ({
timestamp: inner.timestamp,
type: "merge",
inner,
})),
...patch.merges
.filter(merge => merge.revision === rev.id)
.map<TimelineMerge>(inner => ({
timestamp: inner.timestamp,
type: "merge",
inner,
})),
...rev.discussions
.filter(comment => !comment.replyTo)
.map<TimelineThread>(thread => ({