Skip to content

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

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

Merged
merged 2 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
🏷️ Override Bitbucket Cloud's schema to create new branches
  • Loading branch information
NatoBoram committed Mar 4, 2025
commit aca662039dbbe04a7f2824e1dfca2eb2bd9af551
15 changes: 14 additions & 1 deletion src/cloud/client.test.ts
Original file line number Diff line number Diff line change
@@ -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", {

Check failure on line 8 in src/cloud/client.test.ts

View workflow job for this annotation

GitHub Actions / test

src/cloud/client.test.ts > createBitbucketCloudClient

TypeError: Failed to parse URL from /repositories/workspace/repo_slug/refs/branches ❯ coreFetch node_modules/.pnpm/openapi-fetch@0.13.4/node_modules/openapi-fetch/dist/index.js:97:19 ❯ Object.POST node_modules/.pnpm/openapi-fetch@0.13.4/node_modules/openapi-fetch/dist/index.js:243:14 ❯ src/cloud/client.test.ts:8:15 Caused by: Caused by: TypeError: Invalid URL ❯ coreFetch node_modules/.pnpm/openapi-fetch@0.13.4/node_modules/openapi-fetch/dist/index.js:97:19 ❯ Object.POST node_modules/.pnpm/openapi-fetch@0.13.4/node_modules/openapi-fetch/dist/index.js:243:14 ❯ src/cloud/client.test.ts:8:15 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: *** code: 'ERR_INVALID_URL', input: '/repositories/workspace/repo_slug/refs/branches' ***
params: {
path: {
repo_slug: "repo_slug",
workspace: "workspace",
},
},
body: {
name: "name",
target: { hash: "hash" },
},
})
})
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
}
Loading