github

package
v1.25.5 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSuccessfulRun = errors.New("no successful run found")

ErrNoSuccessfulRun is returned by FindWorkflowArtifact when no successful run matches the filter.

Functions

func ArtifactDownloadURL added in v1.25.5

func ArtifactDownloadURL(owner, repo string, artifactID int64) (string, error)

ArtifactDownloadURL returns the short-lived (~1 minute) presigned URL for an artifact's .zip. GitHub requires a token for this even on public repositories, so unlike the lookups it never retries anonymously.

func FindWorkflowArtifact added in v1.25.5

func FindWorkflowArtifact(owner, repo, workflowFile, artifactName string, filter WorkflowRunFilter) (int64, error)

FindWorkflowArtifact finds the newest successful run of workflowFile matching filter and returns the ID of its artifact named artifactName. Listing runs and artifacts works anonymously for public repositories, subject to GitHub's unauthenticated rate limit.

func GetCommitSHA added in v1.25.5

func GetCommitSHA(owner, repo, ref string) (string, error)

GetCommitSHA returns the full SHA that ref, such as an abbreviated SHA, points to.

func GetGitHubHeaders added in v1.24.8

func GetGitHubHeaders(requestURL string) map[string]string

GetGitHubHeaders returns headers to be used in GitHub REST API requests if the URL is for GitHub. See https://docs.github.com/en/rest/authentication/authenticating-to-the-rest-api

func GetGitHubRelease added in v1.24.8

func GetGitHubRelease(owner, repo, requestedVersion string) (tarballURL, downloadedRelease string, err error)

GetGitHubRelease gets the tarball URL and version for a GitHub repository release. With an empty requestedVersion it returns the release GitHub marks as latest, or the newest non-draft release when every release is a prerelease.

func GetGitHubToken added in v1.24.8

func GetGitHubToken() (string, string)

GetGitHubToken returns the GitHub token from the environment and the name of the variable it was found in.

func GetLatestRelease added in v1.25.5

func GetLatestRelease(owner, repo string) (tag, htmlURL string, err error)

GetLatestRelease returns the tag name and HTML page URL of the latest release for owner/repo. It uses GitHub's "latest release" endpoint, which excludes drafts and prereleases.

func GetPullRequestHeadSHA added in v1.25.4

func GetPullRequestHeadSHA(owner, repo string, number int) (string, error)

GetPullRequestHeadSHA returns the head commit SHA of a pull request.

func HasGitHubToken added in v1.24.9

func HasGitHubToken() bool

HasGitHubToken returns true if a GitHub token is set in the environment.

func HasInvalidGitHubToken added in v1.24.9

func HasInvalidGitHubToken(response any) error

HasInvalidGitHubToken checks if the response indicates an invalid GitHub token. This is possible if we get 401 or 404 response.

func NightlyLinkArtifactURL added in v1.25.4

func NightlyLinkArtifactURL(owner, repo string, artifactID int64) string

NightlyLinkArtifactURL returns the nightly.link URL for a specific artifact ID. nightly.link is a third-party service that serves GitHub Actions artifacts for public repositories without requiring authentication.

func PullRequestArtifactURL added in v1.25.4

func PullRequestArtifactURL(owner, repo string, number int, artifactName string) (string, error)

PullRequestArtifactURL returns a nightly.link download URL for artifactName by reading the pull request's HTML page and extracting the link posted there by the pr-artifacts-comment workflow. It uses no GitHub API token or API-rate budget, so it is a useful fallback when the API is rate-limited, but it works only for public repositories and only once that bot comment exists (that is, after the PR's build has finished).

Types

type Client added in v1.24.8

type Client = github.Client

func GetGitHubClient added in v1.24.8

func GetGitHubClient(withAuth bool) (context.Context, *Client, error)

GetGitHubClient returns a context and a singleton GitHub client, initializing it once. With withAuth, it returns the token-authenticated client; otherwise the no-auth client. The returned error is non-nil if the requested client failed to initialize.

type ListOptions added in v1.24.8

type ListOptions = github.ListOptions

type Repository added in v1.24.8

type Repository = github.Repository

type SearchOptions added in v1.24.8

type SearchOptions = github.SearchOptions

type WorkflowRunFilter added in v1.25.4

type WorkflowRunFilter struct {
	Branch  string
	HeadSHA string
}

WorkflowRunFilter selects a GitHub Actions workflow run by branch and/or head SHA.

Jump to

Keyboard shortcuts

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