Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏷️ Override Bitbucket Cloud's schema to create new branches #41

Merged
merged 2 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cloud/client.ts
Original file line number Diff line number Diff line change
@@ -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}.
Expand Down
1 change: 1 addition & 0 deletions src/cloud/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./client.ts"
export type * from "./interfaces/index.ts"
export type * as OpenApi from "./openapi/index.ts"
1 change: 1 addition & 0 deletions src/cloud/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type * from "./paths.ts"
30 changes: 30 additions & 0 deletions src/cloud/interfaces/paths.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
35 changes: 35 additions & 0 deletions src/cloud/interfaces/paths.ts
Original file line number Diff line number Diff line change
@@ -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
}