githubclient

package
v8.82.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsExecution

func IsExecution(err error) bool

IsExecution asserts executionError.

func IsInstallationNotFound

func IsInstallationNotFound(err error) bool

IsInstallationNotFound asserts installationNotFoundError.

func IsInvalidConfig

func IsInvalidConfig(err error) bool

IsInvalidConfig asserts invalidConfigError.

func IsMergeDeclined added in v8.82.0

func IsMergeDeclined(err error) bool

IsMergeDeclined asserts mergeDeclinedError: GitHub declined the merge as the pull request stands (405, a rule or the merge box blocks it; 409, the head moved since it was judged). Its message is GitHub's.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound asserts notFoundError.

func IsPRMergeTimeout

func IsPRMergeTimeout(err error) bool

IsPRMergeTimeout asserts prMergeTimeoutError.

func NewConditional added in v8.79.0

func NewConditional(config Config) (*Client, *Conditional, error)

NewConditional is New for a poll loop: every GET is a conditional request through a Conditional, whose Rate the caller reads for its interval. The client is read-only in practice (DryRun is not applied) and config.BaseURL is used as given, with no /api/v3/ suffix: it names the REST API root itself (api.github.com, or a test double serving /repos/... at its root).

Types

type Client

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

func New

func New(config Config) (*Client, error)

func (*Client) AddRepoToRenovatePermissions

func (c *Client) AddRepoToRenovatePermissions(ctx context.Context, org string, repo *github.Repository) error

Add repository to the Renovate installation. Corresponds to https://docs.github.com/en/rest/apps/installations?apiVersion=2022-11-28#add-a-repository-to-an-app-installation

func (*Client) CheckRunsForRef added in v8.79.0

func (c *Client) CheckRunsForRef(ctx context.Context, owner, repo, ref string) ([]*github.CheckRun, error)

