githubclient

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: MIT

SPDX-License-Identifier: MIT

Index

Constants

View Source
const (
	SHALength = 40
)

SHALength is the standard length of a Git SHA-1 hash.

Variables

This section is empty.

Functions

func CheckRateLimit

func CheckRateLimit(ctx context.Context, client *github.Client) string

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

func IsHexString(s string) bool

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

func NewClient(ctx context.Context) (*github.Client, error)

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

func PrintRateLimit(resp *github.Response)

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).

func (*CachingTransport) RoundTrip

func (t *CachingTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a single HTTP transaction, passing it to the wrapped Transport. This method satisfies the http.RoundTripper interface.

- req: The HTTP request to execute. Returns: The HTTP response and an error, if any.

Jump to

Keyboard shortcuts

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