@@ -270,29 +270,28 @@ func uiGetBranches(ctx context.Context, deps ToolDependencies, args map[string]a
270270
271271 client , err := deps .GetClient (ctx )
272272 if err != nil {
273- return nil , nil , fmt . Errorf ("failed to get GitHub client: %w " , err )
273+ return utils . NewToolResultErrorFromErr ("failed to get GitHub client" , err ), nil , nil
274274 }
275275
276276 opts := & github.BranchListOptions {
277277 ListOptions : github.ListOptions {PerPage : 100 },
278278 }
279279
280- branches , resp , err := client .Repositories .ListBranches (ctx , owner , repo , opts )
281- if err != nil {
282- return ghErrors .NewGitHubAPIErrorResponse (ctx , "failed to list branches" , resp , err ), nil , nil
283- }
284- defer func () { _ = resp .Body .Close () }()
285-
286- if resp .StatusCode != http .StatusOK {
287- body , err := io .ReadAll (resp .Body )
280+ var allBranches []* github.Branch
281+ for {
282+ branches , resp , err := client .Repositories .ListBranches (ctx , owner , repo , opts )
288283 if err != nil {
289- return nil , nil , fmt .Errorf ("failed to read response body: %w" , err )
284+ return ghErrors .NewGitHubAPIErrorResponse (ctx , "failed to list branches" , resp , err ), nil , nil
285+ }
286+ allBranches = append (allBranches , branches ... )
287+ if resp .NextPage == 0 {
288+ break
290289 }
291- return ghErrors . NewGitHubAPIStatusErrorResponse ( ctx , "failed to list branches" , resp , body ), nil , nil
290+ opts . Page = resp . NextPage
292291 }
293292
294- minimalBranches := make ([]MinimalBranch , 0 , len (branches ))
295- for _ , branch := range branches {
293+ minimalBranches := make ([]MinimalBranch , 0 , len (allBranches ))
294+ for _ , branch := range allBranches {
296295 minimalBranches = append (minimalBranches , convertToMinimalBranch (branch ))
297296 }
298297
@@ -301,7 +300,7 @@ func uiGetBranches(ctx context.Context, deps ToolDependencies, args map[string]a
301300 "totalCount" : len (minimalBranches ),
302301 })
303302 if err != nil {
304- return nil , nil , fmt . Errorf ("failed to marshal response: %w " , err )
303+ return utils . NewToolResultErrorFromErr ("failed to marshal response" , err ), nil , nil
305304 }
306305
307306 return utils .NewToolResultText (string (r )), nil , nil
0 commit comments