CheckRunsForRef returns the check runs of ref as the merge box lists them: the latest run per check name and app (GitHub's filter=latest), every page.

func (*Client) CloneRepository

func (c *Client) CloneRepository(ctx context.Context, owner, repo, workDir string) error

func (*Client) CommitAndPush

func (c *Client) CommitAndPush(ctx context.Context, owner, repo, branch, message string) error

func (*Client) CommitStatuses added in v8.79.0

func (c *Client) CommitStatuses(ctx context.Context, owner, repo, ref string) ([]*github.RepoStatus, error)

CommitStatuses returns the commit statuses of ref, the latest per context (the combined status), every page.

func (*Client) CreateBranch

func (c *Client) CreateBranch(ctx context.Context, newBranch string) error

func (*Client) CreateFromTemplate

func (c *Client) CreateFromTemplate(ctx context.Context, templateOwner, templateRepo, newOwner string, repository *github.Repository) (*github.Repository, error)

func (*Client) CreatePullRequest

func (c *Client) CreatePullRequest(ctx context.Context, owner, repo, head, title string) (*github.PullRequest, error)

func (*Client) CurrentLogin added in v8.82.0

func (c *Client) CurrentLogin(ctx context.Context) (string, error)

CurrentLogin is the login the token acts as (GET /user).

func (*Client) DeleteBranch added in v8.82.0

func (c *Client) DeleteBranch(ctx context.Context, owner, repo, branch string) error

DeleteBranch deletes refs/heads/branch through the refs API. A branch that is gone already (GitHub deleted it on merge, or answers 404) is not an error: the outcome is the same.

func (*Client) EnqueuePullRequest added in v8.82.0

func (c *Client) EnqueuePullRequest(ctx context.Context, nodeID string) error

EnqueuePullRequest adds the pull request to its base's merge queue: the GraphQL mutation enqueuePullRequest, REST has no call for it. The endpoint is <REST root>/graphql, api.github.com's layout. The queue merges when its checks pass; the caller waits on the pull request.

func (*Client) FileExists added in v8.79.0

func (c *Client) FileExists(ctx context.Context, owner, repo, path, ref string) (bool, error)

FileExists says whether path is a file at ref.

func (*Client) FindTagForCommit added in v8.81.0

func (c *Client) FindTagForCommit(ctx context.Context, owner, repo, sha string) (string, error)

FindTagForCommit returns the newest tag pointing at sha, or "" when the newest tags do not include one.

func (*Client) GetFile

func (c *Client) GetFile(ctx context.Context, owner, repo, path, ref string) (RepositoryFile, error)

func (*Client) GetPullRequestMerge added in v8.81.0

func (c *Client) GetPullRequestMerge(ctx context.Context, owner, repo string, number int) (PullRequestMerge, error)

GetPullRequestMerge returns the merge state of a pull request.

func (*Client) GetReleaseByTag added in v8.81.0

func (c *Client) GetReleaseByTag(ctx context.Context, owner, repo, tag string) (Release, error)

GetReleaseByTag returns the release of a tag; IsNotFound when there is none.

func (*Client) GetRepository

func (c *Client) GetRepository(ctx context.Context, owner, repo string) (*github.Repository, error)

func (*Client) GetTagSHA added in v8.81.0

func (c *Client) GetTagSHA(ctx context.Context, owner, repo, tag string) (string, error)

GetTagSHA returns the commit a tag points at, through an annotated tag object when the tag is one. IsNotFound when the tag does not exist.

func (*Client) GetUnderlyingClient

func (c *Client) GetUnderlyingClient(ctx context.Context) *github.Client

GetUnderlyingClient returns the underlying go-github client.

func (*Client) GitHub added in v8.82.0

func (c *Client) GitHub() *github.Client

GitHub is the underlying go-github client, for the packages that take one (pkg/reposetup's Remote). It shares the token and the transport.

func (*Client) IsPrivateRepository added in v8.81.0

func (c *Client) IsPrivateRepository(ctx context.Context, owner, repo string) (bool, error)

IsPrivateRepository says whether owner/repo is private.

func (*Client) ListDirectory added in v8.81.0

func (c *Client) ListDirectory(ctx context.Context, owner, repo, path, ref string) ([]string, error)

ListDirectory returns the names of the entries of a directory at ref (files and directories alike). IsNotFound when the path does not exist.

func (*Client) ListRepositories

func (c *Client) ListRepositories(ctx context.Context, owner string) ([]Repository, error)

func (*Client) ListWorkflowRunsForSHA added in v8.81.0

func (c *Client) ListWorkflowRunsForSHA(ctx context.Context, owner, repo, sha string) ([]WorkflowRun, error)

ListWorkflowRunsForSHA returns the Actions runs on a commit, newest first, as WorkflowRun values.

func (*Client) MergePullRequest added in v8.82.0

func (c *Client) MergePullRequest(ctx context.Context, owner, repo string, number int, opts MergeOptions) (string, error)

MergePullRequest merges the pull request through the merge API and returns the merge commit's SHA. GitHub's refusal of the merge as the pull request stands is IsMergeDeclined; anything else is a tooling failure.

func (*Client) MergeQueueRequired added in v8.82.0

func (c *Client) MergeQueueRequired(ctx context.Context, owner, repo, branch string) (bool, error)

MergeQueueRequired says whether a merge queue rule is in effect on branch: the rules endpoint of the branch lists one of type merge_queue. A repository whose rules the token may not read has none.

func (*Client) PullRequest added in v8.79.0

func (c *Client) PullRequest(ctx context.Context, owner, repo string, number int) (*github.PullRequest, error)

PullRequest returns the pull request as GitHub sees it now: state, draft, mergeable state, head and base.

func (*Client) RemoveRepoFromRenovatePermissions

func (c *Client) RemoveRepoFromRenovatePermissions(ctx context.Context, org string, repo *github.Repository) error

Remove repository from the Renovate installation. Corresponds to https://docs.github.com/en/rest/apps/installations?apiVersion=2022-11-28#remove-a-repository-from-an-app-installation

func (*Client) RemoveRepositoryBranchProtection

func (c *Client) RemoveRepositoryBranchProtection(ctx context.Context, repository *github.Repository) (err error)

func (*Client) ReportedChecks added in v8.49.0

func (c *Client) ReportedChecks(ctx context.Context, repository *github.Repository, branch string) ([]string, error)

ReportedChecks returns the names of the commit status contexts and the completed, non-skipped check runs observed on the latest non-tag commit of branch and on the heads of the most recently merged pull requests: the checks that demonstrably run in this repository. Callers use it to require a check only once it exists (devctl repo checks --checks-if-reported).

func (*Client) RequiredStatusContexts added in v8.79.0

func (c *Client) RequiredStatusContexts(ctx context.Context, owner, repo, branch string) ([]string, error)

RequiredStatusContexts returns the status contexts branch requires before a merge: the required status checks of its branch protection and of every ruleset in effect on it, sorted and without duplicates. A protection the token may not read (404: none, or 403: no admin access) contributes nothing; the rules endpoint answers for everyone with read access.

func (*Client) SetRepositoryBranchProtection

func (c *Client) SetRepositoryBranchProtection(ctx context.Context, repository *github.Repository, checkNames []string, checksFilter *regexp.Regexp) (err error)

func (*Client) SetRepositoryDefaultBranch

func (c *Client) SetRepositoryDefaultBranch(ctx context.Context, repository *github.Repository, newDefaultBranch string) (err error)

func (*Client) SetRepositoryPermissions

func (c *Client) SetRepositoryPermissions(ctx context.Context, repository *github.Repository, permissions map[string]string) error

func (*Client) SetRepositorySettings

func (c *Client) SetRepositorySettings(ctx context.Context, repository, repositorySettings *github.Repository) (*github.Repository, error)

func (*Client) SetRepositoryWebhooks

func (c *Client) SetRepositoryWebhooks(ctx context.Context, repository *github.Repository, hook *github.Hook) error

func (*Client) UpdatePullRequestBranch added in v8.82.0

func (c *Client) UpdatePullRequestBranch(ctx context.Context, owner, repo string, number int, expectedHeadSHA string) error

UpdatePullRequestBranch asks GitHub to merge the base into the head (the "Update branch" button). GitHub schedules it and answers 202; the new head appears on the pull request a moment later. expectedHeadSHA guards against updating a head that moved meanwhile.

func (*Client) WaitForPRMerge

func (c *Client) WaitForPRMerge(ctx context.Context, owner, repo string, prNumber int, timeout time.Duration) error

func (*Client) WorkflowRunsForSHA added in v8.79.0

func (c *Client) WorkflowRunsForSHA(ctx context.Context, owner, repo, sha string) ([]*github.WorkflowRun, error)

WorkflowRunsForSHA returns every GitHub Actions run of the head SHA, whatever its status, every page.

type Conditional added in v8.79.0

type Conditional struct {
	// Base sends the requests; nil means http.DefaultTransport.
	Base http.RoundTripper
	// contains filtered or unexported fields
}

Conditional is an http.RoundTripper that makes every GET a conditional request: it keeps the ETag and body of the last 200 per URL, sends the tag as If-None-Match and replays the kept body when GitHub answers 304 Not Modified. A 304 does not count against the rate limit, so a poll loop that sees no change costs nothing; go-github never sees the 304, it reads a 200 with the same body as before.

It also remembers the rate-limit headers of the newest answer, 304 or not, so a poll loop derives its interval from real responses and never asks the rate_limit endpoint.

func (*Conditional) Rate added in v8.79.0

func (c *Conditional) Rate() RateLimit

Rate is the budget the newest response reported.

func (*Conditional) Replayed added in v8.79.0

func (c *Conditional) Replayed() int

Replayed is how many 304 answers were replayed from the cache.

func (*Conditional) RoundTrip added in v8.79.0

func (c *Conditional) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

type Config

type Config struct {
	Logger      *logrus.Logger
	AccessToken string
	DryRun      bool
	// BaseURL points the client at another GitHub API host (an enterprise
	// instance, a test double); empty means api.github.com.
	BaseURL string
}

type MergeMethod added in v8.82.0

type MergeMethod string

MergeMethod is how the head lands on the base.

const (
	// MergeSquash lands the head as one commit.
	MergeSquash MergeMethod = "squash"
	// MergeRebase lands every commit of the head, rebased.
	MergeRebase MergeMethod = "rebase"
)

type MergeOptions added in v8.82.0

type MergeOptions struct {
	// Method is squash or rebase.
	Method MergeMethod
	// HeadSHA is the head the merge is for: GitHub refuses (409) when the
	// head moved since it was judged.
	HeadSHA string
	// CommitTitle is the squash commit's subject; empty leaves GitHub's
	// default. A rebase merge keeps the commits' own subjects.
	CommitTitle string
}

MergeOptions configure Client.MergePullRequest.

type PullRequestMerge added in v8.81.0

type PullRequestMerge struct {
	Number int
	State  string
	Merged bool
	// MergeCommitSHA is the commit on the base branch; empty until merged.
	MergeCommitSHA string
	MergedAt       time.Time
}

PullRequestMerge is what release wait reads of a pull request.

type RateLimit added in v8.79.0

type RateLimit struct {
	// Known is false before the first response with rate-limit headers.
	Known     bool
	Remaining int
	Reset     time.Time
}

RateLimit is what the newest response said about the budget.

type Release added in v8.81.0

type Release struct {
	URL string
	// Published: not a draft.
	Published bool
	Assets    []ReleaseAsset
}

Release is a GitHub release as release wait reads it.

type ReleaseAsset added in v8.81.0

type ReleaseAsset struct {
	Name   string
	URL    string
	Digest string
}

ReleaseAsset is one uploaded asset with the digest GitHub reports for it.

type Repository

type Repository struct {
	Name      string
	Language  string
	Owner     string
	UpdatedAt time.Time
}

type RepositoryFile

type RepositoryFile struct {
	Data []byte
	Path string
}

type WorkflowRun added in v8.81.0

type WorkflowRun struct {
	Name       string
	ID         int64
	Event      string
	HeadBranch string
	Status     string
	Conclusion string
	URL        string
	CreatedAt  time.Time
}

WorkflowRun is one GitHub Actions run.

Jump to

Keyboard shortcuts

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