This is a temporary fork of ktrysmt/go-bitbucket. It exists to adopt Bitbucket Cloud API changes (deprecated endpoint migration, safer error handling) ahead of upstream. We intend to return to the upstream module once it incorporates these changes.
Bitbucket API v2.0 library for Go.
- Bitbucket API v2.0 https://developer.atlassian.com/bitbucket/api/2/reference/resource/
- Swagger for API v2.0 https://api.bitbucket.org/swagger.json
This fork introduces the following breaking and non-breaking changes relative to ktrysmt/go-bitbucket v0.9.x:
- Constructor signatures changed: All client constructors (
NewBasicAuth,NewOAuthbearerToken,NewOAuthClientCredentials, etc.) now return(*Client, error)instead of*Client. Callers must handle the error. NewOAuthWithCodeandNewOAuthWithRefreshTokenreturn three values:(*Client, string, error).log.Fatalremoved: Alllog.Fatalcalls in constructors have been replaced with returned errors, so the library no longer terminates the calling process on failure.
- Workspace listing: Uses
GET /user/workspacesinstead of the deprecatedGET /workspaces. Response decoding handles theworkspace_accessenvelope from the new endpoint. - Custom CA certificate support: New constructor variants (
NewBasicAuthWithCaCert,NewOAuthbearerTokenWithCaCert, etc.) accept custom CA certificates for Bitbucket Server / Data Center deployments with self-signed certs. - Base URL constructors: New variants (
NewBasicAuthWithBaseUrlStr,NewOAuthbearerTokenWithBaseUrlStr, etc.) accept the API base URL as a parameter instead of relying on theBITBUCKET_API_BASE_URLenvironment variable. PullRequests.List(): Added as the properly named method;Gets()is kept as a backward-compatible alias.PullRequestsMergeStrategytype: New string enum for merge strategy options.- Pipeline variable methods:
GetPipelineVariableandUpdatePipelineVariableadded to the repository interface.
go get github.com/trufflesecurity/go-bitbucketpackage main
import (
"fmt"
"log"
"github.com/trufflesecurity/go-bitbucket"
)
func main() {
c, err := bitbucket.NewBasicAuth("username", "password")
if err != nil {
log.Fatal(err)
}
opt := &bitbucket.PullRequestsOptions{
Owner: "your-team",
RepoSlug: "awesome-project",
SourceBranch: "develop",
DestinationBranch: "master",
Title: "fix bug. #9999",
CloseSourceBranch: true,
}
res, err := c.Repositories.PullRequests.Create(opt)
if err != nil {
log.Fatal(err)
}
fmt.Println(res)
}package main
import (
"fmt"
"log"
"github.com/trufflesecurity/go-bitbucket"
)
func main() {
c, err := bitbucket.NewBasicAuth("username", "password")
if err != nil {
log.Fatal(err)
}
opt := &bitbucket.RepositoryOptions{
Owner: "project_name",
RepoSlug: "repo_name",
Scm: "git",
}
res, err := c.Repositories.Repository.Create(opt)
if err != nil {
log.Fatal(err)
}
fmt.Println(res)
}It does not correspond yet. Because there are many differences between v2.0 and v1.0.
- Bitbucket API v1.0 https://confluence.atlassian.com/bitbucket/version-1-423626337.html
It is officially recommended to use v2.0. But unfortunately Bitbucket Server (formerly: Stash) API is still v1.0. And The API v1.0 covers resources that the v2.0 API and API v2.0 is yet to cover.
It's using go mod.
Set your available user account to Global Env.
export BITBUCKET_TEST_USERNAME=<your_username>
export BITBUCKET_TEST_PASSWORD=<your_password>
export BITBUCKET_TEST_OWNER=<your_repo_owner>
export BITBUCKET_TEST_REPOSLUG=<your_repo_name>
export BITBUCKET_TEST_ACCESS_TOKEN=<your_repo_access_token>And just run;
make testIf you want to test individually;
go test -v ./tests/diff_test.goE2E Integration tests;
make test/e2eUnit tests;
make test/unitMock tests;
make test/mockIndividually;
go test ./mock_tests/repository_mock_test.goFor documented workflow of the go:qmock test structure in /mock_tests/repository_mock_test.go refer to;
- TestMockRepositoryPipelineVariables_List_Success
- TestMockRepositoryPipelineVariables_List_Error
Originally created by ktrysmt. Forked and maintained by TruffleSecurity.