Documentation
¶
Index ¶
- Constants
- func IsCommitHash(ref string) bool
- func IsMajorVersionOnly(ref string) bool
- type ActionInfo
- type Cache
- func (c *Cache) Clear()
- func (c *Cache) GetConstrained(key VersionKey) (VersionResult, bool)
- func (c *Cache) GetUnconstrained(key VersionKey) (VersionResult, bool)
- func (c *Cache) SetConstrained(key VersionKey, result VersionResult)
- func (c *Cache) SetUnconstrained(key VersionKey, result VersionResult)
- func (c *Cache) Stats() CacheStats
- type CacheStats
- type Client
- func (c *Client) ClearCache()
- func (c *Client) GetCacheStats() CacheStats
- func (c *Client) GetCommitHash(owner, repo, ref string) (string, error)
- func (c *Client) GetLatestMinorVersion(owner, repo, majorVersion string) (string, string, error)
- func (c *Client) GetLatestVersion(owner, repo, currentVersion, versionConstraint string) (string, string, error)
- func (c *Client) GetLatestVersionUnconstrained(owner, repo string) (string, string, error)
- func (c *Client) GetTagForCommit(owner, repo, commitHash string) (string, error)
- type MockResolver
- func (m *MockResolver) GetCacheStats() CacheStats
- func (m *MockResolver) GetCommitHash(owner, repo, ref string) (string, error)
- func (m *MockResolver) GetLatestMinorVersion(owner, repo, majorVersion string) (string, string, error)
- func (m *MockResolver) GetLatestVersion(owner, repo, currentVersion, versionConstraint string) (string, string, error)
- func (m *MockResolver) GetLatestVersionUnconstrained(owner, repo string) (string, string, error)
- func (m *MockResolver) GetTagForCommit(owner, repo, commitHash string) (string, error)
- type Resolver
- type VersionKey
- type VersionResult
Constants ¶
const ( // GitHubTokenEnvVar is the environment variable for GitHub authentication. GitHubTokenEnvVar = "GITHUB_TOKEN" //nolint:gosec // Not a credential, just env var name )
Variables ¶
This section is empty.
Functions ¶
func IsCommitHash ¶
IsCommitHash checks if a reference is a 40-char hex commit hash.
func IsMajorVersionOnly ¶
IsMajorVersionOnly checks if ref is only a major version (e.g., "v3" or "3").
Types ¶
type ActionInfo ¶
type ActionInfo struct {
Owner string
Repo string
Path string // Subdirectory path for composite actions (e.g., "upload-sarif")
Ref string // Git reference: tag (e.g., "v2"), commit hash, or branch name
}
ActionInfo represents a parsed GitHub Action reference.
func ParseActionUses ¶
func ParseActionUses(uses string) (*ActionInfo, error)
ParseActionUses parses "owner/repo@ref" or "owner/repo/path@ref" into ActionInfo. For composite actions like "github/codeql-action/upload-sarif@v2", the repo is extracted as "codeql-action" and path as "upload-sarif".
func (*ActionInfo) FormatUses ¶
func (a *ActionInfo) FormatUses(ref string) string
FormatUses returns the action uses string with the given ref (e.g., "owner/repo@ref").
func (*ActionInfo) IsAtLatest ¶
func (a *ActionInfo) IsAtLatest(latestTag, latestHash string) bool
IsAtLatest checks if the current ref points to the latest version. Works for hashes, tags, and major versions.
func (*ActionInfo) Name ¶
func (a *ActionInfo) Name() string
Name returns the normalized action name (owner/repo or owner/repo/path).
func (*ActionInfo) NeedsFormatChange ¶
func (a *ActionInfo) NeedsFormatChange(desiredFormat string) bool
NeedsFormatChange checks if the current ref format differs from the desired format.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache stores cached results for version lookups to avoid duplicate API calls when the same action appears in multiple workflows.
func (*Cache) Clear ¶
func (c *Cache) Clear()
Clear clears all cached version lookup results. This is useful for testing or when you want to force fresh API calls.
func (*Cache) GetConstrained ¶
func (c *Cache) GetConstrained(key VersionKey) (VersionResult, bool)
GetConstrained retrieves a cached version result for a constrained lookup. Returns the cached result and true if found, or zero result and false if not cached.
func (*Cache) GetUnconstrained ¶
func (c *Cache) GetUnconstrained(key VersionKey) (VersionResult, bool)
GetUnconstrained retrieves a cached version result for an unconstrained lookup. Returns the cached result and true if found, or zero result and false if not cached.
func (*Cache) SetConstrained ¶
func (c *Cache) SetConstrained(key VersionKey, result VersionResult)
SetConstrained stores a version result in the cache for a constrained lookup.
func (*Cache) SetUnconstrained ¶
func (c *Cache) SetUnconstrained(key VersionKey, result VersionResult)
SetUnconstrained stores a version result in the cache for an unconstrained lookup.
func (*Cache) Stats ¶
func (c *Cache) Stats() CacheStats
Stats returns the current cache statistics.
type CacheStats ¶
type CacheStats struct {
Hits int64 // Number of cache hits
Misses int64 // Number of cache misses (API calls made)
}
CacheStats holds statistics about cache usage.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements the Resolver interface.
func NewClient ¶
func NewClient() *Client
NewClient creates a new Client instance with background context.
func NewClientWithCache ¶
NewClientWithCache creates a Client with a shared cache.
func NewClientWithContext ¶
NewClientWithContext creates a new Client instance with the provided context.
func (*Client) ClearCache ¶
func (c *Client) ClearCache()
ClearCache clears the version lookup cache.
func (*Client) GetCacheStats ¶
func (c *Client) GetCacheStats() CacheStats
GetCacheStats returns the cache usage statistics.
func (*Client) GetCommitHash ¶
GetCommitHash resolves a Git reference to its commit hash.
func (*Client) GetLatestMinorVersion ¶
GetLatestMinorVersion finds the latest minor version for a major version. For example, "v3" might return "v3.5.2".
func (*Client) GetLatestVersion ¶
func (c *Client) GetLatestVersion(owner, repo, currentVersion, versionConstraint string) (string, string, error)
GetLatestVersion fetches the latest compatible tag and commit hash. Results are cached.
func (*Client) GetLatestVersionUnconstrained ¶
GetLatestVersionUnconstrained fetches the semantically latest version. First tries GitHub Releases API (single call), then falls back to tag pagination. Results are cached.
type MockResolver ¶
type MockResolver struct {
GetCommitHashFunc func(owner, repo, ref string) (string, error)
GetLatestVersionFunc func(owner, repo, currentVersion, versionConstraint string) (string, string, error)
GetLatestVersionUnconstrFunc func(owner, repo string) (string, string, error)
GetTagForCommitFunc func(owner, repo, commitHash string) (string, error)
GetLatestMinorVersionFunc func(owner, repo, majorVersion string) (string, string, error)
}
MockResolver is a mock implementation of the Resolver interface for testing.
func (*MockResolver) GetCacheStats ¶
func (m *MockResolver) GetCacheStats() CacheStats
func (*MockResolver) GetCommitHash ¶
func (m *MockResolver) GetCommitHash(owner, repo, ref string) (string, error)
func (*MockResolver) GetLatestMinorVersion ¶
func (m *MockResolver) GetLatestMinorVersion(owner, repo, majorVersion string) (string, string, error)
func (*MockResolver) GetLatestVersion ¶
func (m *MockResolver) GetLatestVersion(owner, repo, currentVersion, versionConstraint string) (string, string, error)
func (*MockResolver) GetLatestVersionUnconstrained ¶
func (m *MockResolver) GetLatestVersionUnconstrained(owner, repo string) (string, string, error)
func (*MockResolver) GetTagForCommit ¶
func (m *MockResolver) GetTagForCommit(owner, repo, commitHash string) (string, error)
type Resolver ¶
type Resolver interface {
GetCommitHash(owner, repo, ref string) (string, error)
GetLatestVersion(owner, repo, currentVersion, versionConstraint string) (string, string, error)
GetLatestVersionUnconstrained(owner, repo string) (string, string, error)
GetTagForCommit(owner, repo, commitHash string) (string, error)
GetLatestMinorVersion(owner, repo, majorVersion string) (string, string, error)
GetCacheStats() CacheStats
}
Resolver defines the interface for GitHub Actions operations.
type VersionKey ¶
type VersionKey struct {
Owner string
Repo string
Ref string // Current version reference (e.g., "v1.2.0"); empty for unconstrained
Constraint string // Version constraint (e.g., "^1.0.0"); empty for unconstrained
}
VersionKey represents a cache key for version lookups.
func NewConstrainedKey ¶
func NewConstrainedKey(owner, repo, ref, constraint string) VersionKey
NewConstrainedKey creates a key for constrained version lookups.
func NewUnconstrainedKey ¶
func NewUnconstrainedKey(owner, repo string) VersionKey
NewUnconstrainedKey creates a key for unconstrained version lookups. Unconstrained lookups get the absolute latest version for a repo.
func (VersionKey) IsConstrained ¶
func (k VersionKey) IsConstrained() bool
IsConstrained returns true if this is a constrained key.
func (VersionKey) String ¶
func (k VersionKey) String() string
String returns the string representation of the cache key.
type VersionResult ¶
VersionResult represents a cached version lookup result.
func NewVersionResult ¶
func NewVersionResult(tag, hash string, err error) VersionResult
NewVersionResult creates a new VersionResult.
func (VersionResult) IsError ¶
func (r VersionResult) IsError() bool
IsError returns true if the result contains an error.