github

package
v0.16.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option = gogithub.ClientOptionsFunc

Option configures New.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL points the client at another API root: a GitHub Enterprise Server, or a test server.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets the HTTP client the requests go through.

type Remote

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

Remote is the Remote for github.com (or a GitHub Enterprise Server) acting with the token the caller supplies. It talks REST through google/go-github, never a git or sops binary.

func New

func New(token string, opts ...Option) (*Remote, error)

New builds the Remote from the caller's token. The token is the caller's; the module keeps none of its own.

func NewWithClient

func NewWithClient(hc *http.Client, opts ...Option) (*Remote, error)

NewWithClient builds the Remote on an HTTP client that already carries the caller's identity — a GitHub App installation transport, a rotated token file — so no token string changes hands. The module adds no credential of its own to it.

func (*Remote) Approve

func (g *Remote) Approve(ctx context.Context, pr forge.PullRequest, body string) error

Approve submits an approving review on the pull request with the caller's identity, pinned to pr.HeadSHA when the caller names it. GitHub applies its own rules to the call: the author of a pull request cannot approve it.

func (*Remote) CanReadRepository

func (g *Remote) CanReadRepository(ctx context.Context, repo forge.Repository) (bool, error)

CanReadRepository implements forge.RepositoryAccess with GET /repos/{owner}/{repo}: 404 is false, a refused token an AuthError.

func (*Remote) Close

func (g *Remote) Close(ctx context.Context, pr forge.PullRequest, deleteBranch bool) error

Close closes the pull request and, when asked, deletes its head branch. A pull request that is closed already (merged or not) is left as it is.

func (*Remote) Commit

func (g *Remote) Commit(ctx context.Context, repo forge.Repository, branch, message string, files map[string][]byte) error

Commit writes one commit with files on top of branch: blobs, a tree on the head's tree, the commit, and a fast-forward of the branch. A nil content removes the path from the tree.

func (*Remote) CommitURL

func (g *Remote) CommitURL(repo forge.Repository, sha string) string

CommitURL implements forge.Linker.

func (*Remote) CreateBranch

func (g *Remote) CreateBranch(ctx context.Context, repo forge.Repository, branch, base string) error

CreateBranch creates branch at base's head, or at base when it is a commit SHA. An existing branch (GitHub answers 422 to the create) is brought up to date with base instead.

func (*Remote) EnableAutoMerge

func (g *Remote) EnableAutoMerge(ctx context.Context, pr forge.PullRequest) error

EnableAutoMerge arms GitHub's auto-merge on the pull request with the repository's merge method. Auto-merge is GraphQL-only; the mutation goes through the same client and identity as every other call.

func (*Remote) FileURL

func (g *Remote) FileURL(repo forge.Repository, ref, path string) string

FileURL implements forge.Linker.

func (*Remote) FindPullRequest

func (g *Remote) FindPullRequest(ctx context.Context, repo forge.Repository, head string) (forge.PullRequest, bool, error)

FindPullRequest returns the open pull request of head, if there is one.

func (*Remote) FindPullRequestsByPrefix

func (g *Remote) FindPullRequestsByPrefix(ctx context.Context, repo forge.Repository, prefix string) ([]forge.PullRequest, error)

FindPullRequestsByPrefix lists the repository's open pull requests page by page and keeps those whose head branch starts with prefix and lives in the repository itself: GitHub's head filter takes an exact branch name only. The head is the repository's own when its repository ID is the base's; a fork's pull request, or one whose fork was deleted, is left out. The pages are read oldest first, so a pull request opened during the read goes to the last page and shifts none of the pages still to read.

func (*Remote) Head

func (g *Remote) Head(ctx context.Context, repo forge.Repository, branch string) (string, error)

Head returns the SHA of the commit at the head of branch, from the branch's ref.

func (*Remote) ListFiles

func (g *Remote) ListFiles(ctx context.Context, repo forge.Repository, ref, dir string) ([]string, error)

ListFiles returns the files under dir at ref — a branch's head or a commit — from its recursive Git tree. A tree GitHub truncates is an error, never a partial answer. A commit SHA GitHub does not find is ErrFileNotFound; a missing branch stays the error GitHub answers.

func (*Remote) Merge

func (g *Remote) Merge(ctx context.Context, pr forge.PullRequest) error

Merge merges the pull request with the repository's merge method (squash where allowed, else merge commit, else rebase), only if the head is still pr.HeadSHA. GitHub applies its own protection rules to the call.

func (*Remote) MergedFiles

func (g *Remote) MergedFiles(ctx context.Context, pr forge.PullRequest) ([]forge.FileChange, error)

MergedFiles lists the merged pull request's files through GitHub's pull request files endpoint, page by page. GitHub lists at most 3000 files; a listing shorter than the pull request's changed-file count is an error, never a partial answer.

func (*Remote) OpenDraftPullRequest

func (g *Remote) OpenDraftPullRequest(ctx context.Context, repo forge.Repository, head, base, title, body string) (forge.PullRequest, error)

OpenDraftPullRequest is OpenPullRequest as a draft.

func (*Remote) OpenPullRequest

func (g *Remote) OpenPullRequest(ctx context.Context, repo forge.Repository, head, base, title, body string) (forge.PullRequest, error)

OpenPullRequest opens head against base with the caller's title and body. When head already has an open pull request, that one is returned.

func (*Remote) ReadFile

func (g *Remote) ReadFile(ctx context.Context, repo forge.Repository, ref, path string) ([]byte, error)

ReadFile returns the content of path at ref — a branch's head or a commit — through the Git blob so a file past the contents API's 1 MB inline limit reads whole. GitHub answers 404 for a missing path and for a missing commit alike.

func (*Remote) Revert

func (g *Remote) Revert(ctx context.Context, pr forge.PullRequest, body string, overrides map[string][]byte) (forge.PullRequest, error)

Revert opens a pull request undoing the merged pr: the merge commit's diff against its first parent, inverted into one commit on branch revert-<number>-<head>. The branch is brought into existence or up to date with the pull request's base the way CreateBranch does — ErrStaleBranch when the base does not merge into it — and the commit lands on its head, so a second revert adds a commit to the open revert pull request.

func (*Remote) Status

func (g *Remote) Status(ctx context.Context, pr forge.PullRequest) (forge.Status, error)

Status reads the pull request, its reviews, and the statuses and check runs of its head.

Jump to

Keyboard shortcuts

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