Skip to content

Commit

Permalink
Add repository.DeleteBranch (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
chmouel authored Oct 17, 2021
1 parent c342cba commit fd48ae5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ type RepositoryBranchCreationOptions struct {
Target RepositoryBranchTarget `json:"target"`
}

type RepositoryBranchDeleteOptions struct {
Owner string `json:"owner"`
RepoSlug string `json:"repo_slug"`
RepoUUID string `json:"uuid"`
RefName string `json:"name"`
RefUUID string `json:uuid`
}

type RepositoryBranchTarget struct {
Hash string `json:"hash"`
}
Expand Down
15 changes: 15 additions & 0 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,21 @@ func (r *Repository) GetBranch(rbo *RepositoryBranchOptions) (*RepositoryBranch,
return decodeRepositoryBranch(bodyString)
}

// DeleteBranch https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/refs/branches/%7Bname%7D#delete
func (r *Repository) DeleteBranch(rbo *RepositoryBranchDeleteOptions) error {
repo := rbo.RepoSlug
if rbo.RepoUUID != "" {
repo = rbo.RepoUUID
}
ref := rbo.RefName
if rbo.RefUUID != "" {
ref = rbo.RefUUID
}
urlStr := r.c.requestUrl("/repositories/%s/%s/refs/branches/%s", rbo.Owner, repo, ref)
_, err := r.c.execute("DELETE", urlStr, "")
return err
}

func (r *Repository) CreateBranch(rbo *RepositoryBranchCreationOptions) (*RepositoryBranch, error) {
urlStr := r.c.requestUrl("/repositories/%s/%s/refs/branches", rbo.Owner, rbo.RepoSlug)
data := r.buildBranchBody(rbo)
Expand Down

0 comments on commit fd48ae5

Please sign in to comment.