diff --git a/bitbucket.go b/bitbucket.go index 005c433..241330d 100644 --- a/bitbucket.go +++ b/bitbucket.go @@ -35,6 +35,7 @@ type repository interface { UpdatePipelineConfig(opt RepositoryPipelineOptions) (*Pipeline, error) AddPipelineVariable(opt RepositoryPipelineVariableOptions) (*PipelineVariable, error) AddPipelineKeyPair(opt RepositoryPipelineKeyPairOptions) (*PipelineKeyPair, error) + UpdatePipelineBuildNumber(opt RepositoryPipelineBuildNumberOptions) (*PipelineBuildNumber, error) ListFiles(opt RepositoryFilesOptions) (*[]RepositoryFile, error) GetFileBlob(opt RepositoryBlobOptions) (*RepositoryBlob, error) ListBranches(opt RepositoryBranchOptions) (*RepositoryBranches, error) @@ -229,6 +230,12 @@ type RepositoryPipelineKeyPairOptions struct { PublicKey string `json:"public_key"` } +type RepositoryPipelineBuildNumberOptions struct { + Owner string `json:"owner"` + RepoSlug string `json:"repo_slug"` + Next int `json:"next"` +} + type DownloadsOptions struct { Owner string `json:"owner"` RepoSlug string `json:"repo_slug"` diff --git a/repository.go b/repository.go index 9a5f8cd..5960d06 100644 --- a/repository.go +++ b/repository.go @@ -100,6 +100,11 @@ type PipelineKeyPair struct { PrivateKey string } +type PipelineBuildNumber struct { + Type string + Next int +} + func (r *Repository) Create(ro *RepositoryOptions) (*Repository, error) { data := r.buildRepositoryBody(ro) urlStr := r.c.requestUrl("/repositories/%s/%s", ro.Owner, ro.RepoSlug) @@ -259,6 +264,18 @@ func (r *Repository) AddPipelineKeyPair(rpkpo *RepositoryPipelineKeyPairOptions) return decodePipelineKeyPairRepository(response) } +func (r *Repository) UpdatePipelineBuildNumber(rpbno *RepositoryPipelineBuildNumberOptions) (*PipelineBuildNumber, error) { + data := r.buildPipelineBuildNumberBody(rpbno) + urlStr := r.c.requestUrl("/repositories/%s/%s/pipelines_config/build_number", rpbno.Owner, rpbno.RepoSlug) + + response, err := r.c.execute("PUT", urlStr, data) + if err != nil { + return nil, err + } + + return decodePipelineBuildNumberRepository(response) +} + func (r *Repository) buildJsonBody(body map[string]interface{}) string { data, err := json.Marshal(body) @@ -344,6 +361,15 @@ func (r *Repository) buildPipelineKeyPairBody(rpkpo *RepositoryPipelineKeyPairOp return r.buildJsonBody(body) } +func (r *Repository) buildPipelineBuildNumberBody(rpbno *RepositoryPipelineBuildNumberOptions) string { + + body := map[string]interface{}{} + + body["next"] = rpbno.Next + + return r.buildJsonBody(body) +} + func decodeRepository(repoResponse interface{}) (*Repository, error) { repoMap := repoResponse.(map[string]interface{}) @@ -528,6 +554,22 @@ func decodePipelineKeyPairRepository(repoResponse interface{}) (*PipelineKeyPair return pipelineKeyPair, nil } +func decodePipelineBuildNumberRepository(repoResponse interface{}) (*PipelineBuildNumber, error) { + repoMap := repoResponse.(map[string]interface{}) + + if repoMap["type"] == "error" { + return nil, DecodeError(repoMap) + } + + var pipelineBuildNumber = new(PipelineBuildNumber) + err := mapstructure.Decode(repoMap, pipelineBuildNumber) + if err != nil { + return nil, err + } + + return pipelineBuildNumber, nil +} + func (rf RepositoryFile) String() string { return rf.Path }