Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,14 @@ type RepositoryBlobOptions struct {
}

type RepositoryBranchOptions struct {
Owner string `json:"owner"`
RepoSlug string `json:"repo_slug"`
Query string `json:"q"`
Sort string `json:"sort"`
PageNum int `json:"page"`
Pagelen int `json:"pagelen"`
MaxDepth int `json:"max_depth"`
Owner string `json:"owner"`
RepoSlug string `json:"repo_slug"`
Query string `json:"q"`
Sort string `json:"sort"`
PageNum int `json:"page"`
Pagelen int `json:"pagelen"`
MaxDepth int `json:"max_depth"`
BranchName string `json:"branch_name"`
}

type RepositoryTagOptions struct {
Expand Down
43 changes: 40 additions & 3 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bitbucket

import (
"encoding/json"
"errors"
"io/ioutil"
"net/url"
"os"
Expand Down Expand Up @@ -214,8 +215,29 @@ func (r *Repository) ListBranches(rbo *RepositoryBranchOptions) (*RepositoryBran
if err != nil {
return nil, err
}
bodyBytes, err := ioutil.ReadAll(response)
if err != nil {
return nil, err
}
bodyString := string(bodyBytes)
return decodeRepositoryBranches(bodyString)
}

return decodeRepositoryBranches(response)
func (r *Repository) GetBranch(rbo *RepositoryBranchOptions) (*RepositoryBranch, error) {
if rbo.BranchName == "" {
return nil, errors.New("Error: Branch Name is empty")
}
urlStr := r.c.requestUrl("/repositories/%s/%s/refs/branches/%s", rbo.Owner, rbo.RepoSlug, rbo.BranchName)
response, err := r.c.executeRaw("GET", urlStr, "")
if err != nil {
return nil, err
}
bodyBytes, err := ioutil.ReadAll(response)
if err != nil {
return nil, err
}
bodyString := string(bodyBytes)
return decodeRepositoryBranch(bodyString)
}

func (r *Repository) ListTags(rbo *RepositoryTagOptions) (*RepositoryTags, error) {
Expand Down Expand Up @@ -486,10 +508,10 @@ func decodeRepositoryFiles(repoResponse interface{}) ([]RepositoryFile, error) {
return *repositoryFiles, nil
}

func decodeRepositoryBranches(branchResponse interface{}) (*RepositoryBranches, error) {
func decodeRepositoryBranches(branchResponseStr string) (*RepositoryBranches, error) {

var branchResponseMap map[string]interface{}
err := json.Unmarshal(branchResponse.([]byte), &branchResponseMap)
err := json.Unmarshal([]byte(branchResponseStr), &branchResponseMap)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -538,6 +560,21 @@ func decodeRepositoryBranches(branchResponse interface{}) (*RepositoryBranches,
return &repositoryBranches, nil
}

func decodeRepositoryBranch(branchResponseStr string) (*RepositoryBranch, error) {

var branchResponseMap map[string]interface{}
err := json.Unmarshal([]byte(branchResponseStr), &branchResponseMap)
if err != nil {
return nil, err
}
var repositoryBranch RepositoryBranch
err = mapstructure.Decode(branchResponseMap, &repositoryBranch)
if err != nil {
return nil, err
}
return &repositoryBranch, nil
}

func decodeRepositoryTags(tagResponse interface{}) (*RepositoryTags, error) {

var tagResponseMap map[string]interface{}
Expand Down