Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add `createPatch` method to the `project.Client`
Sebastian Martinez committed 2 years ago
commit d5857952aa200ae64ae0b9c95667a7798ff81d99
parent 3d4e1bbfd977a45e26ae35e0cf8cd27581b40e6f
2 files changed +48 -3
modified 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<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,
modified 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<typeof patchCreateSchema>;
+

+
export const patchCreatedSchema = object({
+
  success: boolean(),
+
  id: string(),
+
});
+

+
export type PatchCreated = z.infer<typeof patchCreatedSchema>;