github

package
v1.0.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package github provides infrastructure adapter for GitHub API operations.

Index

Constants

View Source
const (
	// GitHubAPIBaseURL is the base URL for GitHub API.
	GitHubAPIBaseURL = "https://api.github.com"

	// DefaultOwner is the default repository owner.
	DefaultOwner = "stablelabs"

	// DefaultRepo is the default repository name.
	DefaultRepo = "stable"

	// DefaultPerPage is the default number of results per page.
	DefaultPerPage = 100
)
View Source
const CacheSchemaVersion = 1

CacheSchemaVersion is the current cache schema version.

View Source
const DefaultCacheTTL = 1 * time.Hour

DefaultCacheTTL is the default time-to-live for cached data.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter implements ports.GitHubClient using the github Client.

func NewAdapter

func NewAdapter(token, owner, repo, cacheDir string) *Adapter

NewAdapter creates a new GitHub adapter.

func (*Adapter) FetchReleases

func (a *Adapter) FetchReleases(ctx context.Context) ([]ports.GitHubRelease, *ports.RateLimitInfo, error)

FetchReleases fetches all releases from the repository.

func (*Adapter) FetchReleasesWithCache

func (a *Adapter) FetchReleasesWithCache(ctx context.Context) ([]ports.GitHubRelease, bool, error)

FetchReleasesWithCache fetches releases with caching support.

func (*Adapter) GetImageVersions

func (a *Adapter) GetImageVersions(ctx context.Context, packageName string) ([]ports.ImageVersion, error)

GetImageVersions returns container image versions.

func (*Adapter) GetImageVersionsWithCache

func (a *Adapter) GetImageVersionsWithCache(ctx context.Context, packageName string) ([]ports.ImageVersion, bool, error)

GetImageVersionsWithCache returns image versions with caching.

type AdapterOption

type AdapterOption func(*Adapter)

AdapterOption is a function that configures an Adapter.

type AuthenticationError

type AuthenticationError struct {
	Message string
}

AuthenticationError indicates authentication failed (401).

func (*AuthenticationError) Error

func (e *AuthenticationError) Error() string

func (*AuthenticationError) ShouldSilenceUsage

func (e *AuthenticationError) ShouldSilenceUsage() bool

ShouldSilenceUsage returns true because authentication errors don't indicate incorrect command usage.

func (*AuthenticationError) UserMessage

func (e *AuthenticationError) UserMessage() string

UserMessage returns the user-friendly error message.

type CacheInfo

type CacheInfo struct {
	Path         string
	FetchedAt    time.Time
	ExpiresAt    time.Time
	VersionCount int
	IsExpired    bool
}

CacheInfo contains information about the cache.

type CacheManager

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

CacheManager handles version cache operations.

func NewCacheManager

func NewCacheManager(homeDir string, ttl time.Duration) *CacheManager

NewCacheManager creates a new cache manager.

func (*CacheManager) CachePath

func (m *CacheManager) CachePath() string

CachePath returns the path to the cache file.

func (*CacheManager) Clear

func (m *CacheManager) Clear() error

Clear deletes the cache file.

func (*CacheManager) ContainerCachePath

func (m *CacheManager) ContainerCachePath() string

ContainerCachePath returns the path to the container versions cache file.

func (*CacheManager) Info

func (m *CacheManager) Info() (*CacheInfo, error)

Info returns information about the cache.

func (*CacheManager) IsContainerCacheExpired

func (m *CacheManager) IsContainerCacheExpired(cache *ContainerVersionCache) bool

IsContainerCacheExpired returns true if the container cache has expired.

func (*CacheManager) IsExpired

func (m *CacheManager) IsExpired(cache *VersionCache) bool

IsExpired returns true if the cache has expired.

func (*CacheManager) Load

func (m *CacheManager) Load() (*VersionCache, error)

Load loads the cache from disk.

func (*CacheManager) LoadContainerCache

func (m *CacheManager) LoadContainerCache() (*ContainerVersionCache, error)

LoadContainerCache loads the container versions cache from disk.

func (*CacheManager) Save

func (m *CacheManager) Save(cache *VersionCache) error

Save saves the cache to disk atomically.

func (*CacheManager) SaveContainerCache

func (m *CacheManager) SaveContainerCache(cache *ContainerVersionCache) error

SaveContainerCache saves the container versions cache to disk atomically.

func (*CacheManager) TTL

func (m *CacheManager) TTL() time.Duration

TTL returns the cache time-to-live duration.

type Client

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

Client is a GitHub API client for fetching releases.

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient creates a new GitHub API client.

func (*Client) FetchContainerVersions

func (c *Client) FetchContainerVersions(ctx context.Context, packageName string) ([]ContainerVersion, *RateLimitInfo, error)

FetchContainerVersions fetches container package versions from GHCR.

func (*Client) FetchReleases

func (c *Client) FetchReleases(ctx context.Context) ([]GitHubRelease, *RateLimitInfo, error)

FetchReleases fetches all releases from the GitHub repository.

func (*Client) FetchReleasesWithCache

func (c *Client) FetchReleasesWithCache(ctx context.Context) ([]GitHubRelease, bool, error)

FetchReleasesWithCache fetches releases from API (always fresh). Cache is only used as fallback when API request fails. Returns (releases, fromCache, error).

func (*Client) GetImageVersions

