From aca662039dbbe04a7f2824e1dfca2eb2bd9af551 Mon Sep 17 00:00:00 2001 From: Nathan Gendron <nato@coderabbit.ai> Date: Tue, 4 Mar 2025 13:23:00 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20Override=20Bitbucke?= =?UTF-8?q?t=20Cloud's=20schema=20to=20create=20new=20branches?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cloud/client.test.ts | 15 ++++++++++++- src/cloud/client.ts | 2 +- src/cloud/index.ts | 1 + src/cloud/interfaces/index.ts | 1 + src/cloud/interfaces/paths.test.ts | 30 +++++++++++++++++++++++++ src/cloud/interfaces/paths.ts | 35 ++++++++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 src/cloud/interfaces/index.ts create mode 100644 src/cloud/interfaces/paths.test.ts create mode 100644 src/cloud/interfaces/paths.ts diff --git a/src/cloud/client.test.ts b/src/cloud/client.test.ts index 374f5dd..19cba27 100644 --- a/src/cloud/client.test.ts +++ b/src/cloud/client.test.ts @@ -1,7 +1,20 @@ import { test } from "vitest" import { createBitbucketCloudClient } from "./client.ts" -test("createBitbucketCloudClient", ({ expect }) => { +test("createBitbucketCloudClient", async ({ expect }) => { const client = createBitbucketCloudClient() expect(client).toBeDefined() + + await client.POST("/repositories/{workspace}/{repo_slug}/refs/branches", { + params: { + path: { + repo_slug: "repo_slug", + workspace: "workspace", + }, + }, + body: { + name: "name", + target: { hash: "hash" }, + }, + }) }) diff --git a/src/cloud/client.ts b/src/cloud/client.ts index 19e8221..b8a87cc 100644 --- a/src/cloud/client.ts +++ b/src/cloud/client.ts @@ -1,6 +1,6 @@ import type { Client, ClientOptions } from "openapi-fetch" import createClient from "openapi-fetch" -import type { paths } from "./openapi/index.ts" +import type { paths } from "./interfaces/paths.ts" /** * Creates an `openapi-fetch` client using {@link createClient}. diff --git a/src/cloud/index.ts b/src/cloud/index.ts index 5a40987..6c74976 100644 --- a/src/cloud/index.ts +++ b/src/cloud/index.ts @@ -1,2 +1,3 @@ export * from "./client.ts" +export type * from "./interfaces/index.ts" export type * as OpenApi from "./openapi/index.ts" diff --git a/src/cloud/interfaces/index.ts b/src/cloud/interfaces/index.ts new file mode 100644 index 0000000..11dcfee --- /dev/null +++ b/src/cloud/interfaces/index.ts @@ -0,0 +1 @@ +export type * from "./paths.ts" diff --git a/src/cloud/interfaces/paths.test.ts b/src/cloud/interfaces/paths.test.ts new file mode 100644 index 0000000..b4e8477 --- /dev/null +++ b/src/cloud/interfaces/paths.test.ts @@ -0,0 +1,30 @@ +import { test } from "vitest" +import { createBitbucketCloudClient } from "../client.js" +import type { CreateBranchRequest } from "./paths.ts" + +async function fetch() { + const response = new Response(JSON.stringify({}), { status: 200 }) + return Promise.resolve(response) +} + +const client = createBitbucketCloudClient({ + baseUrl: "https://api.bitbucket.org/2.0", + fetch, +}) + +test("CreateBranchRequest", async ({ expect }) => { + const example: CreateBranchRequest = { + name: "smf/create-feature", + target: { hash: "default" }, + } + + const { response } = await client.POST( + "/repositories/{workspace}/{repo_slug}/refs/branches", + { + params: { path: { repo_slug: "repo_slug", workspace: "workspace" } }, + body: example, + }, + ) + + expect(response.status).toBe(200) +}) diff --git a/src/cloud/interfaces/paths.ts b/src/cloud/interfaces/paths.ts new file mode 100644 index 0000000..b0d1d74 --- /dev/null +++ b/src/cloud/interfaces/paths.ts @@ -0,0 +1,35 @@ +import type { paths as openapi } from "../openapi/openapi-typescript.ts" + +/** + * Overrides Bitbucket Cloud's OpenAPI schema. + */ +export interface paths + extends Omit<openapi, "/repositories/{workspace}/{repo_slug}/refs/branches"> { + readonly "/repositories/{workspace}/{repo_slug}/refs/branches": Omit< + openapi["/repositories/{workspace}/{repo_slug}/refs/branches"], + "post" + > & { + readonly post: Omit< + openapi["/repositories/{workspace}/{repo_slug}/refs/branches"]["post"], + "requestBody" + > & { + readonly requestBody: { + readonly content: { + readonly "application/json": CreateBranchRequest + } + } + } + } +} + +/** Request to create a branch. */ +export interface CreateBranchRequest { + /** Name of the new branch */ + readonly name: string + /** Where to point the new branch to */ + readonly target: Target +} + +export interface Target { + readonly hash: string +} From 97a59c7cefbf6cb4a381f6a51b0a300bfe373e67 Mon Sep 17 00:00:00 2001 From: Nathan Gendron <nato@coderabbit.ai> Date: Tue, 4 Mar 2025 13:26:00 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=A5=20Remove=20test=20accidentally?= =?UTF-8?q?=20left=20in?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cloud/client.test.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/cloud/client.test.ts b/src/cloud/client.test.ts index 19cba27..374f5dd 100644 --- a/src/cloud/client.test.ts +++ b/src/cloud/client.test.ts @@ -1,20 +1,7 @@ import { test } from "vitest" import { createBitbucketCloudClient } from "./client.ts" -test("createBitbucketCloudClient", async ({ expect }) => { +test("createBitbucketCloudClient", ({ expect }) => { const client = createBitbucketCloudClient() expect(client).toBeDefined() - - await client.POST("/repositories/{workspace}/{repo_slug}/refs/branches", { - params: { - path: { - repo_slug: "repo_slug", - workspace: "workspace", - }, - }, - body: { - name: "name", - target: { hash: "hash" }, - }, - }) })