github

package
v1.206.3-rc.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPRNotFound indicates the PR does not exist.
	ErrPRNotFound = errors.New("pull request not found")

	// ErrNoWorkflowRunFound indicates no successful workflow run was found for the PR.
	ErrNoWorkflowRunFound = errors.New("no successful workflow run found")

	// ErrNoArtifactFound indicates the requested artifact was not found.
	ErrNoArtifactFound = errors.New("artifact not found")

	// ErrNoArtifactForPlatform indicates no artifact exists for the current platform.
	ErrNoArtifactForPlatform = errors.New("no artifact available for current platform")
)

Artifact-related errors.

View Source
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.

View Source
var ErrGitHubTokenRequired = errors.New("GitHub token required")

ErrGitHubTokenRequired indicates that a GitHub token is required but not found.

View Source
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

func ConvertToRawURL(githubURL string) (string, error)

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:

func GetArtifactDownloadURL

func GetArtifactDownloadURL(ctx context.Context, owner, repo string, artifactID int64) (string, error)

GetArtifactDownloadURL returns the download URL for a specific artifact. The URL requires authentication to download.

func GetGitHubToken

func GetGitHubToken() string

GetGitHubToken retrieves a GitHub token using multiple fallback strategies. The token is required for operations that need authentication (e.g., downloading PR artifacts).

Detection order:

  1. --github-token CLI flag (via viper, for toolchain commands)
  2. ATMOS_GITHUB_TOKEN environment variable
  3. GITHUB_TOKEN environment variable
  4. `gh auth token` command output (if GitHub CLI is installed)

Returns the token if found, or an empty string if no token is available. Use GetGitHubTokenOrError if you need to require authentication.

func GetGitHubTokenOrError

func GetGitHubTokenOrError() (string, error)

GetGitHubTokenOrError retrieves a GitHub token or returns an error if none is found. Use this when authentication is required (e.g., downloading PR artifacts).

func GetLatestRelease

func GetLatestRelease(owner string, repo string) (string, error)

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 GetPRHeadSHA

func GetPRHeadSHA(ctx context.Context, owner, repo string, prNumber int, token string) (string, error)

GetPRHeadSHA retrieves the current head commit SHA for a pull request. This is used for cache validation to check if the PR has new commits. The token parameter is required for API authentication.

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

func GetReleaseVersions(owner, repo string, limit int) ([]string, error)

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 IsNoArtifactError

func IsNoArtifactError(err error) bool

IsNoArtifactError checks if the error is a "no artifact" error.

func IsNoWorkflowError

func IsNoWorkflowError(err error) bool

IsNoWorkflowError checks if the error is a "no workflow run" error.

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError checks if the error is a "not found" type error.

func IsPlatformError

func IsPlatformError(err error) bool

IsPlatformError checks if the error is a platform-related error.

func ShouldWaitForRateLimit added in v1.203.0

func ShouldWaitForRateLimit(ctx context.Context, minRemaining int) bool

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 SupportedPRPlatforms

func SupportedPRPlatforms() []string

SupportedPRPlatforms returns a list of platforms supported by PR artifact downloads.

func WaitForRateLimit added in v1.203.0

func WaitForRateLimit(ctx context.Context, minRemaining int) error

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 ActionsService

type ActionsService interface {
	ListRepositoryWorkflowRuns(ctx context.Context, owner, repo string, opts *github.ListWorkflowRunsOptions) (*github.WorkflowRuns, *github.Response, error)
	ListWorkflowRunArtifacts(ctx context.Context, owner, repo string, runID int64, opts *github.ListOptions) (*github.ArtifactList, *github.Response, error)
	GetArtifact(ctx context.Context, owner, repo string, artifactID int64) (*github.Artifact, *github.Response, error)
}

ActionsService defines the interface for GitHub Actions operations. This allows for mocking in tests.

type ArtifactFetcher

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

ArtifactFetcher wraps the artifact fetching logic with injectable services. Use NewArtifactFetcher to create an instance with custom services for testing.