func (c *Client) GetImageVersions(ctx context.Context, packageName string) ([]ImageVersion, error)

GetImageVersions returns simplified version list for UI display.

func (*Client) GetImageVersionsWithCache

func (c *Client) GetImageVersionsWithCache(ctx context.Context, packageName string) ([]ImageVersion, bool, error)

GetImageVersionsWithCache returns image versions from API (always fresh). Cache is only used as fallback when API request fails. Returns (versions, fromCache, error).

type ClientOption

type ClientOption func(*Client)

ClientOption is a function that configures a Client.

func WithCache

func WithCache(cache *CacheManager) ClientOption

WithCache sets the cache manager.

func WithHTTPClient

func WithHTTPClient(client *http.Client) ClientOption

WithHTTPClient sets a custom HTTP client.

func WithOwnerRepo

func WithOwnerRepo(owner, repo string) ClientOption

WithOwnerRepo sets the repository owner and name.

func WithToken

func WithToken(token string) ClientOption

WithToken sets the GitHub token for authentication.

type ContainerVersion

type ContainerVersion struct {
	ID        int       `json:"id"`
	Name      string    `json:"name"` // SHA digest
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Metadata  struct {
		Container struct {
			Tags []string `json:"tags"`
		} `json:"container"`
	} `json:"metadata"`
}

ContainerVersion represents a container package version from GHCR.

type ContainerVersionCache

type ContainerVersionCache struct {
	Version   int                `json:"version"`
	FetchedAt time.Time          `json:"fetched_at"`
	ExpiresAt time.Time          `json:"expires_at"`
	Versions  []ContainerVersion `json:"versions"`
}

ContainerVersionCache represents cached container version data.

type GitHubRelease

type GitHubRelease struct {
	TagName     string    `json:"tag_name"`     // e.g., "v1.0.0"
	Name        string    `json:"name"`         // Release title
	Draft       bool      `json:"draft"`        // Is this a draft release?
	Prerelease  bool      `json:"prerelease"`   // Is this a pre-release?
	PublishedAt time.Time `json:"published_at"` // When was it published?
	HTMLURL     string    `json:"html_url"`     // Link to release page
}

GitHubRelease represents a release from the GitHub repository.

type ImageVersion

type ImageVersion struct {
	Tag       string
	CreatedAt time.Time
	IsLatest  bool
}

ImageVersion represents a simplified version for display.

type NetworkError

type NetworkError struct {
	Message string
	Cause   error
}

NetworkError indicates a network connectivity issue.

func (*NetworkError) Error

func (e *NetworkError) Error() string

func (*NetworkError) RecoveryHint

func (e *NetworkError) RecoveryHint() string

RecoveryHint returns actionable steps to fix the issue.

func (*NetworkError) ShouldSilenceUsage

func (e *NetworkError) ShouldSilenceUsage() bool

ShouldSilenceUsage returns true because network errors don't indicate incorrect command usage.

func (*NetworkError) Unwrap

func (e *NetworkError) Unwrap() error

func (*NetworkError) UserMessage

func (e *NetworkError) UserMessage() string

UserMessage returns the user-friendly error message.

type NotFoundError

type NotFoundError struct {
	Message string
}

NotFoundError indicates the resource was not found (404). This often happens when accessing private repos without proper authentication.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

func (*NotFoundError) RecoveryHint

func (e *NotFoundError) RecoveryHint() string

RecoveryHint returns actionable steps to fix the issue.

func (*NotFoundError) ShouldSilenceUsage

func (e *NotFoundError) ShouldSilenceUsage() bool

ShouldSilenceUsage returns true because 404 errors on private repos don't indicate incorrect command usage - the user needs authentication.

func (*NotFoundError) UserMessage

func (e *NotFoundError) UserMessage() string

UserMessage returns the user-friendly error message with recovery hints.

type RateLimitError

type RateLimitError struct {
	Limit     int
	Remaining int
	Reset     time.Time
}

RateLimitError indicates rate limiting (403/429).

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

func (*RateLimitError) RecoveryHint

func (e *RateLimitError) RecoveryHint() string

RecoveryHint returns actionable steps to fix the issue.

func (*RateLimitError) ShouldSilenceUsage

func (e *RateLimitError) ShouldSilenceUsage() bool

ShouldSilenceUsage returns true because rate limit errors don't indicate incorrect command usage.

func (*RateLimitError) UserMessage

func (e *RateLimitError) UserMessage() string

UserMessage returns the user-friendly error message.

type RateLimitInfo

type RateLimitInfo struct {
	Limit     int
	Remaining int
	Reset     time.Time
}

RateLimitInfo contains GitHub API rate limit information.

type StaleDataWarning

type StaleDataWarning struct {
	Message string
}

StaleDataWarning indicates stale cached data is being used. This is not a fatal error - the operation can proceed with cached data.

func (*StaleDataWarning) Error

func (e *StaleDataWarning) Error() string

type VersionCache

type VersionCache struct {
	Version   int             `json:"version"`    // Cache schema version
	FetchedAt time.Time       `json:"fetched_at"` // When was data fetched?
	ExpiresAt time.Time       `json:"expires_at"` // When does cache expire?
	Releases  []GitHubRelease `json:"releases"`   // Cached releases
}

VersionCache represents cached version data with metadata.

Jump to

Keyboard shortcuts

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