|
8 | 8 | "encoding/pem" |
9 | 9 | "fmt" |
10 | 10 | "io" |
| 11 | + "log/slog" |
11 | 12 | "net/http" |
12 | 13 | "net/url" |
13 | 14 | "strconv" |
@@ -1047,46 +1048,57 @@ func (g *GitHubProvider) ListIssueComments(ctx context.Context, owner, repo stri |
1047 | 1048 | return nil, err |
1048 | 1049 | } |
1049 | 1050 |
|
1050 | | - reqURL := fmt.Sprintf("%s/repos/%s/%s/issues/%d/comments?per_page=100", g.baseURL, owner, repo, number) |
| 1051 | + var allComments []IssueComment |
| 1052 | + page := 1 |
| 1053 | + for { |
| 1054 | + reqURL := fmt.Sprintf("%s/repos/%s/%s/issues/%d/comments?per_page=100&page=%d", g.baseURL, owner, repo, number, page) |
1051 | 1055 |
|
1052 | | - req, err := http.NewRequestWithContext(ctx, "GET", reqURL, http.NoBody) |
1053 | | - if err != nil { |
1054 | | - return nil, err |
1055 | | - } |
1056 | | - g.setAuthHeader(req) |
| 1056 | + req, err := http.NewRequestWithContext(ctx, "GET", reqURL, http.NoBody) |
| 1057 | + if err != nil { |
| 1058 | + return nil, err |
| 1059 | + } |
| 1060 | + g.setAuthHeader(req) |
1057 | 1061 |
|
1058 | | - resp, err := g.httpClient.Do(req) |
1059 | | - if err != nil { |
1060 | | - return nil, err |
1061 | | - } |
1062 | | - defer func() { _ = resp.Body.Close() }() |
| 1062 | + resp, err := g.httpClient.Do(req) |
| 1063 | + if err != nil { |
| 1064 | + return nil, err |
| 1065 | + } |
1063 | 1066 |
|
1064 | | - if resp.StatusCode != http.StatusOK { |
1065 | | - return nil, g.handleErrorResponse(resp) |
1066 | | - } |
| 1067 | + if resp.StatusCode != http.StatusOK { |
| 1068 | + err := g.handleErrorResponse(resp) |
| 1069 | + _ = resp.Body.Close() |
| 1070 | + return nil, err |
| 1071 | + } |
1067 | 1072 |
|
1068 | | - var ghComments []struct { |
1069 | | - ID int64 `json:"id"` |
1070 | | - Body string `json:"body"` |
1071 | | - User githubUser `json:"user"` |
1072 | | - CreatedAt time.Time `json:"created_at"` |
1073 | | - UpdatedAt time.Time `json:"updated_at"` |
1074 | | - } |
1075 | | - if err := json.NewDecoder(resp.Body).Decode(&ghComments); err != nil { |
1076 | | - return nil, err |
1077 | | - } |
| 1073 | + var ghComments []struct { |
| 1074 | + ID int64 `json:"id"` |
| 1075 | + Body string `json:"body"` |
| 1076 | + User githubUser `json:"user"` |
| 1077 | + CreatedAt time.Time `json:"created_at"` |
| 1078 | + UpdatedAt time.Time `json:"updated_at"` |
| 1079 | + } |
| 1080 | + if err := json.NewDecoder(resp.Body).Decode(&ghComments); err != nil { |
| 1081 | + _ = resp.Body.Close() |
| 1082 | + return nil, err |
| 1083 | + } |
| 1084 | + _ = resp.Body.Close() |
| 1085 | + |
| 1086 | + for _, c := range ghComments { |
| 1087 | + allComments = append(allComments, IssueComment{ |
| 1088 | + ID: c.ID, |
| 1089 | + Body: c.Body, |
| 1090 | + User: c.User.toUser(), |
| 1091 | + CreatedAt: c.CreatedAt, |
| 1092 | + UpdatedAt: c.UpdatedAt, |
| 1093 | + }) |
| 1094 | + } |
1078 | 1095 |
|
1079 | | - comments := make([]IssueComment, len(ghComments)) |
1080 | | - for i, c := range ghComments { |
1081 | | - comments[i] = IssueComment{ |
1082 | | - ID: c.ID, |
1083 | | - Body: c.Body, |
1084 | | - User: c.User.toUser(), |
1085 | | - CreatedAt: c.CreatedAt, |
1086 | | - UpdatedAt: c.UpdatedAt, |
| 1096 | + if len(ghComments) < 100 { |
| 1097 | + break |
1087 | 1098 | } |
| 1099 | + page++ |
1088 | 1100 | } |
1089 | | - return comments, nil |
| 1101 | + return allComments, nil |
1090 | 1102 | } |
1091 | 1103 |
|
1092 | 1104 | // UpdateIssueComment updates an existing comment on an issue |
@@ -1328,7 +1340,9 @@ func (g *GitHubProvider) handleErrorResponse(resp *http.Response) error { |
1328 | 1340 | case http.StatusUnauthorized: |
1329 | 1341 | return ErrInvalidCredentials |
1330 | 1342 | case http.StatusForbidden: |
1331 | | - if strings.Contains(bodyStr, "rate limit") { |
| 1343 | + if strings.Contains(bodyStr, "rate limit") || resp.Header.Get("X-RateLimit-Remaining") == "0" { |
| 1344 | + resetAt := resp.Header.Get("X-RateLimit-Reset") |
| 1345 | + slog.Warn("GitHub rate limit hit", "reset_at", resetAt) |
1332 | 1346 | return ErrRateLimited |
1333 | 1347 | } |
1334 | 1348 | if bodyStr != "" { |
|
0 commit comments