Add createPatch method to the project.Client

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2023-07-12 10:58:45 +02:00
parent 3d4e1bbfd9
commit d5857952aa
2 changed files with 48 additions and 3 deletions
+29 -2
View File
@@ -5,7 +5,12 @@ import type {
IssueCreated,
IssueUpdateAction,
} from "./project/issue.js";
import type { Patch, PatchUpdateAction } from "./project/patch.js";
import type {
Patch,
PatchCreate,
PatchCreated,
PatchUpdateAction,
} from "./project/patch.js";
import type { SuccessResponse } from "./shared.js";
import type { ZodSchema } from "zod";
@@ -35,7 +40,11 @@ import {
issuesSchema,
} from "./project/issue.js";
import { patchSchema, patchesSchema } from "./project/patch.js";
import {
patchSchema,
patchesSchema,
patchCreatedSchema,
} from "./project/patch.js";
export interface Project {
id: string;
@@ -469,6 +478,24 @@ export class Client {
);
}
public async createPatch(
id: string,
body: PatchCreate,
authToken: string,
options?: RequestOptions,
): Promise<PatchCreated> {
return this.#fetcher.fetchOk(
{
method: "POST",
path: `projects/${id}/patches`,
headers: { Authorization: `Bearer ${authToken}` },
body,
options,
},
patchCreatedSchema,
);
}
public async updatePatch(
id: string,
patchId: string,
+19 -1
View File
@@ -1,10 +1,11 @@
import type { Comment, ThreadUpdateAction } from "./comment.js";
import type { ZodSchema } from "zod";
import type { ZodSchema, z } from "zod";
import { commentSchema } from "./comment.js";
import {
array,
boolean,
literal,
number,
optional,
@@ -136,3 +137,20 @@ export type PatchUpdateAction =
}
| { type: "merge"; revision: string; commit: string }
| { type: "thread"; revision: string; action: ThreadUpdateAction };
export const patchCreateSchema = object({
title: string(),
description: string(),
target: string(),
oid: string(),
tags: array(string()),
});
export type PatchCreate = z.infer<typeof patchCreateSchema>;
export const patchCreatedSchema = object({
success: boolean(),
id: string(),
});
export type PatchCreated = z.infer<typeof patchCreatedSchema>;