Repository navigation
Add branch listing, creation and deletion to the Bitbucket backend - #221
Conversation
The Bitbucket Cloud backend returned ErrNotSupported for every BranchService method, so `forge branch list`, `branch create` and `branch delete` failed on bitbucket.org. They now use the /refs/branches endpoints. - List follows `next` links and honours Limit, PerPage and Page. Bitbucket rejects a pagelen above 100 with "Invalid pagelen", so the page size is capped there. It only shrinks to Limit when listing from the first page, since a start page is counted in pages of PerPage. - Create needs a commit hash as the target: the API documents the target as a commit hash, preferably a full one. So `from` is looked up as a branch, as the GitHub backend does, and a full commit SHA is used as is. A missing source branch returns ErrNotFound before anything is created. - Delete escapes the branch name into one path segment, the only form in which the refs endpoints accept names containing a slash such as "feature/login". Branch objects don't say whether a branch is the main branch or has restrictions, so Default and Protected stay false, as on GitHub. Tests cover pagination, limits, page sizes, slashed names, creation from a branch and from a commit, error responses and read-only mode, plus a replay of a real api.bitbucket.org branch listing.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Summary
The Bitbucket Cloud backend returned
ErrNotSupportedfor everyBranchServicemethod, soforge branch list,forge branch createandforge branch deletefailed on bitbucket.org. This PR implements them with Bitbucket's/refs/branchesendpoints.How it works
nextlinks and supportsLimit,PerPageandPage. Bitbucket rejects apagelenabove 100 with400 Invalid pagelen, so the page size is capped at 100. The page size shrinks toLimitonly when listing from the first page, because a start page is counted in pages ofPerPage.mainby default. Sofromis looked up as a branch, as the GitHub backend does, and a full commit SHA is used as is. A missing source branch returnsErrNotFoundbefore anything is created.feature/login.Bitbucket's branch objects don't indicate whether a branch is the main branch or has restrictions (restrictions are a separate, admin-only API), so
DefaultandProtectedstay false, as on GitHub.Testing
nextlinks, the limit stopping early, page sizes (including the 100 cap and a start page), not found, creation from a slashed branch and from a full SHA, a missing source branch, a rejected creation, deleting a slashed name, and read-only mode.TestReplayListBranchesreplays a real api.bitbucket.org listing.forge branch listagainst bitbucket.org on a repository with 91 branches (all listed, and-L 5), and paged through the same repository withPerPage: 40(3 pages, 91 branches; withLimit: 45the result stops partway through the second page). Create and delete need an account with write access, so they're covered by the tests and the API reference.go test ./...,go test -race ./bitbucket, thejs/wasmandwasip1/wasmbuilds, andgolangci-lint run(0 issues) all pass locally.Summary by CodeRabbit