mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-01 13:07:49 +02:00
fix(github): check rate limit again after sleeping (#4152)
also ensure sleep > 0 --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
e9760a167b
commit
f883131e73
@ -75,8 +75,15 @@ func (c *githubClient) checkRateLimit(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
sleep := limits.Core.Reset.UTC().Sub(time.Now().UTC())
|
||||
if sleep <= 0 {
|
||||
// it seems that sometimes, after the rate limit just reset, it might
|
||||
// still get <100 remaining and a reset time in the past... in such
|
||||
// cases we can probably sleep a bit more before trying again...
|
||||
sleep = 15 * time.Second
|
||||
}
|
||||
log.Warnf("token too close to rate limiting, will sleep for %s before continuing...", sleep)
|
||||
time.Sleep(sleep)
|
||||
c.checkRateLimit(ctx)
|
||||
}
|
||||
|
||||
func (c *githubClient) GenerateReleaseNotes(ctx *context.Context, repo Repo, prev, current string) (string, error) {
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"text/template"
|
||||
"time"
|
||||
@ -821,12 +822,21 @@ func TestGitHubCreateFileFeatureBranchDoesNotExist(t *testing.T) {
|
||||
func TestCheckRateLimit(t *testing.T) {
|
||||
now := time.Now().UTC()
|
||||
reset := now.Add(1392 * time.Millisecond)
|
||||
var first atomic.Bool
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
if r.URL.Path == "/rate_limit" {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
resetstr, _ := github.Timestamp{Time: reset}.MarshalJSON()
|
||||
if first.Load() {
|
||||
// second time asking for the rate limit
|
||||
fmt.Fprintf(w, `{"resources":{"core":{"remaining":138,"reset":%s}}}`, string(resetstr))
|
||||
return
|
||||
}
|
||||
|
||||
// first time asking for the rate limit
|
||||
fmt.Fprintf(w, `{"resources":{"core":{"remaining":98,"reset":%s}}}`, string(resetstr))
|
||||
first.Store(true)
|
||||
return
|
||||
}
|
||||
t.Error("unhandled request: " + r.Method + " " + r.URL.Path)
|
||||
|
Loading…
x
Reference in New Issue
Block a user