| 218 | } |
| 219 | |
| 220 | func fetchPage(client *http.Client, apiURL string, params url.Values, token string, page int) ([]ghIssue, bool, error) { |
| 221 | params.Set("page", strconv.Itoa(page)) |
| 222 | |
| 223 | reqURL := apiURL + "?" + params.Encode() |
| 224 | req, err := http.NewRequest("GET", reqURL, nil) |
| 225 | if err != nil { |
| 226 | return nil, false, fmt.Errorf("failed to create request: %w", err) |
| 227 | } |
| 228 | |
| 229 | req.Header.Set("Authorization", "Bearer "+token) |
| 230 | req.Header.Set("Accept", "application/vnd.github+json") |
| 231 | |
| 232 | resp, err := client.Do(req) |
| 233 | if err != nil { |
| 234 | return nil, false, fmt.Errorf("request failed: %w", err) |
| 235 | } |
| 236 | defer resp.Body.Close() |
| 237 | |
| 238 | if resp.StatusCode != http.StatusOK { |
| 239 | body, _ := io.ReadAll(resp.Body) |
| 240 | return nil, false, fmt.Errorf("GitHub API returned %d: %s", resp.StatusCode, string(body)) |
| 241 | } |
| 242 | |
| 243 | var issues []ghIssue |
| 244 | if err := json.NewDecoder(resp.Body).Decode(&issues); err != nil { |
| 245 | return nil, false, fmt.Errorf("failed to decode response: %w", err) |
| 246 | } |
| 247 | |
| 248 | hasMore := len(issues) == perPage |
| 249 | return issues, hasMore, nil |
| 250 | } |
| 251 | |
| 252 | func issueToExternalTask(issue ghIssue) sync.ExternalTask { |
| 253 | task := sync.ExternalTask{ |