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 ¶
- Variables
- func Permanent(err error) bool
- func Quote(s string) string
- type APIError
- type App
- func (a *App) Comment(ctx context.Context, pr, marker, body string) (string, error)
- func (a *App) CreateIssue(ctx context.Context, owner, repo, title, body string, labels []string) (CreatedIssue, error)
- func (a *App) Enabled() bool
- func (a *App) PathExists(ctx context.Context, owner, repo, path string) (bool, error)
- func (a *App) Permission(ctx context.Context, owner, repo, login string) (string, error)
- func (a *App) Repository(ctx context.Context, owner, repo string) (Repository, error)
- func (a *App) UserLogin(ctx context.Context, owner, repo string, id int64) (string, error)
- type CreatedIssue
- type OAuth
- func (o OAuth) AuthorizeURL(clientID, redirect, state, challenge string) string
- func (o OAuth) ExchangeCode(ctx context.Context, clientID, clientSecret, code, verifier, redirect string) (string, error)
- func (o OAuth) RevokeUserToken(ctx context.Context, clientID, clientSecret, token string) error
- func (o OAuth) User(ctx context.Context, token string) (int64, string, error)
- type Repository
Constants ¶
This section is empty.
Variables ¶
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.
var ErrNotAPullRequest = errors.New("github: not a GitHub pull request URL")
ErrNotAPullRequest reports a URL that is not a GitHub pull request's.
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 ¶
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 ¶
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 ¶
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) Permanent ¶
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 ¶
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) CreateIssue ¶ added in v0.54.0
func (a *App) CreateIssue(ctx context.Context, owner, repo, title, body string, labels []string) (CreatedIssue, error)
CreateIssue opens an issue on owner/repo with labels and returns its number and URL.
func (*App) PathExists ¶ added in v0.53.5
PathExists is whether owner/repo's default branch holds path, as GitHub's contents API answers a HEAD with a short-lived read-only installation token (contents: read, zero write permissions; v5 P0-T1). Works on both public and private repositories. GitHub's 404 is false; any other refusal is an error.
func (*App) Permission ¶
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
Repository is owner/repo's visibility, read with a scoped read-only installation token (contents: read + metadata: read). It is the planner's visibility read (CD5, v5 P0-T1): 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.
type CreatedIssue ¶ added in v0.54.0
CreatedIssue is the issue CreateIssue opened on GitHub.
type OAuth ¶ added in v0.47.0
OAuth is GitHub's web application flow, as the broker's GitHub account link runs it (v4 D8): the authorize URL, the code exchange with PKCE, GET /user, and the token's revocation. WebURL is GitHub's site (https://github.com, or a GHES host), APIURL its API base; both https. No error quotes a code, a verifier, a client secret or a token: a refusal names GitHub's error word or an HTTP status.
func (OAuth) AuthorizeURL ¶ added in v0.47.0
AuthorizeURL is where the browser is sent: the user authorizes the client at GitHub, which redirects to redirect with a code and state. challenge is the PKCE S256 challenge.
func (OAuth) ExchangeCode ¶ added in v0.47.0
func (o OAuth) ExchangeCode(ctx context.Context, clientID, clientSecret, code, verifier, redirect string) (string, error)
ExchangeCode trades code and its PKCE verifier for a user token.
func (OAuth) RevokeUserToken ¶ added in v0.47.0
RevokeUserToken deletes token at GitHub (DELETE /applications/{client_id}/token): the broker keeps none, so it revokes each one as soon as GET /user has answered.
type Repository ¶ added in v0.35.0
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.