Skip to content

Commit 06d419f

Browse files
panychekktrysmt
authored andcommitted
Allow updating the Pipelines build number (#81)
1 parent 08ab101 commit 06d419f

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

bitbucket.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type repository interface {
3535
UpdatePipelineConfig(opt RepositoryPipelineOptions) (*Pipeline, error)
3636
AddPipelineVariable(opt RepositoryPipelineVariableOptions) (*PipelineVariable, error)
3737
AddPipelineKeyPair(opt RepositoryPipelineKeyPairOptions) (*PipelineKeyPair, error)
38+
UpdatePipelineBuildNumber(opt RepositoryPipelineBuildNumberOptions) (*PipelineBuildNumber, error)
3839
ListFiles(opt RepositoryFilesOptions) (*[]RepositoryFile, error)
3940
GetFileBlob(opt RepositoryBlobOptions) (*RepositoryBlob, error)
4041
ListBranches(opt RepositoryBranchOptions) (*RepositoryBranches, error)
@@ -229,6 +230,12 @@ type RepositoryPipelineKeyPairOptions struct {
229230
PublicKey string `json:"public_key"`
230231
}
231232

233+
type RepositoryPipelineBuildNumberOptions struct {
234+
Owner string `json:"owner"`
235+
RepoSlug string `json:"repo_slug"`
236+
Next int `json:"next"`
237+
}
238+
232239
type DownloadsOptions struct {
233240
Owner string `json:"owner"`
234241
RepoSlug string `json:"repo_slug"`

repository.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ type PipelineKeyPair struct {
100100
PrivateKey string
101101
}
102102

103+
type PipelineBuildNumber struct {
104+
Type string
105+
Next int
106+
}
107+
103108
func (r *Repository) Create(ro *RepositoryOptions) (*Repository, error) {
104109
data := r.buildRepositoryBody(ro)
105110
urlStr := r.c.requestUrl("/repositories/%s/%s", ro.Owner, ro.RepoSlug)
@@ -259,6 +264,18 @@ func (r *Repository) AddPipelineKeyPair(rpkpo *RepositoryPipelineKeyPairOptions)
259264
return decodePipelineKeyPairRepository(response)
260265
}
261266

267+
func (r *Repository) UpdatePipelineBuildNumber(rpbno *RepositoryPipelineBuildNumberOptions) (*PipelineBuildNumber, error) {
268+
data := r.buildPipelineBuildNumberBody(rpbno)
269+
urlStr := r.c.requestUrl("/repositories/%s/%s/pipelines_config/build_number", rpbno.Owner, rpbno.RepoSlug)
270+
271+
response, err := r.c.execute("PUT", urlStr, data)
272+
if err != nil {
273+
return nil, err
274+
}
275+
276+
return decodePipelineBuildNumberRepository(response)
277+
}
278+
262279
func (r *Repository) buildJsonBody(body map[string]interface{}) string {
263280

264281
data, err := json.Marshal(body)
@@ -344,6 +361,15 @@ func (r *Repository) buildPipelineKeyPairBody(rpkpo *RepositoryPipelineKeyPairOp
344361
return r.buildJsonBody(body)
345362
}
346363

364+
func (r *Repository) buildPipelineBuildNumberBody(rpbno *RepositoryPipelineBuildNumberOptions) string {
365+
366+
body := map[string]interface{}{}
367+
368+
body["next"] = rpbno.Next
369+
370+
return r.buildJsonBody(body)
371+
}
372+
347373
func decodeRepository(repoResponse interface{}) (*Repository, error) {
348374
repoMap := repoResponse.(map[string]interface{})
349375

@@ -528,6 +554,22 @@ func decodePipelineKeyPairRepository(repoResponse interface{}) (*PipelineKeyPair
528554
return pipelineKeyPair, nil
529555
}
530556

557+
func decodePipelineBuildNumberRepository(repoResponse interface{}) (*PipelineBuildNumber, error) {
558+
repoMap := repoResponse.(map[string]interface{})
559+
560+
if repoMap["type"] == "error" {
561+
return nil, DecodeError(repoMap)
562+
}
563+
564+
var pipelineBuildNumber = new(PipelineBuildNumber)
565+
err := mapstructure.Decode(repoMap, pipelineBuildNumber)
566+
if err != nil {
567+
return nil, err
568+
}
569+
570+
return pipelineBuildNumber, nil
571+
}
572+
531573
func (rf RepositoryFile) String() string {
532574
return rf.Path
533575
}

0 commit comments

Comments
 (0)