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 +}