Documentation
¶
Overview ¶
Package github gives vet a GitHub token and a GitHub API client. A GitHub target is a clone, and the token provider replaces "vet connect" (decisions D8).
Index ¶
- Variables
- func IsCommitSHA(s string) bool
- func ListAll[T any](list func(page int) ([]T, *gh.Response, error)) ([]T, error)
- func NewClient(ctx context.Context, tp TokenProvider, baseURL string, hc *http.Client) (*gh.Client, error)
- func OriginRepo(dir string) string
- func Reason(err error) (reason string, token bool)
- func ReleaseTag(version string) (string, bool)
- func RemoteRepo(u string) string
- func SemverOf(v string) string
- func Source(ctx context.Context, tp TokenProvider) (string, error)
- func WorktreeRoot(dir string) (string, bool)
- type Asset
- type ChainProvider
- type Choice
- type EnvProvider
- type GHProvider
- type Release
- type TokenProvider
Constants ¶
This section is empty.
Variables ¶
var ErrNoToken = errors.New("github: no token")
ErrNoToken means that no provider has a token. vet then calls GitHub anonymously, with the lower rate limit.
Functions ¶
func IsCommitSHA ¶
IsCommitSHA reports a full commit SHA of 40 hex characters.
func ListAll ¶
ListAll calls list for each page of a GitHub API list, from the first page, and returns the items of all pages.
func NewClient ¶
func NewClient(ctx context.Context, tp TokenProvider, baseURL string, hc *http.Client) (*gh.Client, error)
NewClient returns a GitHub API client with the provider's token. With no token the client is anonymous. A baseURL other than the public API points the client at another server, for example a test stub.
func OriginRepo ¶
OriginRepo returns owner/repo of the github.com origin remote of the git repository at dir or above it, or "".
func Reason ¶
Reason returns a short reason for an error of a GitHub API call, as "GitHub API answered 403", and whether a token can fix it. An error that is not of the API keeps its text.
func ReleaseTag ¶
ReleaseTag returns the release tag of a vet version, or false for a development build, a pseudo-version or a version with build metadata.
func RemoteRepo ¶
RemoteRepo returns owner/repo of a github.com remote URL, or "".
func SemverOf ¶
SemverOf returns the version in the form of golang.org/x/mod/semver, with the leading v, or "" for a version that is not valid. A release build sets the version with no v.
func Source ¶
func Source(ctx context.Context, tp TokenProvider) (string, error)
Source names where a provider finds its token: GITHUB_TOKEN, GH_TOKEN or gh auth token. It returns ErrNoToken when no provider has a token.
func WorktreeRoot ¶
WorktreeRoot returns the root of the git working tree at dir or above it, or false when dir is in no git repository.
Types ¶
type ChainProvider ¶
type ChainProvider []TokenProvider
ChainProvider returns the token of the first provider that has one.
type Choice ¶
type Choice struct {
// Major is the major version, such as v2, or "" for each major.
Major string
// Prerelease takes a pre-release too.
Prerelease bool
// Immutable takes only a release that GitHub marks immutable.
Immutable bool
// Cooldown skips a release that is younger. The age counts from the
// latest of the publish time and the asset update times. A release
// with a time after Now does not count.
Cooldown time.Duration
// Minimum skips a release below this version, or "".
Minimum string
Now time.Time
}
Choice is the rule that picks a release.
type EnvProvider ¶
EnvProvider reads GITHUB_TOKEN, then GH_TOKEN.
type GHProvider ¶
type GHProvider struct {
// Command replaces the gh binary, for tests.
Command string
Timeout time.Duration
}
GHProvider runs "gh auth token".
type Release ¶
type Release struct {
Tag string `json:"tag_name"`
Draft bool `json:"draft"`
Prerelease bool `json:"prerelease"`
Immutable bool `json:"immutable"`
PublishedAt time.Time `json:"published_at"`
Assets []Asset `json:"assets"`
}
Release is a release of a repository, with the fields that a release choice reads. go-github has no immutable field, so vet decodes the API answer itself.
type TokenProvider ¶
TokenProvider returns a GitHub token.
func DefaultProvider ¶
func DefaultProvider() TokenProvider
DefaultProvider reads GITHUB_TOKEN, then GH_TOKEN, then "gh auth token".