Skip to content
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
6 changes: 6 additions & 0 deletions bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type repository interface {
ListFiles(opt RepositoryFilesOptions) (*[]RepositoryFile, error)
GetFileBlob(opt RepositoryBlobOptions) (*RepositoryBlob, error)
ListBranches(opt RepositoryBranchOptions) (*RepositoryBranches, error)
BranchingModel(opt RepositoryBranchingModelOptions) (*BranchingModel, error)
}

type repositories interface {
Expand Down Expand Up @@ -236,6 +237,11 @@ type RepositoryPipelineBuildNumberOptions struct {
Next int `json:"next"`
}

type RepositoryBranchingModelOptions struct {
Owner string `json:"owner"`
RepoSlug string `json:"repo_slug"`
}

type DownloadsOptions struct {
Owner string `json:"owner"`
RepoSlug string `json:"repo_slug"`
Expand Down
42 changes: 42 additions & 0 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ type PipelineBuildNumber struct {
Next int
}

type BranchingModel struct {
Type string
Branch_Types []BranchType
Development BranchDevelopment
}

type BranchType struct {
Kind string
Prefix string
}

type BranchDevelopment struct {
Name string
Branch RepositoryBranch
Use_Mainbranch bool
}

func (r *Repository) Create(ro *RepositoryOptions) (*Repository, error) {
data := r.buildRepositoryBody(ro)
urlStr := r.c.requestUrl("/repositories/%s/%s", ro.Owner, ro.RepoSlug)
Expand Down Expand Up @@ -276,6 +293,15 @@ func (r *Repository) UpdatePipelineBuildNumber(rpbno *RepositoryPipelineBuildNum
return decodePipelineBuildNumberRepository(response)
}

func (r *Repository) BranchingModel(rbmo *RepositoryBranchingModelOptions) (*BranchingModel, error) {
urlStr := r.c.requestUrl("/repositories/%s/%s/branching-model", rbmo.Owner, rbmo.RepoSlug)
response, err := r.c.execute("GET", urlStr, "")
if err != nil {
return nil, err
}
return decodeBranchingModel(response)
}

func (r *Repository) buildJsonBody(body map[string]interface{}) string {

data, err := json.Marshal(body)
Expand Down Expand Up @@ -570,6 +596,22 @@ func decodePipelineBuildNumberRepository(repoResponse interface{}) (*PipelineBui
return pipelineBuildNumber, nil
}

func decodeBranchingModel(branchingModelResponse interface{}) (*BranchingModel, error) {
branchingModelMap := branchingModelResponse.(map[string]interface{})

if branchingModelMap["type"] == "error" {
return nil, DecodeError(branchingModelMap)
}

var branchingModel = new(BranchingModel)
err := mapstructure.Decode(branchingModelMap, branchingModel)
if err != nil {
return nil, err
}

return branchingModel, nil
}

func (rf RepositoryFile) String() string {
return rf.Path
}
Expand Down