Help us shape the future of Go! Take the 2026 Go Developer Survey

github

package
v0.0.0-...-855fa55 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package github adapts the GitHub REST API to the gate package's GitHub interface, authenticating as the pollux-agent GitHub App.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client creates GitHub check runs, authenticating per installation as the pollux-agent GitHub App.

func NewClient

func NewClient(httpClient *http.Client, appID int64, privateKeyPEM []byte, baseURL string) (*Client, error)

NewClient returns a Client that signs GitHub App JWTs with privateKeyPEM and authenticates installation requests through httpClient's transport. An empty baseURL targets the public GitHub API; tests pass an httptest URL.

func (*Client) BranchCommit

func (c *Client) BranchCommit(ctx context.Context, installationID int64, owner, repo, branch string) (gate.Commit, error)

BranchCommit returns the commit branch points at.

func (*Client) BranchSHA

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

BranchSHA returns the commit branch points at.

func (*Client) CommitAt

func (c *Client) CommitAt(ctx context.Context, installationID int64, owner, repo, sha string) (gate.Commit, error)

CommitAt returns the commit with the given SHA.

func (*Client) CommitFiles

func (c *Client) CommitFiles(ctx context.Context, installationID int64, owner, repo, branch, parentSHA string, files []gate.FileChange, message string) (string, error)

CommitFiles commits files on top of parentSHA and moves branch to the new commit with a non-force ref update. It returns gate.ErrBranchMoved when GitHub rejects the update because branch is no longer at parentSHA.

func (*Client) CreateBranch

func (c *Client) CreateBranch(ctx context.Context, installationID int64, owner, repo, branch, sha string) error

CreateBranch creates branch at sha. It returns gate.ErrBranchExists when the branch already exists.

func (*Client) CreateCheckRun

func (c *Client) CreateCheckRun(ctx context.Context, installationID int64, owner, repo string, run gate.CheckRun) (int64, error)

CreateCheckRun creates a check run on head_sha in owner/repo, authenticating as installationID, and returns its ID. An in-progress run carries no conclusion.

func (*Client) CreateIssueComment

func (c *Client) CreateIssueComment(ctx context.Context, installationID int64, owner, repo string, number int, body string) (gate.Comment, error)

CreateIssueComment creates a comment on the conversation of owner/repo#number.

func (*Client) CreatePullRequest

func (c *Client) CreatePullRequest(ctx context.Context, installationID int64, owner, repo string, pr gate.NewPullRequest) (gate.ScaffoldPR, error)

CreatePullRequest opens a pull request from pr.Head into pr.Base.

func (*Client) CreateReviewComment

func (c *Client) CreateReviewComment(ctx context.Context, installationID int64, owner, repo string, number int, rc gate.ReviewComment) (gate.Comment, error)

CreateReviewComment creates a review comment on the right side of rc.Path at rc.CommitSHA, or a file-level comment when rc.File is set.

func (*Client) DefaultBranch

func (c *Client) DefaultBranch(ctx context.Context, installationID int64, owner, repo string) (string, string, error)

DefaultBranch returns the name and tip commit of owner/repo's default branch.

func (*Client) Dispatch

func (c *Client) Dispatch(ctx context.Context, installationID int64, owner, repo string, in actions.DispatchInputs) (int64, error)

Dispatch runs the pollux-agent workflow on owner/repo's default branch and returns the ID of the run it started.

func (*Client) DocsAtRef

func (c *Client) DocsAtRef(ctx context.Context, installationID int64, owner, repo, ref string) (fs.FS, error)

DocsAtRef returns the .md files under docs/ of owner/repo at ref as a file system rooted at the repo root. Files over docs.MaxDocBytes are left out. It errors when the docs tree is truncated, when the root tree is truncated without a docs entry, or holds more than maxDocsAtRef docs.

func (*Client) DocsExist

func (c *Client) DocsExist(ctx context.Context, installationID int64, owner, repo, ref string) (bool, error)

DocsExist reports whether owner/repo has any entry named docs at ref: a directory, a file, or a submodule. Only a missing path is false.

func (*Client) EditIssueComment

func (c *Client) EditIssueComment(ctx context.Context, installationID int64, owner, repo string, id int64, body string) error

EditIssueComment replaces the body of issue comment id.

func (*Client) EditReviewComment

func (c *Client) EditReviewComment(ctx context.Context, installationID int64, owner, repo string, id int64, body string) error

EditReviewComment replaces the body of review comment id.

func (*Client) FileAtRef

func (c *Client) FileAtRef(ctx context.Context, installationID int64, owner, repo, path, ref string) (content []byte, ok bool, err error)

FileAtRef returns the content of the file at path in owner/repo at ref. ok is false when the path is not a file at ref or the file exceeds docs.MaxDocBytes.

func (*Client) FindPullRequest

func (c *Client) FindPullRequest(ctx context.Context, installationID int64, owner, repo, branch string) (gate.ScaffoldPR, bool, error)

FindPullRequest returns the pull request opened from branch of owner/repo itself, preferring this App's bot's (open first), then an open one, over the rest. ByBot is set when its author is this App's bot user.

func (*Client) GetPullRequest

func (c *Client) GetPullRequest(ctx context.Context, installationID int64, owner, repo string, number int) (gate.PullRequest, error)

GetPullRequest returns owner/repo#number's current base and head commits.

func (*Client) InstallationToken

func (c *Client) InstallationToken(ctx context.Context, installationID int64, repo string) (string, error)

