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
- Variables
- func Manifest(name, base string) map[string]any
- func ParseKey(b []byte) (*rsa.PrivateKey, error)
- func PublicHost(host string) bool
- func Verify(secret, body []byte, header string) bool
- type Client
- func (c *Client) Archive(ctx context.Context, inst int64, repo, commit string) (io.ReadCloser, error)
- func (c *Client) Deliveries(ctx context.Context) ([]Delivery, error)
- func (c *Client) Installations(ctx context.Context) ([]Installation, error)
- func (c *Client) RepoInstallation(ctx context.Context, repo string) (int64, error)
- func (c *Client) Repositories(ctx context.Context, inst int64) ([]Repository, error)
- func (c *Client) Resolve(ctx context.Context, inst int64, repo, branch string) (string, error)
- func (c *Client) SetStatus(ctx context.Context, inst int64, ...) error
- type Credentials
- type Delivery
- type Installation
- type Repository
Constants ¶
const ( API = "https://api.github.com" Web = "https://github.com" )
Default addresses. Tests point a Client elsewhere.
const ( StatusPending = "pending" StatusSuccess = "success" StatusFailure = "failure" )
Commit status states.
Variables ¶
var ErrNotFound = errors.New("not found on GitHub")
ErrNotFound means GitHub has no such thing, or the App cannot see it.
Functions ¶
func Manifest ¶
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 ¶
PublicHost reports whether GitHub could reach host: not an address meant for one machine or a private network.
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 ¶
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 ¶
RepoInstallation finds the installation that can read repo, or ErrNotFound if the App was not given access to it.
func (*Client) Repositories ¶
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.
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.