@@ -21,6 +21,7 @@ import (
21
21
)
22
22
23
23
const DEFAULT_PAGE_LENGTH = 10
24
+ const DEFAULT_LIMIT_PAGES = 0
24
25
const DEFAULT_MAX_DEPTH = 1
25
26
const DEFAULT_BITBUCKET_API_BASE_URL = "https://api.bitbucket.org/2.0"
26
27
@@ -42,6 +43,9 @@ type Client struct {
42
43
Workspaces * Workspace
43
44
Pagelen int
44
45
MaxDepth int
46
+ // LimitPages limits the number of pages for a request
47
+ // default value as 0 -- disable limits
48
+ LimitPages int
45
49
// DisableAutoPaging allows you to disable the default behavior of automatically requesting
46
50
// all the pages for a paginated response.
47
51
DisableAutoPaging bool
@@ -150,7 +154,8 @@ func injectClient(a *auth) *Client {
150
154
if err != nil {
151
155
log .Fatalf ("invalid bitbucket url" )
152
156
}
153
- c := & Client {Auth : a , Pagelen : DEFAULT_PAGE_LENGTH , MaxDepth : DEFAULT_MAX_DEPTH , apiBaseURL : bitbucketUrl }
157
+ c := & Client {Auth : a , Pagelen : DEFAULT_PAGE_LENGTH , MaxDepth : DEFAULT_MAX_DEPTH ,
158
+ apiBaseURL : bitbucketUrl , LimitPages : DEFAULT_LIMIT_PAGES }
154
159
c .Repositories = & Repositories {
155
160
c : c ,
156
161
PullRequests : & PullRequests {c : c },
@@ -349,12 +354,16 @@ func (c *Client) doPaginatedRequest(req *http.Request, emptyResponse bool) (inte
349
354
}
350
355
351
356
responsePaginated := & Response {}
357
+ var curPage int
358
+
352
359
err = json .Unmarshal (responseBytes , responsePaginated )
353
360
if err == nil && len (responsePaginated .Values ) > 0 {
354
361
var values []interface {}
355
362
for {
363
+ curPage ++
356
364
values = append (values , responsePaginated .Values ... )
357
- if c .DisableAutoPaging || len (responsePaginated .Next ) == 0 {
365
+ if c .DisableAutoPaging || len (responsePaginated .Next ) == 0 ||
366
+ (curPage >= c .LimitPages && c .LimitPages != 0 ) {
358
367
break
359
368
}
360
369
newReq , err := http .NewRequest (req .Method , responsePaginated .Next , nil )
0 commit comments