From d5857952aa200ae64ae0b9c95667a7798ff81d99 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Wed, 12 Jul 2023 10:49:59 +0200 Subject: [PATCH] Add `createPatch` method to the `project.Client` Signed-off-by: Sebastian Martinez --- httpd-client/lib/project.ts | 31 +++++++++++++++++++++++++++++-- httpd-client/lib/project/patch.ts | 20 +++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/httpd-client/lib/project.ts b/httpd-client/lib/project.ts index cccafc3ab..840f6f50f 100644 --- a/httpd-client/lib/project.ts +++ b/httpd-client/lib/project.ts @@ -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 { + return this.#fetcher.fetchOk( + { + method: "POST", + path: `projects/${id}/patches`, + headers: { Authorization: `Bearer ${authToken}` }, + body, + options, + }, + patchCreatedSchema, + ); + } + public async updatePatch( id: string, patchId: string, diff --git a/httpd-client/lib/project/patch.ts b/httpd-client/lib/project/patch.ts index 1c09825aa..e3bbe4a45 100644 --- a/httpd-client/lib/project/patch.ts +++ b/httpd-client/lib/project/patch.ts @@ -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; + +export const patchCreatedSchema = object({ + success: boolean(), + id: string(), +}); + +export type PatchCreated = z.infer;