Skip to content
Merged
Changes from all commits
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
27 changes: 13 additions & 14 deletions pkg/github/ui_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,29 +270,28 @@ func uiGetBranches(ctx context.Context, deps ToolDependencies, args map[string]a

client, err := deps.GetClient(ctx)
if err != nil {
return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err)
return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil
}

opts := &github.BranchListOptions{
ListOptions: github.ListOptions{PerPage: 100},
}

branches, resp, err := client.Repositories.ListBranches(ctx, owner, repo, opts)
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to list branches", resp, err), nil, nil
}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
body, err := io.ReadAll(resp.Body)
var allBranches []*github.Branch
for {
branches, resp, err := client.Repositories.ListBranches(ctx, owner, repo, opts)
if err != nil {
return nil, nil, fmt.Errorf("failed to read response body: %w", err)
return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to list branches", resp, err), nil, nil
}
allBranches = append(allBranches, branches...)
if resp.NextPage == 0 {
break
}
return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to list branches", resp, body), nil, nil
opts.Page = resp.NextPage
}

minimalBranches := make([]MinimalBranch, 0, len(branches))
for _, branch := range branches {
minimalBranches := make([]MinimalBranch, 0, len(allBranches))
for _, branch := range allBranches {
minimalBranches = append(minimalBranches, convertToMinimalBranch(branch))
}

Expand All @@ -301,7 +300,7 @@ func uiGetBranches(ctx context.Context, deps ToolDependencies, args map[string]a
"totalCount": len(minimalBranches),
})
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal response: %w", err)
return utils.NewToolResultErrorFromErr("failed to marshal response", err), nil, nil
}

return utils.NewToolResultText(string(r)), nil, nil
Expand Down
Loading