From 031b01ac378179f780e93bfb9fc788d334013de6 Mon Sep 17 00:00:00 2001 From: ruinivist Date: Tue, 10 Feb 2026 20:46:05 +0000 Subject: [PATCH] feat: add log if github is rate limiting --- internal/github/fetcher.go | 12 ++++++++++++ internal/github/fetcher_test.go | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/internal/github/fetcher.go b/internal/github/fetcher.go index 5134dfd..6ae7d29 100644 --- a/internal/github/fetcher.go +++ b/internal/github/fetcher.go @@ -28,6 +28,12 @@ func getPushPatches(user string) ([]string, error) { } 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 { 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") } 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 { // the DOCS say that some larges ones may time out // and they DID diff --git a/internal/github/fetcher_test.go b/internal/github/fetcher_test.go index 299c53c..2ee5c3a 100644 --- a/internal/github/fetcher_test.go +++ b/internal/github/fetcher_test.go @@ -20,6 +20,12 @@ func TestGetPushPatches(t *testing.T) { func TestGetUniqTzFromPatches(t *testing.T) { // another test in the same vein patches, _ := getPushPatches("torvalds") + + if len(patches) == 0 { + // you might be getting rate limited + t.Fatalf("no patches found") + } + tzs, err := getUniqueTzFromPatches(patches) if err != nil { t.Fatal(err)