@@ -59,24 +59,40 @@ export class BitbucketRepositoryProvider implements RepositoryProvider {
59
59
async getBranches ( user : User , owner : string , repo : string ) : Promise < Branch [ ] > {
60
60
const branches : Branch [ ] = [ ] ;
61
61
const api = await this . apiFactory . create ( user ) ;
62
- const response = await api . repositories . listBranches ( {
63
- workspace : owner ,
64
- repo_slug : repo ,
65
- sort : "target.date" ,
66
- } ) ;
67
62
68
- for ( const branch of response . data . values ! ) {
69
- branches . push ( {
70
- htmlUrl : branch . links ?. html ?. href ! ,
71
- name : branch . name ! ,
72
- commit : {
73
- sha : branch . target ?. hash ! ,
74
- author : branch . target ?. author ?. user ?. display_name ! ,
75
- authorAvatarUrl : branch . target ?. author ?. user ?. links ?. avatar ?. href ,
76
- authorDate : branch . target ? .date ! ,
77
- commitMessage : branch . target ?. message || "missing commit message" ,
78
- } ,
63
+ // Handle pagination.
64
+ let nextPage = 1 ;
65
+ let isMoreDataAvailable = true ;
66
+
67
+ while ( isMoreDataAvailable ) {
68
+ const response = await api . repositories . listBranches ( {
69
+ workspace : owner ,
70
+ repo_slug : repo ,
71
+ sort : " target.date" ,
72
+ page : String ( nextPage ) ,
73
+ pagelen : 100 ,
79
74
} ) ;
75
+
76
+ for ( const branch of response . data . values ! ) {
77
+ branches . push ( {
78
+ htmlUrl : branch . links ?. html ?. href ! ,
79
+ name : branch . name ! ,
80
+ commit : {
81
+ sha : branch . target ?. hash ! ,
82
+ author : branch . target ?. author ?. user ?. display_name ! ,
83
+ authorAvatarUrl : branch . target ?. author ?. user ?. links ?. avatar ?. href ,
84
+ authorDate : branch . target ?. date ! ,
85
+ commitMessage : branch . target ?. message || "missing commit message" ,
86
+ } ,
87
+ } ) ;
88
+ }
89
+
90
+ // If the response has a "next" property, it indicates there are more pages.
91
+ if ( response . data . next ) {
92
+ nextPage ++ ;
93
+ } else {
94
+ isMoreDataAvailable = false ;
95
+ }
80
96
}
81
97
82
98
return branches ;
0 commit comments