You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-11-29 23:07:42 +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:
committed by
GitHub
parent
e9760a167b
commit
f883131e73
@@ -75,8 +75,15 @@ func (c *githubClient) checkRateLimit(ctx *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
sleep := limits.Core.Reset.UTC().Sub(time.Now().UTC())
|
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)
|
log.Warnf("token too close to rate limiting, will sleep for %s before continuing...", sleep)
|
||||||
time.Sleep(sleep)
|
time.Sleep(sleep)
|
||||||
|
c.checkRateLimit(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *githubClient) GenerateReleaseNotes(ctx *context.Context, repo Repo, prev, current string) (string, error) {
|
func (c *githubClient) GenerateReleaseNotes(ctx *context.Context, repo Repo, prev, current string) (string, error) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
@@ -821,12 +822,21 @@ func TestGitHubCreateFileFeatureBranchDoesNotExist(t *testing.T) {
|
|||||||
func TestCheckRateLimit(t *testing.T) {
|
func TestCheckRateLimit(t *testing.T) {
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
reset := now.Add(1392 * time.Millisecond)
|
reset := now.Add(1392 * time.Millisecond)
|
||||||
|
var first atomic.Bool
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
if r.URL.Path == "/rate_limit" {
|
if r.URL.Path == "/rate_limit" {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
resetstr, _ := github.Timestamp{Time: reset}.MarshalJSON()
|
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))
|
fmt.Fprintf(w, `{"resources":{"core":{"remaining":98,"reset":%s}}}`, string(resetstr))
|
||||||
|
first.Store(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.Error("unhandled request: " + r.Method + " " + r.URL.Path)
|
t.Error("unhandled request: " + r.Method + " " + r.URL.Path)
|
||||||
|
|||||||
Reference in New Issue
Block a user