This is an automated email from the ASF dual-hosted git repository.

klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 6bd54c688 fix(github): process situation without ratelimit header 
(#4431)
6bd54c688 is described below

commit 6bd54c6886a85b2417f606b376df186dc40cb253
Author: Warren Chen <[email protected]>
AuthorDate: Thu Feb 16 15:07:37 2023 +0800

    fix(github): process situation without ratelimit header (#4431)
---
 backend/plugins/github/tasks/api_client.go | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/backend/plugins/github/tasks/api_client.go 
b/backend/plugins/github/tasks/api_client.go
index 2299f649f..c9bfa852c 100644
--- a/backend/plugins/github/tasks/api_client.go
+++ b/backend/plugins/github/tasks/api_client.go
@@ -54,9 +54,17 @@ func CreateApiClient(taskCtx plugin.TaskContext, connection 
*models.GithubConnec
                        }
                        return remaining * len(tokens), time.Unix(int64(reset), 
0).Sub(date), nil
                        */
-                       rateLimit, err := 
strconv.Atoi(res.Header.Get("X-RateLimit-Limit"))
-                       if err != nil {
-                               return 0, 0, errors.Default.Wrap(err, "failed 
to parse X-RateLimit-Limit header")
+                       var rateLimit int
+                       headerRateLimit := res.Header.Get("X-RateLimit-Limit")
+                       if len(headerRateLimit) > 0 {
+                               var e error
+                               rateLimit, e = strconv.Atoi(headerRateLimit)
+                               if e != nil {
+                                       return 0, 0, errors.Default.Wrap(err, 
"failed to parse X-RateLimit-Limit header")
+                               }
+                       } else {
+                               // if we can't find "X-RateLimit-Limit" in 
header, we will return globalRatelimit in ApiRateLimitCalculator.Calculate
+                               return 0, 0, nil
                        }
                        // even though different token could have different 
rate limit, but it is hard to support it
                        // so, we calculate the rate limit of a single token, 
and presume all tokens are the same, to

Reply via email to