{"modulePath":"github.com/dooservice/gitd","version":"v0.15.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package githubapp\n\nPackage githubapp makes the tokens of a GitHub App: a short JWT signed with the App's private key asks GitHub for an installation token limited to one repository and to what one operation needs, kept in memory until shortly before it expires.\n\n## Variables\n\n```go\nvar (\n\t// ErrPending is a code not entered yet: ask again after the interval.\n\tErrPending = errors.New(\"the code has not been entered yet\")\n\t// ErrSlowDown is asking too often: ask again after a longer interval.\n\tErrSlowDown = errors.New(\"asked too often\")\n)\n```\nWhat waiting for a person to enter a code may answer besides a token.\n\n```go\nvar ErrNotInstalled = fmt.Errorf(\"%w: the GitHub App is not installed on it\", credentials.ErrUnreachable)\n```\nErrNotInstalled is a repository the App cannot reach: not installed on its owner, or not on that repository.\n\n## Functions\n\n```go\nfunc APIBase(host string, httpsPort int) string\n```\nAPIBase is the address of the API of a GitHub host: api.github.com for github.com, and \\`/api/v3\\` on the host, on its HTTPS port, for a GitHub Enterprise Server.\n\n```go\nfunc FormAction(webBase, organization, state string) string\n```\nFormAction is where a browser posts a manifest to create an App owned by organization, or by the person signed in when organization is empty, carrying state back.\n\n```go\nfunc Manifest(name, redirectURL string) (string, error)\n```\nManifest is the manifest of an App named name, which GitHub sends back to redirectURL with a code: private, no webhook, only the permissions publishing takes.\n\n```go\nfunc WebBase(host string, httpsPort int) string\n```\nWebBase is the address of a GitHub host's pages.\n\n## Types\n\n```go\ntype API struct {\n\t// contains filtered or unexported fields\n}\n```\nAPI calls GitHub's REST API at one address: api.github.com, or a GitHub Enterprise Server's. A redirect is never followed, so a token is sent only where it was meant for.\n\n```go\nfunc NewAPI(base, userAgent string) *API\n```\nNewAPI returns the API at base, calling as userAgent (gitd and its version).\n\n```go\nfunc (api *API) AskToReview(ctx context.Context, repository Repository, number int64, reviewers []string) error\n```\nAskToReview asks people to review a pull request.\n\n```go\nfunc (api *API) Convert(ctx context.Context, code string) (Created, error)\n```\nConvert exchanges the code GitHub sent back from a manifest for the App it created. The code alone is the proof: the call carries no other credential.\n\n```go\nfunc (api *API) DefaultBranch(ctx context.Context, repository Repository) (string, error)\n```\nDefaultBranch is the branch a repository's pull requests merge into unless they say.\n\n```go\nfunc (api *API) Edit(ctx context.Context, repository Repository, number int64, edit Edit) error\n```\nEdit writes a pull request's title and body over what they were.\n\n```go\nfunc (api *API) Label(ctx context.Context, repository Repository, number int64, labels []string) error\n```\nLabel adds labels to a pull request.\n\n```go\nfunc (api *API) Open(ctx context.Context, repository Repository, request PullRequest) (Opened, error)\n```\nOpen opens a pull request.\n\n```go\nfunc (api *API) OpenFrom(ctx context.Context, repository Repository, branch string) (Opened, bool, error)\n```\nOpenFrom is the pull request open from a branch of the repository itself, and false when none is.\n\n```go\nfunc (api *API) User(ctx context.Context, accessToken string) (string, error)\n```\nUser is the login of the person a token is theirs.\n\n```go\ntype APIError struct {\n\tStatus  int\n\tMessage string\n}\n```\nAPIError is an answer GitHub gave other than success: its status and its message.\n\n```go\nfunc (failure *APIError) Error() string\n```\n\n```go\ntype App struct {\n\t// contains filtered or unexported fields\n}\n```\nApp makes the installation tokens of one GitHub App, each for one repository and one purpose, kept in memory until shortly before they expire and never written anywhere.\n\n```go\nfunc NewApp(signer *Signer, api *API) *App\n```\nNewApp returns the App that signer signs for, calling GitHub's API at api.\n\n```go\nfunc (app *App) Identity(ctx context.Context) (string, string, error)\n```\nIdentity is who the App's tokens act as: its bot, e.g. \\`acme-agents\\[bot]\\`, and where its installations are managed.\n\n```go\nfunc (app *App) Token(ctx context.Context, repository repo.Repo, purpose credentials.Purpose) (string, error)\n```\nToken is a token for one repository and one purpose: the one kept, or a new one when the one kept is near its end.\n\n```go\ntype Created struct {\n\tID      int64  `json:\"id\"`\n\tSlug    string `json:\"slug\"`\n\tHTMLURL string `json:\"html_url\"`\n\tPEM     string `json:\"pem\"`\n\tOwner   struct {\n\t\tLogin string `json:\"login\"`\n\t} `json:\"owner\"`\n}\n```\nCreated is an App GitHub created from a manifest: its ID, its name in addresses, its page, who owns it, and its private key.\n\n```go\ntype DeviceCode struct {\n\tDeviceCode      string `json:\"device_code\"`\n\tUserCode        string `json:\"user_code\"`\n\tVerificationURI string `json:\"verification_uri\"`\n\tExpiresIn       int    `json:\"expires_in\"`\n\tInterval        int    `json:\"interval\"`\n}\n```\nDeviceCode is what a person enters, where, and how to wait for them.\n\n```go\ntype Edit struct {\n\tTitle string `json:\"title\"`\n\tBody  string `json:\"body\"`\n}\n```\nEdit is what editing a pull request writes over: its title and body.\n\n```go\ntype KeyLoader func() ([]byte, error)\n```\nKeyLoader reads an App's private key, in PEM. It is called each time a JWT is signed, so a key replaced where it is kept is used from then on.\n\n```go\ntype OAuth struct {\n\t// contains filtered or unexported fields\n}\n```\nOAuth signs a person in through a GitHub App by GitHub's device flow, and renews their tokens, with the App's client ID alone: neither takes a secret.\n\n```go\nfunc NewOAuth(web, clientID string) *OAuth\n```\nNewOAuth returns the device flow of the App whose client ID is clientID, on the GitHub whose pages are at web.\n\n```go\nfunc (oauth *OAuth) Poll(ctx context.Context, deviceCode string) (UserTokens, error)\n```\nPoll asks once whether the person entered the code: their tokens when they did, ErrPending or ErrSlowDown while they have not, and another error when they never will.\n\n```go\nfunc (oauth *OAuth) Renew(ctx context.Context, refreshToken string) (UserTokens, error)\n```\nRenew exchanges a renewal token for new tokens; the renewal token is replaced too.\n\n```go\nfunc (oauth *OAuth) Start(ctx context.Context) (DeviceCode, error)\n```\nStart asks GitHub for a code for a person to enter.\n\n```go\ntype Opened struct {\n\tURL    string `json:\"html_url\"`\n\tNumber int64  `json:\"number\"`\n}\n```\nOpened is a pull request GitHub opened.\n\n```go\ntype PullRequest struct {\n\tTitle string `json:\"title\"`\n\tBody  string `json:\"body\"`\n\tHead  string `json:\"head\"`\n\tBase  string `json:\"base\"`\n\tDraft bool   `json:\"draft\"`\n}\n```\nPullRequest is a pull request to open: from Head into Base.\n\n```go\ntype Repository struct {\n\tOwner string\n\tName  string\n\tToken string\n}\n```\nRepository is a repository on GitHub by its owner and name, and the token that reaches it.\n\n```go\ntype Signer struct {\n\t// contains filtered or unexported fields\n}\n```\nSigner signs the JWTs an App authenticates to GitHub with.\n\n```go\nfunc NewSigner(appID int64, key KeyLoader) (*Signer, error)\n```\nNewSigner returns the signer of an App, checking that its key can be read now.\n\n```go\nfunc (signer *Signer) JWT(now time.Time) (string, error)\n```\nJWT is a token that says, until it expires, that this App is asking.\n\n```go\ntype UserTokens struct {\n\tAccessToken           string `json:\"access_token\"`\n\tExpiresIn             int    `json:\"expires_in\"`\n\tRefreshToken          string `json:\"refresh_token\"`\n\tRefreshTokenExpiresIn int    `json:\"refresh_token_expires_in\"`\n\tError                 string `json:\"error\"`\n\tErrorDescription      string `json:\"error_description\"`\n}\n```\nUserTokens are a person's tokens: one that works for eight hours, and one that renews it for six months.\n\n```go\nfunc (tokens UserTokens) AccessExpires(now time.Time) time.Time\n```\nAccessExpires and RefreshExpires are when the tokens stop working, counted from now.\n\n```go\nfunc (tokens UserTokens) RefreshExpires(now time.Time) time.Time\n```\n\n","path":"github.com/dooservice/gitd/internal/githubapp","name":"githubapp","synopsis":"Package githubapp makes the tokens of a GitHub App: a short JWT signed with the App's private key asks GitHub for an installation token limited to one repository and to what one operation needs, kept in memory until shortly before it expires.","isRedistributable":true}