func NewArtifactFetcher

func NewArtifactFetcher(prs PullRequestService, actions ActionsService) *ArtifactFetcher

NewArtifactFetcher creates an ArtifactFetcher with custom services. This is primarily used for testing with mock services.

func (*ArtifactFetcher) GetArtifactDownloadURL

func (f *ArtifactFetcher) GetArtifactDownloadURL(ctx context.Context, owner, repo string, artifactID int64) (string, error)

GetArtifactDownloadURL returns the download URL using custom services.

func (*ArtifactFetcher) GetPRArtifactInfo

func (f *ArtifactFetcher) GetPRArtifactInfo(ctx context.Context, owner, repo string, prNumber int) (*PRArtifactInfo, error)

GetPRArtifactInfo retrieves build artifact info for a PR using custom services.

func (*ArtifactFetcher) GetPRHeadSHA

func (f *ArtifactFetcher) GetPRHeadSHA(ctx context.Context, owner, repo string, prNumber int) (string, error)

GetPRHeadSHA retrieves the head SHA for a PR using custom services.

func (*ArtifactFetcher) GetSHAArtifactInfo

func (f *ArtifactFetcher) GetSHAArtifactInfo(ctx context.Context, owner, repo, sha string) (*SHAArtifactInfo, error)

GetSHAArtifactInfo retrieves build artifact info for a SHA using custom services.

type PRArtifactInfo

type PRArtifactInfo struct {
	// PR number.
	PRNumber int
	// Head SHA of the PR.
	HeadSHA string
	// Workflow run ID that produced the artifact.
	RunID int64
	// Artifact ID.
	ArtifactID int64
	// Artifact name (e.g., "build-artifacts-macos").
	ArtifactName string
	// Size in bytes.
	SizeInBytes int64
	// Download URL (requires authentication).
	DownloadURL string
	// RunStartedAt is when the workflow run started.
	RunStartedAt time.Time
}

PRArtifactInfo contains information about a PR's build artifact.

func GetPRArtifactInfo

func GetPRArtifactInfo(ctx context.Context, owner, repo string, prNumber int) (*PRArtifactInfo, error)

GetPRArtifactInfo retrieves build artifact information for a PR. This finds the latest successful workflow run for the PR and locates the artifact matching the current platform.

Requires authentication - use GetGitHubTokenOrError() first.

type PullRequestService

type PullRequestService interface {
	Get(ctx context.Context, owner string, repo string, number int) (*github.PullRequest, *github.Response, error)
}

PullRequestService defines the interface for pull request operations. This allows for mocking in tests.

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.

type ReleasesOptions

type ReleasesOptions struct {
	Owner              string
	Repo               string
	Limit              int
	Offset             int
	IncludePrereleases bool
	Since              *time.Time
}

ReleasesOptions contains options for fetching GitHub releases.

type SHAArtifactInfo

type SHAArtifactInfo struct {
	// Head SHA of the commit.
	HeadSHA string
	// Workflow run ID that produced the artifact.
	RunID int64
	// Artifact ID.
	ArtifactID int64
	// Artifact name (e.g., "build-artifacts-macos").
	ArtifactName string
	// Size in bytes.
	SizeInBytes int64
	// Download URL (requires authentication).
	DownloadURL string
	// RunStartedAt is when the workflow run started.
	RunStartedAt time.Time
}

SHAArtifactInfo contains information about a SHA's build artifact.

func GetSHAArtifactInfo

func GetSHAArtifactInfo(ctx context.Context, owner, repo, sha string) (*SHAArtifactInfo, error)

GetSHAArtifactInfo retrieves build artifact information for a commit SHA. This finds the latest successful workflow run for the SHA and locates the artifact matching the current platform.

Requires authentication - use GetGitHubTokenOrError() first.

Directories

Path Synopsis
Package actions provides utilities for GitHub Actions workflows.
Package actions provides utilities for GitHub Actions workflows.

Jump to

Keyboard shortcuts

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