feat: add log if github is rate limiting

This commit is contained in:
2026-02-10 20:46:05 +00:00
parent f79c9f2865
commit 031b01ac37
2 changed files with 18 additions and 0 deletions
+12
View File
@@ -28,6 +28,12 @@ func getPushPatches(user string) ([]string, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode == http.StatusForbidden || resp.StatusCode == http.StatusTooManyRequests {
if resp.Header.Get("X-RateLimit-Remaining") == "0" {
return nil, fmt.Errorf("github rate limit exceeded")
}
}
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
return nil, fmt.Errorf("github api failed") return nil, fmt.Errorf("github api failed")
} }
@@ -82,6 +88,12 @@ func getUniqueTzFromPatches(patchUrls []string) ([]string, error) {
return nil, fmt.Errorf("failed to get patch") return nil, fmt.Errorf("failed to get patch")
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode == http.StatusForbidden || resp.StatusCode == http.StatusTooManyRequests {
if resp.Header.Get("X-RateLimit-Remaining") == "0" {
return nil, fmt.Errorf("github rate limit exceeded")
}
}
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
// the DOCS say that some larges ones may time out // the DOCS say that some larges ones may time out
// and they DID // and they DID
+6
View File
@@ -20,6 +20,12 @@ func TestGetPushPatches(t *testing.T) {
func TestGetUniqTzFromPatches(t *testing.T) { func TestGetUniqTzFromPatches(t *testing.T) {
// another test in the same vein // another test in the same vein
patches, _ := getPushPatches("torvalds") patches, _ := getPushPatches("torvalds")
if len(patches) == 0 {
// you might be getting rate limited
t.Fatalf("no patches found")
}
tzs, err := getUniqueTzFromPatches(patches) tzs, err := getUniqueTzFromPatches(patches)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)