github

package
v0.40.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 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

Overview

Package github is the broker's GitHub App client (SP2 design §3, ruling P28). It posts an agent's review verdict as one pull request comment, as SP3's factory App, and reads who a GitHub user is and what they may read, for room visibility (D7).

Index

Constants

This section is empty.

Variables

View Source
var ErrNoInstallation = errors.New("github: the App is not installed on the repository, or it does not exist")

ErrNoInstallation reports a repository GitHub knows no installation of the App on: it does not exist, or the App is not installed there. It wraps GitHub's 404, which stays permanent.

View Source
var ErrNotAPullRequest = errors.New("github: not a GitHub pull request URL")

ErrNotAPullRequest reports a URL that is not a GitHub pull request's.

View Source
var ErrTooManyComments = errors.New("github: too many comments to search for the marker")

ErrTooManyComments reports a pull request with more comments than the client searches, so it cannot know whether the App already posted, and does not post.

Functions

func Permanent

func Permanent(err error) bool

Permanent reports an error a retry cannot heal: GitHub's 4xx other than a rate limit or a 401, a URL that names no pull request, or one too long to search. A key that cannot be read, that is no App id's, or that GitHub rejects is not: the owner's Secret can still land or be fixed (ruling SZ).

func Quote

func Quote(s string) string

Quote makes untrusted text, an agent's verdict summary, inert in a pull request comment: a fenced code block that nothing in the text can close, because its fence is longer than any run of backticks the text holds. GitHub renders a code block as text only: no mention notifies anyone, no cross-reference (a URL, #N, GH-N, owner/repo#N, a SHA) backlinks another issue, no image loads and no HTML renders, a marker included (reviews 3.4 I1, 3.5 m3). Hidden characters go first: format and control characters but newline and tab, every other default-ignorable code point and the variation selectors (bidi overrides, zero-width joiners, the BOM, soft hyphens, escapes).

Types

type APIError

type APIError struct {
	Status      int
	Path        string
	RateLimited bool
	RetryAfter  time.Duration
}

APIError is a GitHub answer outside 2xx. It names the status and path only: a reply body can quote a credential. RateLimited marks a 403 or 429 that is GitHub's primary or secondary rate limit, and RetryAfter is when it lifts, when GitHub says.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Permanent

func (e *APIError) Permanent() bool

Permanent reports a 4xx other than a rate limit or a 401, which a retry does not heal (the App is not installed, the pull request is gone, the comment is refused). A 401 that survives Comment's fresh-token retry is a key GitHub rejects, which the operator can fix (ruling SZ).

type App

type App struct {
	Dir string
	API string
	HC  *http.Client
	Now func() time.Time
	// contains filtered or unexported fields
}

App reads its id and key from Dir (app_id, private_key) at every mint. Dir is an optional Secret volume that kubelet fills once the owner has written the key (ruling P31), so the broker needs no restart and has no startup race. API is GitHub's https API base, HC the httpx egress client, Now the clock: all three are required.

func (*App) Comment

func (a *App) Comment(ctx context.Context, pr, marker, body string) (string, error)

Comment posts body, then marker, on the pull request, once. The App's own comment that already ends with marker is returned instead: a retry after a crash, or a new leader. Another author's copy of the marker never counts. Calls for one marker run one at a time; other markers are not held up.

func (*App) Enabled

func (a *App) Enabled() bool

Enabled reports whether the App's key has landed in Dir.

func (*App) Permission

func (a *App) Permission(ctx context.Context, owner, repo, login string) (string, error)

Permission is login's permission on owner/repo as GitHub's collaborator API states it (admin, write, read or none), read with owner/repo's installation token, which metadata: read covers. GitHub's 404, a login it does not know or one with no access, is "none"; any other refusal is an error, never an answer, so the caller fails closed.

func (*App) Repository added in v0.35.0

func (a *App) Repository(ctx context.Context, owner, repo string) (Repository, error)

Repository is owner/repo's visibility, read with its installation token, which metadata: read covers. It is the planner's public-only read (CD5, v3.x conversational intake): public text only, decided once per repository by the caller's cache rather than by a model.

A repository GitHub does not show the App — no installation, or a 404 for its scoped token — is ErrNoInstallation, and a reply with no visibility word is an error: neither is an answer, so the caller refuses rather than planning on a guess.

func (*App) UserLogin

func (a *App) UserLogin(ctx context.Context, owner, repo string, id int64) (string, error)

UserLogin is the current login of the GitHub user with the numeric id, read with owner/repo's installation token. The id is stable across a rename; the login is not, so access decisions resolve the id each time they refresh.

type Repository added in v0.35.0

type Repository struct {
	Private    bool   `json:"private"`
	Visibility string `json:"visibility"`
}

Repository is one repository as GitHub's repository API states it: Private whether GitHub reports it private, and Visibility GitHub's own word for it — "public", "private", or an enterprise's "internal", which is private to everyone outside it however much a token can see.

Jump to

Keyboard shortcuts

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