Documentation
¶
Index ¶
- type Option
- type Remote
- func (g *Remote) Approve(ctx context.Context, pr commit.PullRequest, body string) error
- func (g *Remote) Close(ctx context.Context, pr commit.PullRequest, deleteBranch bool) error
- func (g *Remote) Commit(ctx context.Context, repo commit.Repository, branch, message string, ...) error
- func (g *Remote) CreateBranch(ctx context.Context, repo commit.Repository, branch, base string) error
- func (g *Remote) EnableAutoMerge(ctx context.Context, pr commit.PullRequest) error
- func (g *Remote) FindPullRequest(ctx context.Context, repo commit.Repository, head string) (commit.PullRequest, bool, error)
- func (g *Remote) FindPullRequestsByPrefix(ctx context.Context, repo commit.Repository, prefix string) ([]commit.PullRequest, error)
- func (g *Remote) Head(ctx context.Context, repo commit.Repository, branch string) (string, error)
- func (g *Remote) ListFiles(ctx context.Context, repo commit.Repository, ref, dir string) ([]string, error)
- func (g *Remote) Merge(ctx context.Context, pr commit.PullRequest) error
- func (g *Remote) MergedFiles(ctx context.Context, pr commit.PullRequest) ([]commit.FileChange, error)
- func (g *Remote) OpenDraftPullRequest(ctx context.Context, repo commit.Repository, head, base, title, body string) (commit.PullRequest, error)
- func (g *Remote) OpenPullRequest(ctx context.Context, repo commit.Repository, head, base, title, body string) (commit.PullRequest, error)
- func (g *Remote) ReadFile(ctx context.Context, repo commit.Repository, ref, path string) ([]byte, error)
- func (g *Remote) Revert(ctx context.Context, pr commit.PullRequest, body string, ...) (commit.PullRequest, error)
- func (g *Remote) Status(ctx context.Context, pr commit.PullRequest) (commit.Status, error)
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 ¶
WithBaseURL points the client at another API root: a GitHub Enterprise Server, or a test server.
func WithHTTPClient ¶
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 ¶
New builds the Remote from the caller's token. The token is the caller's; the module keeps none of its own.
func NewWithClient ¶
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 ¶
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) Close ¶
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 commit.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) CreateBranch ¶
func (g *Remote) CreateBranch(ctx context.Context, repo commit.Repository, branch, base string) error
CreateBranch creates branch at base's head. An existing branch (GitHub answers 422 to the create) is brought up to date with base instead.
func (*Remote) EnableAutoMerge ¶
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) FindPullRequest ¶
func (g *Remote) FindPullRequest(ctx context.Context, repo commit.Repository, head string) (commit.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 commit.Repository, prefix string) ([]commit.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 ¶
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 commit.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 ¶
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 commit.PullRequest) ([]commit.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 commit.Repository, head, base, title, body string) (commit.PullRequest, error)
OpenDraftPullRequest is OpenPullRequest as a draft.
func (*Remote) OpenPullRequest ¶
func (g *Remote) OpenPullRequest(ctx context.Context, repo commit.Repository, head, base, title, body string) (commit.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 commit.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 commit.PullRequest, body string, overrides map[string][]byte) (commit.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.