Skip to content

Commit 470011f

Browse files
authored
Add repository branching model support (#85)
1 parent e16430a commit 470011f

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

bitbucket.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type repository interface {
3939
ListFiles(opt RepositoryFilesOptions) (*[]RepositoryFile, error)
4040
GetFileBlob(opt RepositoryBlobOptions) (*RepositoryBlob, error)
4141
ListBranches(opt RepositoryBranchOptions) (*RepositoryBranches, error)
42+
BranchingModel(opt RepositoryBranchingModelOptions) (*BranchingModel, error)
4243
}
4344

4445
type repositories interface {
@@ -236,6 +237,11 @@ type RepositoryPipelineBuildNumberOptions struct {
236237
Next int `json:"next"`
237238
}
238239

240+
type RepositoryBranchingModelOptions struct {
241+
Owner string `json:"owner"`
242+
RepoSlug string `json:"repo_slug"`
243+
}
244+
239245
type DownloadsOptions struct {
240246
Owner string `json:"owner"`
241247
RepoSlug string `json:"repo_slug"`

repository.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,23 @@ type PipelineBuildNumber struct {
105105
Next int
106106
}
107107

108+
type BranchingModel struct {
109+
Type string
110+
Branch_Types []BranchType
111+
Development BranchDevelopment
112+
}
113+
114+
type BranchType struct {
115+
Kind string
116+
Prefix string
117+
}
118+
119+
type BranchDevelopment struct {
120+
Name string
121+
Branch RepositoryBranch
122+
Use_Mainbranch bool
123+
}
124+
108125
func (r *Repository) Create(ro *RepositoryOptions) (*Repository, error) {
109126
data := r.buildRepositoryBody(ro)
110127
urlStr := r.c.requestUrl("/repositories/%s/%s", ro.Owner, ro.RepoSlug)
@@ -276,6 +293,15 @@ func (r *Repository) UpdatePipelineBuildNumber(rpbno *RepositoryPipelineBuildNum
276293
return decodePipelineBuildNumberRepository(response)
277294
}
278295

296+
func (r *Repository) BranchingModel(rbmo *RepositoryBranchingModelOptions) (*BranchingModel, error) {
297+
urlStr := r.c.requestUrl("/repositories/%s/%s/branching-model", rbmo.Owner, rbmo.RepoSlug)
298+
response, err := r.c.execute("GET", urlStr, "")
299+
if err != nil {
300+
return nil, err
301+
}
302+
return decodeBranchingModel(response)
303+
}
304+
279305
func (r *Repository) buildJsonBody(body map[string]interface{}) string {
280306

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

599+
func decodeBranchingModel(branchingModelResponse interface{}) (*BranchingModel, error) {
600+
branchingModelMap := branchingModelResponse.(map[string]interface{})
601+
602+
if branchingModelMap["type"] == "error" {
603+
return nil, DecodeError(branchingModelMap)
604+
}
605+
606+
var branchingModel = new(BranchingModel)
607+
err := mapstructure.Decode(branchingModelMap, branchingModel)
608+
if err != nil {
609+
return nil, err
610+
}
611+
612+
return branchingModel, nil
613+
}
614+
573615
func (rf RepositoryFile) String() string {
574616
return rf.Path
575617
}

0 commit comments

Comments
 (0)