mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-03 10:40:30 +08:00
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:
@@ -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>;
|
||||
|
||||
|
||||
@@ -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 => ({
|
||||
|
||||
Reference in New Issue
Block a user