Add issue embeds

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2023-09-27 16:40:49 +02:00
parent 2864a0311b
commit 1ef0f9dfd1
28 changed files with 585 additions and 107 deletions
+7 -2
View File
@@ -94,12 +94,17 @@ export class Fetcher {
): Promise<TypeOf<T>> {
const response = await this.fetch(params);
const responseBody = await response.json();
if (!response.ok) {
let responseBody = await response.text();
try {
responseBody = JSON.parse(responseBody);
} catch (_e: unknown) {
// We keep the original text response body.
}
throw new ResponseError(params.method, response, responseBody);
}
const responseBody = await response.json();
const result = schema.safeParse(responseBody);
if (result.success) {
return result.data;
+1
View File
@@ -372,6 +372,7 @@ export class Client {
title: string;
description: string;
assignees: string[];
embeds: { name: string; content: string }[];
labels: string[];
},
authToken: string,
+4 -10
View File
@@ -1,20 +1,14 @@
import type { ZodSchema } from "zod";
import type { z } from "zod";
import { array, number, object, string, tuple } from "zod";
export interface Comment {
id: string;
author: { id: string; alias?: string };
body: string;
reactions: [string, string][];
timestamp: number;
replyTo: string | null;
}
export type Comment = z.infer<typeof commentSchema>;
export const commentSchema = object({
id: string(),
author: object({ id: string(), alias: string().optional() }),
body: string(),
embeds: array(object({ name: string(), content: string() })),
reactions: array(tuple([string(), string()])),
timestamp: number(),
replyTo: string().nullable(),
}) satisfies ZodSchema<Comment>;
});
+6 -1
View File
@@ -56,7 +56,12 @@ export type IssueUpdateAction =
assignees: string[];
}
| { type: "lifecycle"; state: IssueState }
| { type: "comment"; body: string; replyTo: string }
| {
type: "comment";
body: string;
embeds: { name: string; content: string }[];
replyTo: string;
}
| { type: "comment.edit"; id: string; body: string }
| { type: "comment.redact"; id: string }
| {
+1
View File
@@ -120,6 +120,7 @@ describe("project", () => {
title: "aaa",
description: "bbb",
assignees: [],
embeds: [],
labels: ["bug", "documentation"],
},
sessionId,
+1 -1
View File
@@ -11,7 +11,7 @@ export async function createIssueToBeModified(
) {
const { id } = await api.project.createIssue(
cobRid,
{ title: "aaa", description: "bbb", assignees: [], labels: [] },
{ title: "aaa", description: "bbb", embeds: [], assignees: [], labels: [] },
sessionId,
);