InstallationToken returns a short-lived installation access token for installationID, narrowed to contents:read on repo (a name without owner), to authenticate a git clone outside the go-github client.

func (*Client) ListChangedFiles

func (c *Client) ListChangedFiles(ctx context.Context, installationID int64, owner, repo string, number int) ([]review.ChangedFile, error)

ListChangedFiles returns the files in owner/repo#number's diff. GitHub caps the listing at 3000 files, and omits the patch for large or binary files.

func (*Client) ListComments

func (c *Client) ListComments(ctx context.Context, installationID int64, owner, repo string, number int) ([]gate.Comment, error)

ListComments returns owner/repo#number's review comments, then its issue comments.

func (*Client) MergeBase

func (c *Client) MergeBase(ctx context.Context, installationID int64, owner, repo, base, head string) (string, error)

MergeBase returns the merge base commit of base and head in owner/repo.

func (*Client) PathAtRef

func (c *Client) PathAtRef(ctx context.Context, installationID int64, owner, repo, path, ref string) (exists, dir bool, err error)

PathAtRef reports what is at path itself in owner/repo at ref: nothing, a directory, or anything else (a file of any size, symlink, submodule). It does not look at parent paths.

func (*Client) Permission

func (c *Client) Permission(ctx context.Context, installationID int64, owner, repo, user string) (bool, error)

Permission reports whether user has admin, maintain or write access to owner/repo.

func (*Client) React

func (c *Client) React(ctx context.Context, installationID int64, owner, repo string, kind gate.CommentKind, id int64, reaction gate.Reaction) (int64, error)

React adds reaction to comment id and returns the reaction's ID; GitHub returns the existing reaction when this app already left it.

func (*Client) ReplyToReviewComment

func (c *Client) ReplyToReviewComment(ctx context.Context, installationID int64, owner, repo string, number int, inReplyTo int64, body string) (gate.Comment, error)

ReplyToReviewComment posts body as a reply in the thread of review comment inReplyTo.

func (*Client) ResetBranch

func (c *Client) ResetBranch(ctx context.Context, installationID int64, owner, repo, branch, sha string) error

ResetBranch force-moves an existing branch to sha.

func (*Client) ResolveReviewThread

func (c *Client) ResolveReviewThread(ctx context.Context, installationID int64, owner, repo string, number int, commentID int64) error

ResolveReviewThread resolves the review thread that contains review comment commentID, wherever GitHub lists it among the thread's comments. Threads are matched on their first 100 comments; a proposal thread never grows near that. A thread that is already resolved, or gone with its comment, is not an error.

func (*Client) ResultArtifact

func (c *Client) ResultArtifact(ctx context.Context, installationID int64, owner, repo string, runID int64) ([]byte, error)

ResultArtifact returns the result.json inside run runID's result artifact.

func (*Client) Unreact

func (c *Client) Unreact(ctx context.Context, installationID int64, owner, repo string, kind gate.CommentKind, id, reactionID int64) error

Unreact removes reaction reactionID from comment id; a reaction that is already gone is not an error.

func (*Client) UpdateCheckRun

func (c *Client) UpdateCheckRun(ctx context.Context, installationID int64, owner, repo string, id int64, run gate.CheckRun) error

UpdateCheckRun replaces check run id's status, conclusion and output.

func (*Client) WorkflowExists

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

WorkflowExists reports whether owner/repo's default branch has gate.WorkflowPath.

type UserClient

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

UserClient speaks to GitHub on behalf of a signed-in user: the OAuth code exchange, and user-token API calls.

func NewUserClient

func NewUserClient(httpClient *http.Client, clientID, clientSecret, oauthURL, apiURL string) *UserClient

NewUserClient returns a UserClient for the GitHub App's OAuth credentials. Empty oauthURL and apiURL target github.com; tests pass httptest URLs.

func (*UserClient) AccessibleRepos

func (c *UserClient) AccessibleRepos(ctx context.Context, accessToken string) ([]auth.Repo, error)

AccessibleRepos returns the repositories the user can read on every installation of the app the user can access. An installation that answers 403 or 404 (uninstalled, or an SSO org the token is not authorized for) is skipped.

func (*UserClient) AuthorizeURL

func (c *UserClient) AuthorizeURL() string

AuthorizeURL is where GitHub's OAuth authorization page lives.

func (*UserClient) Exchange

func (c *UserClient) Exchange(ctx context.Context, code, verifier, redirectURL string) (auth.Tokens, error)

Exchange trades an authorization code for the user's tokens. GitHub reports most failures as HTTP 200 with an "error" field, and some as 4xx; both wrap auth.ErrInvalidLogin.

func (UserClient) GoString

func (c UserClient) GoString() string

func (UserClient) LogValue

func (c UserClient) LogValue() slog.Value

func (*UserClient) Refresh

func (c *UserClient) Refresh(ctx context.Context, refreshToken string) (auth.Tokens, error)

Refresh trades a refresh token for a new token pair; GitHub rotates both. Only bad_refresh_token wraps auth.ErrRefreshRefused; every other failure is a plain error, so a transient one does not end the session.

func (*UserClient) Revoke

func (c *UserClient) Revoke(ctx context.Context, accessToken string) error

Revoke revokes one access token. The whole grant is left alone: it spans the user's other sessions, and this session's refresh token dies with its row.

func (UserClient) String

func (c UserClient) String() string

String and LogValue keep the client secret out of logs and error text.

func (*UserClient) User

func (c *UserClient) User(ctx context.Context, accessToken string) (auth.Profile, error)

User returns the user the access token belongs to.

Jump to

Keyboard shortcuts

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