From 26db64679fd106db54bb6b7478c07b24fbc0c122 Mon Sep 17 00:00:00 2001 From: Nato Boram Date: Tue, 4 Mar 2025 14:22:46 -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=20(#41)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🏷️ Override Bitbucket Cloud's schema to create new branches * 🔥 Remove test accidentally left in --- 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 ++++++++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 1 deletion(-) 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.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 { + 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 677da9ed9c90807d33ea4dd1e50d02bfd4aa40ee Mon Sep 17 00:00:00 2001 From: Nathan Gendron Date: Tue, 4 Mar 2025 14:32:18 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=96=20v1.1.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f82e099..79d6d45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@coderabbitai/bitbucket", - "version": "1.1.2", + "version": "1.1.3", "description": "CodeRabbit's TypeScript API client for connecting to Bitbucket Cloud and Bitbucket Data Center", "keywords": [ "bitbucket-api-v1",