Skip to content

Commit 6df1ade

Browse files
sffortytwoktrysmt
authored andcommitted
Added support for max_depth (#73)
1 parent 0561927 commit 6df1ade

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

bitbucket.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ type RepositoryBranchOptions struct {
138138
Sort string `json:"sort"`
139139
PageNum int `json:"page"`
140140
Pagelen int `json:"pagelen"`
141+
MaxDepth int `json:"max_depth"`
141142
}
142143

143144
type PullRequestsOptions struct {
@@ -238,5 +239,6 @@ type DownloadsOptions struct {
238239
type PageRes struct {
239240
Page int32 `json:"page"`
240241
PageLen int32 `json:"pagelen"`
242+
MaxDepth int32 `json:"max_depth"`
241243
Size int32 `json:"size"`
242244
}

client.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
)
2424

2525
const DEFAULT_PAGE_LENGTH = 10
26+
const DEFAULT_MAX_DEPTH = 1
2627

2728
type Client struct {
2829
Auth *auth
@@ -31,6 +32,7 @@ type Client struct {
3132
Teams teams
3233
Repositories *Repositories
3334
Pagelen uint64
35+
MaxDepth uint64
3436

3537
HttpClient *http.Client
3638
}
@@ -122,7 +124,7 @@ func NewBasicAuth(u, p string) *Client {
122124
}
123125

124126
func injectClient(a *auth) *Client {
125-
c := &Client{Auth: a, Pagelen: DEFAULT_PAGE_LENGTH}
127+
c := &Client{Auth: a, Pagelen: DEFAULT_PAGE_LENGTH, MaxDepth: DEFAULT_MAX_DEPTH}
126128
c.Repositories = &Repositories{
127129
c: c,
128130
PullRequests: &PullRequests{c: c},
@@ -169,6 +171,17 @@ func (c *Client) execute(method string, urlStr string, text string) (interface{}
169171
urlObj.RawQuery = q.Encode()
170172
urlStr = urlObj.String()
171173
}
174+
175+
if c.MaxDepth != DEFAULT_MAX_DEPTH {
176+
urlObj, err := url.Parse(urlStr)
177+
if err != nil {
178+
return nil, err
179+
}
180+
q := urlObj.Query()
181+
q.Set("max_depth", strconv.FormatUint(c.MaxDepth, DEC_RADIX))
182+
urlObj.RawQuery = q.Encode()
183+
urlStr = urlObj.String()
184+
}
172185
}
173186

174187
body := strings.NewReader(text)
@@ -217,6 +230,7 @@ func (c *Client) execute(method string, urlStr string, text string) (interface{}
217230
resultMap["values"] = valuesSlice
218231
delete(resultMap, "page")
219232
delete(resultMap, "pagelen")
233+
delete(resultMap, "max_depth")
220234
delete(resultMap, "size")
221235
result = resultMap
222236
}

repositories.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Repositories struct {
2323
type RepositoriesRes struct {
2424
Page int32
2525
Pagelen int32
26+
MaxDepth int32
2627
Size int32
2728
Items []Repository
2829
}
@@ -85,6 +86,10 @@ func decodeRepositorys(reposResponse interface{}) (*RepositoriesRes, error) {
8586
if !ok {
8687
pagelen = 0
8788
}
89+
max_depth, ok := reposResponseMap["max_width"].(float64)
90+
if !ok {
91+
max_depth = 0
92+
}
8893
size, ok := reposResponseMap["size"].(float64)
8994
if !ok {
9095
size = 0
@@ -93,6 +98,7 @@ func decodeRepositorys(reposResponse interface{}) (*RepositoriesRes, error) {
9398
repositories := RepositoriesRes{
9499
Page: int32(page),
95100
Pagelen: int32(pagelen),
101+
MaxDepth: int32(max_depth),
96102
Size: int32(size),
97103
Items: repos,
98104
}

repository.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type RepositoryBlob struct {
4646
type RepositoryBranches struct {
4747
Page int
4848
Pagelen int
49+
MaxDepth int
4950
Size int
5051
Next string
5152
Branches []RepositoryBranch
@@ -106,6 +107,7 @@ func (r *Repository) Get(ro *RepositoryOptions) (*Repository, error) {
106107
func (r *Repository) ListFiles(ro *RepositoryFilesOptions) ([]RepositoryFile, error) {
107108
filePath := path.Join("/repositories", ro.Owner, ro.RepoSlug, "src", ro.Ref, ro.Path) + "/"
108109
urlStr := r.c.requestUrl(filePath)
110+
print(urlStr)
109111
response, err := r.c.execute("GET", urlStr, "")
110112
if err != nil {
111113
return nil, err
@@ -146,6 +148,10 @@ func (r *Repository) ListBranches(rbo *RepositoryBranchOptions) (*RepositoryBran
146148
params.Add("pagelen", strconv.Itoa(rbo.Pagelen))
147149
}
148150

151+
if rbo.MaxDepth > 0 {
152+
params.Add("max_depth", strconv.Itoa(rbo.MaxDepth))
153+
}
154+
149155
urlStr := r.c.requestUrl("/repositories/%s/%s/refs/branches?%s", rbo.Owner, rbo.RepoSlug, params.Encode())
150156
response, err := r.c.executeRaw("GET", urlStr, "")
151157
if err != nil {
@@ -349,6 +355,10 @@ func decodeRepositoryBranches(branchResponse interface{}) (*RepositoryBranches,
349355
if !ok {
350356
pagelen = 0
351357
}
358+
max_depth, ok := branchResponseMap["max_depth"].(float64)
359+
if !ok {
360+
max_depth = 0
361+
}
352362
size, ok := branchResponseMap["size"].(float64)
353363
if !ok {
354364
size = 0
@@ -362,6 +372,7 @@ func decodeRepositoryBranches(branchResponse interface{}) (*RepositoryBranches,
362372
repositoryBranches := RepositoryBranches{
363373
Page: int(page),
364374
Pagelen: int(pagelen),
375+
MaxDepth: int(max_depth),
365376
Size: int(size),
366377
Next: next,
367378
Branches: branches,

0 commit comments

Comments
 (0)