From 85b6a470e54513e4b96ef0bbd1bd312b8b17ad54 Mon Sep 17 00:00:00 2001 From: Ben Robinson Date: Mon, 2 Oct 2023 12:43:06 +0100 Subject: [PATCH 1/2] use a partial lookup on the secondary rate limit check --- github_ratelimit/detect.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/github_ratelimit/detect.go b/github_ratelimit/detect.go index b992e6c..27d3a8f 100644 --- a/github_ratelimit/detect.go +++ b/github_ratelimit/detect.go @@ -5,6 +5,7 @@ import ( "encoding/json" "io" "net/http" + "strings" ) type SecondaryRateLimitBody struct { @@ -13,12 +14,12 @@ type SecondaryRateLimitBody struct { } const ( - SecondaryRateLimitMessage = `You have exceeded a secondary rate limit and have been temporarily blocked from content creation. Please retry your request again later.` + SecondaryRateLimitMessage = `You have exceeded a secondary rate limit` SecondaryRateLimitDocumentationURL = `https://docs.github.com/rest/overview/resources-in-the-rest-api#secondary-rate-limits` ) func (s SecondaryRateLimitBody) IsSecondaryRateLimit() bool { - return s.Message == SecondaryRateLimitMessage && s.DocumentURL == SecondaryRateLimitDocumentationURL + return strings.Contains(s.Message, SecondaryRateLimitMessage) && s.DocumentURL == SecondaryRateLimitDocumentationURL } // isSecondaryRateLimit checks whether the response is a legitimate secondary rate limit. From d8ee117365418d9520a5b1fc30a259794d1bbb7e Mon Sep 17 00:00:00 2001 From: Ben Robinson Date: Mon, 2 Oct 2023 16:31:22 +0100 Subject: [PATCH 2/2] Update github_ratelimit/detect.go Co-authored-by: Jarek Porzucek <17789797+jporzucek@users.noreply.github.com> --- github_ratelimit/detect.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github_ratelimit/detect.go b/github_ratelimit/detect.go index 27d3a8f..5bbd360 100644 --- a/github_ratelimit/detect.go +++ b/github_ratelimit/detect.go @@ -19,7 +19,7 @@ const ( ) func (s SecondaryRateLimitBody) IsSecondaryRateLimit() bool { - return strings.Contains(s.Message, SecondaryRateLimitMessage) && s.DocumentURL == SecondaryRateLimitDocumentationURL + return strings.HasPrefix(s.Message, SecondaryRateLimitMessage) && s.DocumentURL == SecondaryRateLimitDocumentationURL } // isSecondaryRateLimit checks whether the response is a legitimate secondary rate limit.