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)