Skip to content

Commit aa0db3e

Browse files
authored
add repo update (#128)
* format code * add repo update * use uuid when uuid provided on repo delete
1 parent dcb172e commit aa0db3e

File tree

2 files changed

+47
-25
lines changed

2 files changed

+47
-25
lines changed

bitbucket.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ type RepositoriesOptions struct {
115115
}
116116

117117
type RepositoryOptions struct {
118+
Uuid string `json:"uuid"`
118119
Owner string `json:"owner"`
119120
RepoSlug string `json:"repo_slug"`
120121
Scm string `json:"scm"`
@@ -358,12 +359,12 @@ func (e RepositoryEnvironmentTypeOption) String() string {
358359
}
359360

360361
type RepositoryEnvironmentOptions struct {
361-
Owner string `json:"owner"`
362-
RepoSlug string `json:"repo_slug"`
363-
Uuid string `json:"uuid"`
364-
Name string `json:"name"`
362+
Owner string `json:"owner"`
363+
RepoSlug string `json:"repo_slug"`
364+
Uuid string `json:"uuid"`
365+
Name string `json:"name"`
365366
EnvironmentType RepositoryEnvironmentTypeOption `json:"environment_type"`
366-
Rank int `json:"rank"`
367+
Rank int `json:"rank"`
367368
}
368369

369370
type RepositoryEnvironmentDeleteOptions struct {
@@ -373,29 +374,29 @@ type RepositoryEnvironmentDeleteOptions struct {
373374
}
374375

375376
type RepositoryDeploymentVariablesOptions struct {
376-
Owner string `json:"owner"`
377-
RepoSlug string `json:"repo_slug"`
377+
Owner string `json:"owner"`
378+
RepoSlug string `json:"repo_slug"`
378379
Environment *Environment `json:"environment"`
379-
Query string `json:"q"`
380-
Sort string `json:"sort"`
381-
PageNum int `json:"page"`
382-
Pagelen int `json:"pagelen"`
383-
MaxDepth int `json:"max_depth"`
380+
Query string `json:"q"`
381+
Sort string `json:"sort"`
382+
PageNum int `json:"page"`
383+
Pagelen int `json:"pagelen"`
384+
MaxDepth int `json:"max_depth"`
384385
}
385386

386387
type RepositoryDeploymentVariableOptions struct {
387-
Owner string `json:"owner"`
388-
RepoSlug string `json:"repo_slug"`
388+
Owner string `json:"owner"`
389+
RepoSlug string `json:"repo_slug"`
389390
Environment *Environment `json:"environment"`
390-
Uuid string `json:"uuid"`
391-
Key string `json:"key"`
392-
Value string `json:"value"`
393-
Secured bool `json:"secured"`
391+
Uuid string `json:"uuid"`
392+
Key string `json:"key"`
393+
Value string `json:"value"`
394+
Secured bool `json:"secured"`
394395
}
395396

396397
type RepositoryDeploymentVariableDeleteOptions struct {
397-
Owner string `json:"owner"`
398-
RepoSlug string `json:"repo_slug"`
398+
Owner string `json:"owner"`
399+
RepoSlug string `json:"repo_slug"`
399400
Environment *Environment `json:"environment"`
400-
Uuid string `json:"uuid"`
401+
Uuid string `json:"uuid"`
401402
}

repository.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,26 @@ func (r *Repository) CreateTag(rbo *RepositoryTagCreationOptions) (*RepositoryTa
372372
return decodeRepositoryTagCreated(bodyString)
373373
}
374374

375+
func (r *Repository) Update(ro *RepositoryOptions) (*Repository, error) {
376+
data := r.buildRepositoryBody(ro)
377+
key := ro.RepoSlug
378+
if ro.Uuid != "" {
379+
key = ro.Uuid
380+
}
381+
urlStr := r.c.requestUrl("/repositories/%s/%s", ro.Owner, key)
382+
response, err := r.c.execute("PUT", urlStr, data)
383+
if err != nil {
384+
return nil, err
385+
}
386+
return decodeRepository(response)
387+
}
388+
375389
func (r *Repository) Delete(ro *RepositoryOptions) (interface{}, error) {
376-
urlStr := r.c.requestUrl("/repositories/%s/%s", ro.Owner, ro.RepoSlug)
390+
key := ro.RepoSlug
391+
if ro.Uuid != "" {
392+
key = ro.Uuid
393+
}
394+
urlStr := r.c.requestUrl("/repositories/%s/%s", ro.Owner, key)
377395
return r.c.execute("DELETE", urlStr, "")
378396
}
379397

@@ -618,12 +636,15 @@ func (r *Repository) buildRepositoryBody(ro *RepositoryOptions) string {
618636

619637
body := map[string]interface{}{}
620638

639+
if ro.Uuid != "" {
640+
body["uuid"] = ro.Uuid
641+
}
642+
if ro.RepoSlug != "" {
643+
body["name"] = ro.RepoSlug
644+
}
621645
if ro.Scm != "" {
622646
body["scm"] = ro.Scm
623647
}
624-
//if ro.Scm != "" {
625-
// body["name"] = ro.Name
626-
//}
627648
if ro.IsPrivate != "" {
628649
body["is_private"] = strings.ToLower(strings.TrimSpace(ro.IsPrivate)) != "false"
629650
}

0 commit comments

Comments
 (0)