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

github

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package github is the GitHub adapter: the only code in Ghostbranch that imports a GitHub API client.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoToken = errors.New("github: no token")

ErrNoToken means New was given an empty token. Ghostbranch never builds an unauthenticated client: it would read public repos and then fail on private ones with confusing 404s.

Functions

This section is empty.

Types

type Client

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

func New

func New(token string) (*Client, error)

New returns a client for api.github.com. The token is trimmed.

func NewWithBaseURL

func NewWithBaseURL(token, baseURL string) (*Client, error)

NewWithBaseURL points the client at another API root (tests).

func (*Client) AddToStack

func (c *Client) AddToStack(ctx context.Context, full string, stack int, prs []int) (forge.Stack, error)

AddToStack appends prs, bottom first, to stack number stack (forge.Stacker): POST /repos/{o}/{r}/stacks/{n}/add.

func (*Client) CancelRun

func (c *Client) CancelRun(ctx context.Context, full string, id int64) error

CancelRun asks GitHub to cancel workflow run id. GitHub answers 202, which only accepts the request; a 409 (forge.ErrConflict) means GitHub won't cancel the run in its current state, often because it has finished.

func (*Client) ChecksLimited

func (c *Client) ChecksLimited(full string) bool

ChecksLimited reports whether ListChecks had to fall back to workflow runs for full because the token cannot read check runs. Third-party check apps are invisible in that mode.

func (*Client) ClosePullRequest

func (c *Client) ClosePullRequest(ctx context.Context, full string, number int) error

ClosePullRequest closes PR number. Closing a closed PR is a no-op on GitHub; a plain 403 is forge.ErrForbidden.

func (*Client) CreatePR

func (c *Client) CreatePR(ctx context.Context, full string, in forge.NewPR) (forge.PR, error)

func (*Client) CreatePrivateRepo

func (c *Client) CreatePrivateRepo(ctx context.Context, full string) (forge.Repo, error)

func (*Client) CreateStack

func (c *Client) CreateStack(ctx context.Context, full string, prs []int) (forge.Stack, error)

CreateStack makes a native stack of prs, bottom first (forge.Stacker): POST /repos/{o}/{r}/stacks.

func (*Client) CurrentUser

func (c *Client) CurrentUser(ctx context.Context) (forge.User, error)

func (*Client) EditPR

func (c *Client) EditPR(ctx context.Context, full string, number int, title, body *string) error

EditPR changes PR number's title and body; a nil field is not sent, so GitHub leaves it as it is. A plain 403 is forge.ErrForbidden.

func (*Client) FindOpenPR

func (c *Client) FindOpenPR(ctx context.Context, full, head, base string) (*forge.PR, error)

func (*Client) ForceCancelRun

func (c *Client) ForceCancelRun(ctx context.Context, full string, id int64) error

ForceCancelRun force-cancels workflow run id, for a run that ignored CancelRun. go-github has no wrapper, so this is a raw request; GitHub answers 202.

func (*Client) GetPR

func (c *Client) GetPR(ctx context.Context, full string, number int) (forge.PR, error)

func (*Client) GetRepo

func (c *Client) GetRepo(ctx context.Context, full string) (forge.Repo, error)

func (*Client) InstallationRepos added in v0.2.0

func (c *Client) InstallationRepos(ctx context.Context, id int64) ([]string, error)

InstallationRepos lists the repos installation id covers that the user can also access (forge.Installer): GET /user/installations/{id}/repositories, every page.

func (*Client) ListChecks

func (c *Client) ListChecks(ctx context.Context, full, sha string) ([]forge.Check, error)

ListChecks merges check runs and legacy commit statuses for sha.

func (*Client) OAuthScopes

func (c *Client) OAuthScopes(ctx context.Context) ([]string, bool, error)

OAuthScopes reads a classic token's scopes from GET /user's X-OAuth-Scopes header (forge.PermissionProber).

func (*Client) ProbePermissions

func (c *Client) ProbePermissions(ctx context.Context, full string) (forge.RepoPermissions, error)

ProbePermissions learns what the token may do on full with read calls only (forge.PermissionProber). A fine-grained token can't be asked what it may write, so only Contents: write is probed, through PushAccess.

func (*Client) PushAccess

func (c *Client) PushAccess(ctx context.Context, full string) forge.PushAccess

PushAccess asks GitHub's git endpoint for push discovery. GitHub answers 200 only when the token may write, and 403 when it may not. Nothing is pushed. The REST permissions field is not used: it reflects the user's role, not what a fine-grained token may do.

func (*Client) PushRuns

func (c *Client) PushRuns(ctx context.Context, full, sha string) ([]forge.Run, error)

PushRuns lists the Actions runs for sha that a push started, any status.

func (*Client) SecretNames

func (c *Client) SecretNames(ctx context.Context, full string) ([]string, error)

SecretNames lists the Actions secret names of full and the org secrets shared with it, sorted and de-duplicated. Values are never read. A user repo has no org secrets, so a 404 on that listing is not an error.

func (*Client) SetDefaultBranch

func (c *Client) SetDefaultBranch(ctx context.Context, full, branch string) error

func (*Client) StackOf

func (c *Client) StackOf(ctx context.Context, full string, pr int) (*forge.Stack, error)

StackOf is the stack PR pr is in (forge.Stacker). The PR carries its stack's number even once merged; a PR without one, as on a host without native stacks, is nil, and so is one whose stack dissolved between the two reads (the stack is a 404).

func (*Client) UserInstallations added in v0.2.0

func (c *Client) UserInstallations(ctx context.Context) ([]forge.Installation, error)

UserInstallations lists the app's installs the user can see (forge.Installer): GET /user/installations, every page.

func (*Client) WithGitBase

func (c *Client) WithGitBase(base string) *Client

WithGitBase points git smart-HTTP probes at another host (tests).

Jump to

Keyboard shortcuts

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