-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
π WalkthroughWalkthroughThe pull request restructures the module organisation related to Bitbucket Cloudβs API types. It updates the import path for the Changes
Sequence Diagram(s)sequenceDiagram
participant Test
participant Client
participant API
Test->>Client: Invoke CreateBranchRequest
Client->>API: POST /repositories/{workspace}/{repo_slug}/refs/branches with new payload structure
API-->>Client: Return HTTP 200 response
Client-->>Test: Deliver successful response
Possibly Related PRs
Suggested Labels
β¨ Finishing Touches
πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
π§Ή Nitpick comments (3)
src/cloud/interfaces/paths.test.ts (2)
5-8
: Consider enhancing the mock implementation.The mock fetch function currently returns an empty object with a 200 status. For better test coverage, consider returning a realistic response body that matches Bitbucket's actual API response structure.
- async function fetch() { - const response = new Response(JSON.stringify({}), { status: 200 }) - return Promise.resolve(response) - } + async function fetch() { + const response = new Response(JSON.stringify({ + name: "smf/create-feature", + target: { + hash: "abc123def456", + type: "commit" + }, + links: { + self: { href: "https://api.bitbucket.org/2.0/repositories/workspace/repo_slug/refs/branches/smf/create-feature" } + } + }), { status: 201 }) + return Promise.resolve(response) + }
15-30
: Test case looks good but could be expanded.The test case appropriately validates the basic functionality of creating a branch using the custom request type. However, consider expanding test coverage:
- Verify response status 201 (created) instead of 200
- Add expectations for the request payload format
- Test different branch name patterns
- Include error case testing
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) + expect(response.status).toBe(201) // Bitbucket typically returns 201 for resource creation + + // Additional test cases could be added here }) + test("CreateBranchRequest with validation errors", async ({ expect }) => { + // Test with invalid branch name or target to verify error handling + })src/cloud/interfaces/paths.ts (1)
33-35
: Consider adding type information to Target interface.The Target interface could benefit from a more specific type definition for the hash property, potentially distinguishing between commit hashes and branch/tag references.
export interface Target { - readonly hash: string + /** + * Commit hash, branch name, or tag to point the new branch at. + * For example: "master", "develop", "a1b2c3d4e5f6", etc. + */ + readonly hash: string + /** Optional type property that Bitbucket sometimes expects */ + readonly type?: "commit" }
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (5)
src/cloud/client.ts
(1 hunks)src/cloud/index.ts
(1 hunks)src/cloud/interfaces/index.ts
(1 hunks)src/cloud/interfaces/paths.test.ts
(1 hunks)src/cloud/interfaces/paths.ts
(1 hunks)
β Files skipped from review due to trivial changes (2)
- src/cloud/interfaces/index.ts
- src/cloud/client.ts
π Additional comments (4)
src/cloud/index.ts (1)
2-2
: Excellent addition to expose the interface types.The additional export statement makes types from the interfaces module accessible to consumers, which is essential for exposing the newly defined branch creation types.
src/cloud/interfaces/paths.ts (3)
3-5
: Good documentation on the purpose of this override.The comment clearly states the purpose of overriding Bitbucket Cloud's OpenAPI schema.
6-23
: Well-structured type extension for schema override.The approach to extend and modify the OpenAPI schema is clean and type-safe. The code properly:
- Extends the original schema
- Omits the specific path to override
- Reconstructs the path with the modified request body structure
This implementation maintains type safety while adapting to Bitbucket's actual API requirements.
25-31
: Clear and well-documented interface for branch creation.The
CreateBranchRequest
interface is appropriately documented with comments explaining each field's purpose. The structure matches Bitbucket's API requirements for branch creation.
π Description
Bitbucket Cloud's documentation is as odd with its schema.
Overriding is the simplest way to get over it.
"/repositories/{workspace}/{repo_slug}/refs/branches"
thepost
'srequestBody
with a type taken straight from its docs.π References
Summary by CodeRabbit
New Features
Tests