Documentation
¶
Overview ¶
SPDX-License-Identifier: MIT
SPDX-License-Identifier: MIT
Index ¶
- Constants
- func CheckRateLimit(ctx context.Context, client *github.Client) string
- func GetLatestActionRef(ctx context.Context, client *github.Client, owner string, repo string) (string, string, error)
- func IsHexString(s string) bool
- func NewClient(ctx context.Context) (*github.Client, error)
- func PrintRateLimit(resp *github.Response)
- func ResolveRefToSHA(ctx context.Context, client *github.Client, owner, repo, ref string) (string, error)
- type CachingTransport
Constants ¶
const (
SHALength = 40
)
SHALength is the standard length of a Git SHA-1 hash.
Variables ¶
This section is empty.
Functions ¶
func CheckRateLimit ¶
CheckRateLimit retrieves the current GitHub API rate limit status and logs it. This is useful for monitoring usage and diagnosing rate limit errors.
- ctx: The context for the API call, allows for cancellation/timeouts. - client: The initialized GitHub client for making API requests.
Returns a string representing the state of authentication.
func GetLatestActionRef ¶ added in v0.2.0
func GetLatestActionRef( ctx context.Context, client *github.Client, owner string, repo string, ) (string, string, error)
GetLatestActionRef retrieves the most recent reference (tag or release) for a GitHub repository and its corresponding commit SHA. It first attempts to get the latest release, and if that fails, falls back to the most recent tag.
- ctx: The context for API calls, allows for cancellation/timeouts. - client: The initialized GitHub client for making API requests. - owner: The owner (user or organization) of the GitHub repository. - repo: The name of the GitHub repository. Returns:
- string: The name of the latest reference (tag or release name)
- string: The full SHA hash corresponding to that reference
- error: An error if both release and tag retrieval fail
func IsHexString ¶
IsHexString checks if a string consists entirely of valid hexadecimal digits. This is used to determine if a string is likely a Git SHA.
- s: The string to check. Returns: true if the string contains only hexadecimal characters, false otherwise.
func NewClient ¶
NewClient initializes and returns a new GitHub API client. It configures authentication (using GITHUB_TOKEN if available) and adds an HTTP cache layer.
- ctx: The context for the client, allows for cancellation. Returns: An initialized *github.Client and an error if setup fails (e.g., cache directory creation).
func PrintRateLimit ¶
PrintRateLimit logs rate limit information extracted directly from a GitHub API Response. This function is primarily used as a fallback if retrieving the full RateLimit struct fails.
- resp: The *github.Response object from a GitHub API call.
func ResolveRefToSHA ¶
func ResolveRefToSHA( ctx context.Context, client *github.Client, owner, repo, ref string, ) (string, error)
ResolveRefToSHA attempts to find the commit SHA for a given Git ref (tag, branch, or potential SHA). It checks in the order: 1. If the ref itself is a valid, existing commit SHA. 2. If the ref matches an existing Git tag (handling lightweight and annotated tags). 3. If the ref matches an existing Git branch.
- ctx: The context for the API calls, allows for cancellation/timeouts. - client: The initialized GitHub client for making API requests. - owner: The owner (user or organization) of the GitHub repository (e.g., "actions"). - repo: The name of the GitHub repository (e.g., "checkout"). - ref: The Git reference string to resolve (e.g., "v4", "main", "abcdef"). Returns: The full 40-character SHA-1 hash as a string if resolved, or an empty string and an error if not found or a critical error occurs.
Types ¶
type CachingTransport ¶
type CachingTransport struct {
Transport http.RoundTripper // The underlying transport, which could be the cache transport or an authenticated transport.
}
CachingTransport wraps an http.RoundTripper to potentially add custom logic, such as logging or metrics, around the transport (including the cache layer).