mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-03 20:36:07 +01:00 
			
		
		
		
	tests: configure github remaining limit + read token (#9800)
* ci: configure remaining github limmit * prepend with github since package is common to all migrations * add RefreshRate * Update github.go * add missing space * go fmt * Read env variable GITHUB_READ_TOKEN for token * Update .drone.yml
This commit is contained in:
		@@ -24,6 +24,8 @@ import (
 | 
			
		||||
var (
 | 
			
		||||
	_ base.Downloader        = &GithubDownloaderV3{}
 | 
			
		||||
	_ base.DownloaderFactory = &GithubDownloaderV3Factory{}
 | 
			
		||||
	// GithubLimitRateRemaining limit to wait for new rate to apply
 | 
			
		||||
	GithubLimitRateRemaining = 0
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
@@ -115,7 +117,7 @@ func (g *GithubDownloaderV3) SetContext(ctx context.Context) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (g *GithubDownloaderV3) sleep() {
 | 
			
		||||
	for g.rate != nil && g.rate.Remaining <= 0 {
 | 
			
		||||
	for g.rate != nil && g.rate.Remaining <= GithubLimitRateRemaining {
 | 
			
		||||
		timer := time.NewTimer(time.Until(g.rate.Reset.Time))
 | 
			
		||||
		select {
 | 
			
		||||
		case <-g.ctx.Done():
 | 
			
		||||
@@ -124,15 +126,24 @@ func (g *GithubDownloaderV3) sleep() {
 | 
			
		||||
		case <-timer.C:
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		rates, _, err := g.client.RateLimits(g.ctx)
 | 
			
		||||
		err := g.RefreshRate()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Error("g.client.RateLimits: %s", err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		g.rate = rates.GetCore()
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RefreshRate update the current rate (doesn't count in rate limit)
 | 
			
		||||
func (g *GithubDownloaderV3) RefreshRate() error {
 | 
			
		||||
	rates, _, err := g.client.RateLimits(g.ctx)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	g.rate = rates.GetCore()
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetRepoInfo returns a repository information
 | 
			
		||||
func (g *GithubDownloaderV3) GetRepoInfo() (*base.Repository, error) {
 | 
			
		||||
	g.sleep()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user