Documentation
¶
Overview ¶
Package github implements forge.Forge over the GitHub API, authenticated as the GitHub App installation.
Index ¶
- type Forge
- func (f *Forge) GetPullRequest(ctx context.Context, owner, repo string, number int) (*forge.PullRequest, error)
- func (f *Forge) ListChangedFiles(ctx context.Context, owner, repo string, number int) ([]forge.ChangedFile, error)
- func (f *Forge) ListOpenPullRequests(ctx context.Context, owner, repo string) ([]forge.PullRequest, error)
- func (f *Forge) ParsePRURL(u string) (string, string, int, bool)
- func (f *Forge) ParseRepoURL(u string) (string, string, bool)
- func (f *Forge) ParseWebhook(r *http.Request) (forge.Event, error)
- func (f *Forge) UpsertComment(ctx context.Context, owner, repo string, number int, body string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Forge ¶
type Forge struct {
// contains filtered or unexported fields
}
Forge is the GitHub forge: pull requests and comments through client, webhook deliveries signed with app's secret from the installation installationID, and the repo and pull request URLs of its web URL.
func New ¶
New returns the GitHub forge over client. Webhook deliveries are validated with app and accepted only from the installation installationID. Repo and pull request URLs are those of webURL (GITHUB_URL), which must pass ghapp.ParseWebURL.
func (*Forge) GetPullRequest ¶
func (f *Forge) GetPullRequest(ctx context.Context, owner, repo string, number int) (*forge.PullRequest, error)
GetPullRequest reads owner/repo#number. Lookup failures (including 404 and 403) are returned as errors.
func (*Forge) ListChangedFiles ¶
func (f *Forge) ListChangedFiles(ctx context.Context, owner, repo string, number int) ([]forge.ChangedFile, error)
ListChangedFiles lists the files owner/repo#number changes, reading every page (100 files each). GitHub lists at most forge.MaxListedFiles. A failure on any page is returned as an error.
func (*Forge) ListOpenPullRequests ¶
func (f *Forge) ListOpenPullRequests(ctx context.Context, owner, repo string) ([]forge.PullRequest, error)
ListOpenPullRequests lists the open pull requests of owner/repo, reading every page (100 each). Their ChangedFiles is 0: a listed pull request has no changed_files. A failure on any page is returned as an error.
func (*Forge) ParsePRURL ¶ added in v0.27.0
ParsePRURL returns the owner, repo and number of u when u starts with <web URL>/<owner>/<repo>/pull/<number>, scheme and host compared case-sensitively. Trailing path segments (e.g. /files) are ignored.
func (*Forge) ParseRepoURL ¶ added in v0.27.0
ParseRepoURL returns the lowercased owner and repo of u when u, lowercased and without a trailing "/" then ".git", is <web URL>/<owner>/<repo>. Any other URL (another host, SSH, a deeper path) returns ok false.
func (*Forge) ParseWebhook ¶
ParseWebhook validates the delivery's signature, parses its payload, checks that it comes from the allowed installation and returns it as a forge.Event. A rejected signature is logged and returns forge.ErrUnverified with a zero Event. Every later outcome has the Event's Name: a payload that can't be parsed is logged and its error returned; a delivery from another installation, or without one, is logged and returns forge.ErrForbidden (ping is exempt because it carries no installation). ping, installation and installation_repositories deliveries, and the event types badil does not handle, are logged here and returned with forge.KindOther. The X-Github-Event value is logged as the event attribute.
func (*Forge) UpsertComment ¶
func (f *Forge) UpsertComment(ctx context.Context, owner, repo string, number int, body string) error
UpsertComment posts body as badil's comment on owner/repo#number, prefixed with prCommentMarker: the existing marked comment, searched across every page, is updated, or a new one is created.