Help us shape the future of Go! Take the 2026 Go Developer Survey

github

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package github integrates shed with a single GitHub App.

The App provides everything shed needs from GitHub: repository access through installation tokens, sign-in through OAuth, push webhooks, and CI status. REST calls go through go-github.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Manifest

func Manifest(baseURL, name string) ([]byte, error)

Manifest returns the JSON App manifest for a shed instance served at baseURL, to be posted to GitHub's app creation page.

func VerifySignature

func VerifySignature(secret string, body []byte, header string) bool

VerifySignature reports whether header, the X-Hub-Signature-256 value of a webhook delivery, is the valid HMAC-SHA256 of body under secret.

Types

type App

type App struct {
	ID            int64
	Slug          string
	ClientID      string
	ClientSecret  string
	WebhookSecret string
	// PrivateKey is the PEM-encoded RSA key used to sign app JWTs.
	PrivateKey []byte
}

App holds the credentials of a registered GitHub App.

func ConvertManifest

func ConvertManifest(ctx context.Context, httpClient *http.Client, code string) (App, error)

ConvertManifest exchanges the code GitHub returns after the manifest flow for the credentials of the newly created App. A nil httpClient means a client with a 30-second timeout.

type CIState

type CIState string

CIState is the aggregate state of the CI results for a commit.

const (
	// CIPending means some check or status has not finished and none failed.
	CIPending CIState = "pending"
	// CISuccess means every check and status passed.
	CISuccess CIState = "success"
	// CIFailure means at least one check or status failed.
	CIFailure CIState = "failure"
	// CINone means the commit has no checks or statuses. Checks may simply
	// not have been created yet.
	CINone CIState = "none"
)

CI states.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client calls the GitHub API as an App. It is safe for concurrent use.

func New

func New(app App, httpClient *http.Client) (*Client, error)

New returns a Client for app. A nil httpClient means a client with a 30-second timeout. The client is never modified.

func (*Client) App

func (c *Client) App() App

App returns the credentials the Client was created with.

func (*Client) AuthorizeURL

func (c *Client) AuthorizeURL(redirectURL, state string) string

AuthorizeURL returns the GitHub page that asks a user to authorize the App. GitHub redirects back to redirectURL with the code and state.

func (*Client) Branches

func (c *Client) Branches(ctx context.Context, fullName string) ([]string, error)

Branches returns the branch names of the repository fullName (owner/name).

func (*Client) CIStatus

func (c *Client) CIStatus(ctx context.Context, fullName, sha string) (CIState, error)

CIStatus combines the check runs and commit statuses of commit sha in the repository fullName (owner/name). A failure outranks pending results, so callers can stop waiting as soon as anything fails.

func (*Client) CloneURL

func (c *Client) CloneURL(ctx context.Context, fullName string) (string, error)

CloneURL returns an HTTPS URL for cloning the repository fullName (owner/name) that embeds a short-lived installation token. It is a secret.

func (*Client) Commit

func (c *Client) Commit(ctx context.Context, fullName, ref string) (Commit, error)

Commit returns the commit that ref, a branch name or SHA, points to in the repository fullName (owner/name).

func (*Client) ExchangeUser

func (c *Client) ExchangeUser(ctx context.Context, code, redirectURL string) (User, error)

ExchangeUser trades the code from an authorization redirect for a user token and returns the user it belongs to. redirectURL must match the one given to Client.AuthorizeURL.

func (*Client) Lookup

func (c *Client) Lookup(ctx context.Context) (slug, clientID string, err error)

Lookup fetches the App's own record from GitHub, which confirms that the App ID and private key belong together, and returns the App's slug and client ID.

func (*Client) Repos

func (c *Client) Repos(ctx context.Context) ([]Repo, error)

Repos returns the repositories of every installation of the App, sorted by full name.

type Commit

type Commit struct {
	SHA string
	// Message is the first line of the commit message.
	Message string
	Author  string
}

Commit describes a git commit.

type PushEvent

type PushEvent struct {
	// Repo is the repository as owner/name.
	Repo string
	// Branch is the pushed branch, or empty if the ref is not a branch.
	Branch string
	// SHA is the new head commit.
	SHA string
	// Message is the first line of the head commit's message.
	Message string
	// Author is the head commit's author name.
	Author string
	// Deleted reports that the push deleted the branch.
	Deleted bool
}

PushEvent is the part of a push webhook payload shed acts on.

func ParsePush

func ParsePush(body []byte) (PushEvent, error)

ParsePush decodes the body of a push webhook delivery.

type Repo

type Repo struct {
	FullName      string
	DefaultBranch string
	Private       bool
}

Repo is a repository the App can access.

type User

type User struct {
	ID        int64
	Login     string
	Name      string
	AvatarURL string
}

User is a GitHub account that signed in through the App.

Jump to

Keyboard shortcuts

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