github

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 10 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 implements forge.Forge over the GitHub API, authenticated as the GitHub App installation.

Index

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

func New(client *gh.Client, app *ghapp.App, installationID int64, webURL string) (*Forge, error)

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

func (f *Forge) ParsePRURL(u string) (string, string, int, bool)

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

func (f *Forge) ParseRepoURL(u string) (string, string, bool)

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

func (f *Forge) ParseWebhook(r *http.Request) (forge.Event, error)

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.

Jump to

Keyboard shortcuts

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