github

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: EUPL-1.2 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// NewClient is a variable that holds the function to create a new GitHub client.
	// This allows for mocking in tests.
	NewClient = func(httpClient *http.Client) *github.Client {
		return github.NewClient(httpClient)
	}
	// NewRequest is a variable that holds the function to create a new HTTP request.
	NewRequest = func(method, url string, body io.Reader) (*http.Request, error) {
		return http.NewRequest(method, url, body)
	}
	// DefaultClient is the default http client
	DefaultClient = &http.Client{}
)
View Source
var NewAuthenticatedClient = func(ctx context.Context) *http.Client {
	token := os.Getenv("GITHUB_TOKEN")
	if token == "" {
		return http.DefaultClient
	}
	ts := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: token},
	)
	return oauth2.NewClient(ctx, ts)
}

NewAuthenticatedClient creates a new authenticated http client.

Functions

func DownloadReleaseAsset

func DownloadReleaseAsset(asset *github.ReleaseAsset) ([]byte, error)

DownloadReleaseAsset downloads a release asset.

func GetLatestRelease

func GetLatestRelease(owner, repo string) (*github.RepositoryRelease, error)

GetLatestRelease gets the latest release for a repository.

func ParseRepoFromURL

func ParseRepoFromURL(u string) (owner, repo string, err error)

ParseRepoFromURL parses the owner and repository from a GitHub URL.

Types

type GithubClient

type GithubClient interface {
	GetPublicRepos(ctx context.Context, userOrOrg string) ([]string, error)
}

GithubClient is an interface for interacting with the Github API.

func NewGithubClient

func NewGithubClient() GithubClient

NewGithubClient creates a new GithubClient.

type Repo

type Repo struct {
	CloneURL string `json:"clone_url"`
}

Jump to

Keyboard shortcuts

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