github

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package github provides a GitHub API client for fetching version information.

Index

Constants

View Source
const (
	// APIVersion is the GitHub REST API version header value.
	APIVersion = "2022-11-28"
)

API configuration constants.

Variables

View Source
var (
	// ErrInvalidURL indicates the provided URL is not a valid GitHub repository URL.
	ErrInvalidURL = errors.New("invalid GitHub repository URL")

	// ErrHTTPRequest indicates an HTTP request to the GitHub API failed.
	ErrHTTPRequest = errors.New("HTTP request failed")
)

Sentinel errors for GitHub API operations.

Functions

func GetOwnerRepo

func GetOwnerRepo(url string) (owner, repo string, err error)

GetOwnerRepo extracts owner and repository name from a GitHub URL.

func ParseGitTagsOutput

func ParseGitTagsOutput(output string) []string

ParseGitTagsOutput parses git ls-remote style output into tag names. This is useful for parsing cached or pre-fetched tag data.

Types

type Client

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

Client provides methods to interact with the GitHub REST API.

func NewClient

func NewClient() *Client

NewClient creates a new GitHub API client with default settings. It automatically uses GITHUB_TOKEN or GITHUB_API_TOKEN environment variable if set.

func NewClientWithHTTP

func NewClientWithHTTP(httpClient HTTPClient, apiURL string) *Client

NewClientWithHTTP creates a new GitHub client with a custom HTTP client.

func NewClientWithToken

func NewClientWithToken(token string) *Client

NewClientWithToken creates a new GitHub client with explicit token.

func (*Client) GetReleases

func (client *Client) GetReleases(ctx context.Context, repoURL string) ([]string, error)

GetReleases fetches all releases from a GitHub repository.

func (*Client) GetTags

func (client *Client) GetTags(ctx context.Context, repoURL string) ([]string, error)

GetTags fetches all tags from a GitHub repository using the API.

func (*Client) GetToken

func (client *Client) GetToken() string

GetToken returns the current auth token (for testing).

func (*Client) SetToken

func (client *Client) SetToken(token string)

SetToken sets the authentication token.

type HTTPClient

type HTTPClient interface {
	// Do sends an HTTP request and returns an HTTP response.
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient interface for HTTP operations (allows mocking).

type ReleaseResponse

type ReleaseResponse struct {
	TagName string `json:"tag_name"`
}

ReleaseResponse represents a release from the GitHub API.

type TagResponse

type TagResponse struct {
	Ref string `json:"ref"`
}

TagResponse represents a tag from the GitHub API.

Directories

Path Synopsis
Package mock provides mock servers for testing the GitHub client.
Package mock provides mock servers for testing the GitHub client.

Jump to

Keyboard shortcuts

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