ghutil

package
v0.41.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const RateLimitThreshold = 10

Variables

View Source
var ErrRateLimited = errors.New("github token rate limited")

ErrRateLimited is returned when a GitHub API token has hit its rate limit. Callers with a token pool should exhaust this token and try another.

Functions

func AbuseRetryAfter

func AbuseRetryAfter(err error) time.Duration

AbuseRetryAfter returns the retry-after duration if the error is a secondary (abuse) rate limit error. Returns 0 if the error is not an abuse rate limit.

func CheckRateLimit

func CheckRateLimit(ctx context.Context, resp *github.Response) error

func CheckTokenQuota added in v0.30.3

func CheckTokenQuota(ctx context.Context, token string) int

CheckTokenQuota calls the GitHub rate_limit API (free, no quota cost) and returns the remaining quota. Returns -1 on error (treat as usable).

func Deref

func Deref(s *string) string

func GetGitHubDeveloper

func GetGitHubDeveloper(ctx context.Context, client *http.Client, username string) (*data.Developer, error)

func GetLabels

func GetLabels(labels []*github.Label) []string

func GetUsernames

func GetUsernames(users ...*github.User) []string

func HasSufficientQuota added in v0.30.3

func HasSufficientQuota(ctx context.Context, token string) bool

HasSufficientQuota returns true if the token has enough remaining API calls.

func IsRateLimited added in v0.28.0

func IsRateLimited(err error) bool

IsRateLimited reports whether err (or any error in its chain) indicates a GitHub rate limit has been reached. Matches ErrRateLimited, github.RateLimitError, and github.AbuseRateLimitError.

func MapUserToDeveloper

func MapUserToDeveloper(u *github.User) *data.Developer

func MinTokenQuota added in v0.30.3

func MinTokenQuota() int

MinTokenQuota returns the minimum remaining API calls required for a token to be included in the pool.

func ParseDate

func ParseDate(t *time.Time) string

func ParseUsers

func ParseUsers(body *string) []string

func RateInfo

func RateInfo(r *github.Rate) string

func Trim

func Trim(s *string) string

func WaitForRateReset added in v0.17.6

func WaitForRateReset(ctx context.Context, err error) bool

WaitForRateReset checks whether err is a GitHub primary or secondary rate limit error. If so it sleeps until the reset time (plus jitter) and returns true so the caller can retry. Returns false for non-rate-limit errors or if the wait would exceed maxWait.

Types

type TokenPool

type TokenPool struct {
	// contains filtered or unexported fields
}

TokenPool manages a pool of GitHub API tokens using round-robin selection. Safe for concurrent use. Works transparently with a single token. Tracks per-token usage counts for observability and supports marking individual tokens as exhausted (e.g. after hitting a rate limit).

func NewTokenPool

func NewTokenPool(tokens ...string) *TokenPool

NewTokenPool creates a pool from one or more tokens. Tokens can be passed individually or as a single comma-separated string.

func (*TokenPool) ActiveCount added in v0.28.0

func (p *TokenPool) ActiveCount() int

ActiveCount returns the number of non-exhausted tokens.

func (*TokenPool) Exhaust added in v0.28.0

func (p *TokenPool) Exhaust(token string)

Exhaust marks the given token as exhausted so Token() skips it.

func (*TokenPool) Size

func (p *TokenPool) Size() int

Size returns the total number of tokens in the pool (including exhausted).

func (*TokenPool) Token

func (p *TokenPool) Token() string

Token returns the next non-exhausted token in the round-robin rotation. Returns "" when all tokens are exhausted or the pool is empty.

func (*TokenPool) UsageCounts added in v0.18.0

func (p *TokenPool) UsageCounts() []int

UsageCounts returns a copy of per-token call counts (indexed by pool position).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL