Documentation
¶
Overview ¶
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.
Index ¶
- Variables
- func APIBase(host string, httpsPort int) string
- func FormAction(webBase, organization, state string) string
- func Manifest(name, redirectURL string) (string, error)
- func WebBase(host string, httpsPort int) string
- type API
- func (api *API) AskToReview(ctx context.Context, repository Repository, number int64, reviewers []string) error
- func (api *API) Convert(ctx context.Context, code string) (Created, error)
- func (api *API) DefaultBranch(ctx context.Context, repository Repository) (string, error)
- func (api *API) Edit(ctx context.Context, repository Repository, number int64, edit Edit) error
- func (api *API) Label(ctx context.Context, repository Repository, number int64, labels []string) error
- func (api *API) Open(ctx context.Context, repository Repository, request PullRequest) (Opened, error)
- func (api *API) OpenFrom(ctx context.Context, repository Repository, branch string) (Opened, bool, error)
- func (api *API) User(ctx context.Context, accessToken string) (string, error)
- type APIError
- type App
- type Created
- type DeviceCode
- type Edit
- type KeyLoader
- type OAuth
- type Opened
- type PullRequest
- type Repository
- type Signer
- type UserTokens
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPending is a code not entered yet: ask again after the interval. ErrPending = errors.New("the code has not been entered yet") // ErrSlowDown is asking too often: ask again after a longer interval. ErrSlowDown = errors.New("asked too often") )
What waiting for a person to enter a code may answer besides a token.
var ErrNotInstalled = fmt.Errorf("%w: the GitHub App is not installed on it", credentials.ErrUnreachable)
ErrNotInstalled is a repository the App cannot reach: not installed on its owner, or not on that repository.
Functions ¶
func APIBase ¶
APIBase 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.
func FormAction ¶
FormAction 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.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API 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.
func (*API) AskToReview ¶
func (api *API) AskToReview(ctx context.Context, repository Repository, number int64, reviewers []string) error
AskToReview asks people to review a pull request.
func (*API) Convert ¶
Convert 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.
func (*API) DefaultBranch ¶
DefaultBranch is the branch a repository's pull requests merge into unless they say.
func (*API) Label ¶
func (api *API) Label(ctx context.Context, repository Repository, number int64, labels []string) error
Label adds labels to a pull request.
func (*API) Open ¶
func (api *API) Open(ctx context.Context, repository Repository, request PullRequest) (Opened, error)
Open opens a pull request.
type App ¶
type App struct {
// contains filtered or unexported fields
}
App 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.
type Created ¶
type Created struct {
ID int64 `json:"id"`
Slug string `json:"slug"`
HTMLURL string `json:"html_url"`
PEM string `json:"pem"`
Owner struct {
Login string `json:"login"`
} `json:"owner"`
}
Created is an App GitHub created from a manifest: its ID, its name in addresses, its page, who owns it, and its private key.
type DeviceCode ¶
type DeviceCode struct {
DeviceCode string `json:"device_code"`
UserCode string `json:"user_code"`
VerificationURI string `json:"verification_uri"`
ExpiresIn int `json:"expires_in"`
Interval int `json:"interval"`
}
DeviceCode is what a person enters, where, and how to wait for them.
type KeyLoader ¶
KeyLoader 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.
type OAuth ¶
type OAuth struct {
// contains filtered or unexported fields
}
OAuth 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.
func NewOAuth ¶
NewOAuth returns the device flow of the App whose client ID is clientID, on the GitHub whose pages are at web.
func (*OAuth) Poll ¶
Poll 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.
type PullRequest ¶
type PullRequest struct {
Title string `json:"title"`
Body string `json:"body"`
Head string `json:"head"`
Base string `json:"base"`
Draft bool `json:"draft"`
}
PullRequest is a pull request to open: from Head into Base.
type Repository ¶
Repository is a repository on GitHub by its owner and name, and the token that reaches it.
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
Signer signs the JWTs an App authenticates to GitHub with.
type UserTokens ¶
type UserTokens struct {
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
RefreshTokenExpiresIn int `json:"refresh_token_expires_in"`
Error string `json:"error"`
ErrorDescription string `json:"error_description"`
}
UserTokens are a person's tokens: one that works for eight hours, and one that renews it for six months.
func (UserTokens) AccessExpires ¶
func (tokens UserTokens) AccessExpires(now time.Time) time.Time
AccessExpires and RefreshExpires are when the tokens stop working, counted from now.
func (UserTokens) RefreshExpires ¶
func (tokens UserTokens) RefreshExpires(now time.Time) time.Time