Documentation
¶
Index ¶
- Variables
- func ConvertToRawURL(githubURL string) (string, error)
- func GetLatestRelease(owner string, repo string) (string, error)
- func GetLatestReleaseInfo(owner, repo string) (*github.RepositoryRelease, error)
- func GetReleaseByTag(owner, repo, tag string) (*github.RepositoryRelease, error)
- func GetReleaseVersions(owner, repo string, limit int) ([]string, error)
- func GetReleases(opts ReleasesOptions) ([]*github.RepositoryRelease, error)
- func ShouldWaitForRateLimit(ctx context.Context, minRemaining int) bool
- func ShouldWaitForRateLimitWithService(ctx context.Context, service RateLimitService, minRemaining int) bool
- func WaitForRateLimit(ctx context.Context, minRemaining int) error
- type RateLimitService
- type RateLimitStatus
- type ReleasesOptions
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidGitHubURL indicates the GitHub URL format is invalid. ErrInvalidGitHubURL = errors.New("invalid GitHub URL") // ErrUnsupportedGitHubHost indicates the GitHub host is not supported. ErrUnsupportedGitHubHost = errors.New("unsupported GitHub host") // ErrNoVersionsFound indicates no versions were found for a repository. ErrNoVersionsFound = errors.New("no versions found") )
Error definitions for the github package.
var RateLimitWaiter = waitForRateLimitImpl
RateLimitWaiter is the function used to wait for rate limits. Tests can override this to skip the actual wait.
Functions ¶
func ConvertToRawURL ¶ added in v1.203.0
ConvertToRawURL converts a GitHub repository URL to its raw content URL. Supports various GitHub URL formats and converts them to raw.githubusercontent.com URLs.
Examples:
- https://github.com/owner/repo/blob/main/path/file.yaml → https://raw.githubusercontent.com/owner/repo/main/path/file.yaml
- https://github.com/owner/repo/tree/v1.0.0/path → https://raw.githubusercontent.com/owner/repo/v1.0.0/path
- github://owner/repo/path/file.yaml@branch → https://raw.githubusercontent.com/owner/repo/branch/path/file.yaml
- github://owner/repo@v1.0.0 → https://raw.githubusercontent.com/owner/repo/v1.0.0
func GetLatestRelease ¶
GetLatestRelease returns the latest release tag for a GitHub repository.
func GetLatestReleaseInfo ¶
func GetLatestReleaseInfo(owner, repo string) (*github.RepositoryRelease, error)
GetLatestReleaseInfo fetches the latest stable release from GitHub.
func GetReleaseByTag ¶
func GetReleaseByTag(owner, repo, tag string) (*github.RepositoryRelease, error)
GetReleaseByTag fetches a specific GitHub release by tag name.
func GetReleaseVersions ¶ added in v1.203.0
GetReleaseVersions fetches release versions as strings (tag names without 'v' prefix). Returns only non-prerelease versions, suitable for toolchain version management.
func GetReleases ¶
func GetReleases(opts ReleasesOptions) ([]*github.RepositoryRelease, error)
GetReleases fetches GitHub releases with pagination, prerelease filtering, and date filtering.
func ShouldWaitForRateLimit ¶ added in v1.203.0
ShouldWaitForRateLimit checks if rate limit is low enough to warrant waiting. This is a non-blocking check that just returns the decision.
func ShouldWaitForRateLimitWithService ¶ added in v1.203.0
func ShouldWaitForRateLimitWithService(ctx context.Context, service RateLimitService, minRemaining int) bool
ShouldWaitForRateLimitWithService checks if rate limit is low using a custom service. This is primarily used for testing with mock services.
func WaitForRateLimit ¶ added in v1.203.0
WaitForRateLimit checks GitHub rate limits and waits if necessary. If remaining requests are below minRemaining, it waits until the rate limit resets. Uses a spinner UI in TTY mode, otherwise simple output. Returns nil on success or context cancellation error. Does not return error on rate limit check failures (to avoid blocking operations).
Types ¶
type RateLimitService ¶ added in v1.203.0
type RateLimitService interface {
Get(ctx context.Context) (*github.RateLimits, *github.Response, error)
}
RateLimitService defines the interface for rate limit operations. This allows for mocking in tests.
type RateLimitStatus ¶ added in v1.203.0
type RateLimitStatus struct {
// Remaining is the number of requests remaining in the current rate limit window.
Remaining int
// Limit is the maximum number of requests allowed in the rate limit window.
Limit int
// ResetAt is when the rate limit will reset.
ResetAt time.Time
}
RateLimitStatus contains information about GitHub API rate limits.
func CheckRateLimit ¶ added in v1.203.0
func CheckRateLimit(ctx context.Context) (*RateLimitStatus, error)
CheckRateLimit queries the GitHub API for current rate limit status. Returns nil status (not error) if the check fails, to avoid blocking operations.
func CheckRateLimitWithService ¶ added in v1.203.0
func CheckRateLimitWithService(ctx context.Context, service RateLimitService) (*RateLimitStatus, error)
CheckRateLimitWithService queries the GitHub API using a custom service. This is primarily used for testing with mock services.