github

package
v0.7.15 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package github talks to GitHub as the panel's own GitHub App.

Each panel creates its own App on its owner's account through GitHub's manifest flow, so nobody copies tokens around and Zelie the project never sits between a panel and GitHub. The App only asks for what deploying needs: reading code and setting commit statuses.

Index

Constants

View Source
const (
	API = "https://api.github.com"
	Web = "https://github.com"
)

Default addresses. Tests point a Client elsewhere.

View Source
const (
	StatusPending = "pending"
	StatusSuccess = "success"
	StatusFailure = "failure"
)

Commit status states.

Variables

View Source
var ErrNotFound = errors.New("not found on GitHub")

ErrNotFound means GitHub has no such thing, or the App cannot see it.

Functions

func Manifest

func Manifest(name, base string) map[string]any

Manifest describes the App a panel creates for itself. base is the panel's address, such as https://panel.example.com. GitHub refuses a webhook it cannot reach, so a panel on a private address gets an App without one: private repositories work, pushes do not deploy.

func ParseKey

func ParseKey(b []byte) (*rsa.PrivateKey, error)

ParseKey reads the App's private key as GitHub gives it.

func PublicHost

func PublicHost(host string) bool

PublicHost reports whether GitHub could reach host: not an address meant for one machine or a private network.

func Verify

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

Verify checks a webhook's X-Hub-Signature-256 header against its body. Without a secret nothing verifies: anyone can sign with an empty key.

Types

type Client

type Client struct {
	HTTP  *http.Client
	API   string
	AppID int64
	Key   *rsa.PrivateKey
	Now   func() time.Time
	// contains filtered or unexported fields
}

Client acts as one App.

func (*Client) Archive

func (c *Client) Archive(ctx context.Context, inst int64, repo, commit string) (io.ReadCloser, error)

Archive downloads the code at a commit as a gzipped tar. GitHub answers with a redirect to a short-lived signed address, which the HTTP client follows; it drops the Authorization header on the way, as it should.

func (*Client) Deliveries

func (c *Client) Deliveries(ctx context.Context) ([]Delivery, error)

Deliveries lists the App's most recent webhook deliveries, newest first. It shows whether GitHub can reach the panel at all.

func (*Client) Installations

func (c *Client) Installations(ctx context.Context) ([]Installation, error)

func (*Client) RepoInstallation

func (c *Client) RepoInstallation(ctx context.Context, repo string) (int64, error)

RepoInstallation finds the installation that can read repo, or ErrNotFound if the App was not given access to it.

func (*Client) Repositories

func (c *Client) Repositories(ctx context.Context, inst int64) ([]Repository, error)

func (*Client) Resolve

func (c *Client) Resolve(ctx context.Context, inst int64, repo, branch string) (string, error)

Resolve returns the commit a branch points at.

func (*Client) SetStatus

func (c *Client) SetStatus(ctx context.Context, inst int64, repo, commit, state, description, target string) error

SetStatus puts a mark next to a commit on GitHub.

type Credentials

type Credentials struct {
	ID            int64  `json:"id"`
	Slug          string `json:"slug"`
	HTMLURL       string `json:"html_url"`
	PEM           string `json:"pem"`
	WebhookSecret string `json:"webhook_secret"`
	Owner         struct {
		Login string `json:"login"`
	} `json:"owner"`
}

Credentials are what GitHub hands over once, when the App is created.

func Convert

func Convert(ctx context.Context, hc *http.Client, api, code string) (Credentials, error)

Convert trades the code from the manifest flow for the new App's credentials. The code works once and for an hour.

type Delivery

type Delivery struct {
	Event       string    `json:"event"`
	StatusCode  int       `json:"status_code"`
	Status      string    `json:"status"`
	DeliveredAt time.Time `json:"delivered_at"`
}

Delivery is GitHub's record of sending one webhook.

type Installation

type Installation struct {
	ID      int64  `json:"id"`
	Account string `json:"account"`
	// All is true when the App may read every repository of the account.
	All bool `json:"all"`
}

Installation is an account the App was installed on.

type Repository

type Repository struct {
	FullName      string `json:"full_name"`
	Private       bool   `json:"private"`
	DefaultBranch string `json:"default_branch"`
}

Repository is one the App can read.

Jump to

Keyboard shortcuts

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