Documentation
¶
Overview ¶
Package github talks to the GitHub REST API and resolves how an organization was named on the command line.
Index ¶
- func DefaultAPIBase(host string) string
- func DefaultProtocol(host string) string
- func FindToken(host string) (token, source string)
- func NormalizeHost(host string) string
- type APIError
- type Client
- func (c *Client) CurrentUser(ctx context.Context) (string, error)
- func (c *Client) ListRepos(ctx context.Context, owner Owner, progress func(page, total int)) ([]Repo, error)
- func (c *Client) LookupOwner(ctx context.Context, login string) (Owner, error)
- func (c *Client) LookupRepo(ctx context.Context, owner, name string) (Repo, error)
- func (c *Client) Overridden() bool
- type Owner
- type OwnerRef
- type Repo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAPIBase ¶ added in v1.1.0
DefaultAPIBase returns the REST API base URL for a host.
func DefaultProtocol ¶
DefaultProtocol returns "ssh" when the gh CLI is configured for SSH on host, otherwise "https".
func FindToken ¶
FindToken locates a token for host: environment variables first (matching the gh CLI's own precedence), then gh's stored credentials. The returned source is a short label for display, e.g. "$GITHUB_TOKEN" or "gh auth".
Tokens are strictly scoped to the host they belong to: GH_TOKEN and GITHUB_TOKEN authenticate github.com only, GH_ENTERPRISE_TOKEN and GITHUB_ENTERPRISE_TOKEN authenticate everything else. A github.com token is never sent to another host — a typo'd or hostile host name must not receive it. gh's stored credentials are already looked up per host.
func NormalizeHost ¶ added in v1.2.0
NormalizeHost canonicalizes a host name so that spellings which resolve to the same GitHub host take the same code path. Every host decision keys off this string — which token applies (FindToken) and which API base is used (DefaultAPIBase) — so an un-normalized "www.github.com" would be treated as a GitHub Enterprise host: the wrong API base, and a github.com token sent to a host the docs promise it never reaches.
Types ¶
type Client ¶
type Client struct {
Host string
APIBase string
Token string
HTTP *http.Client
// contains filtered or unexported fields
}
Client is a minimal GitHub REST client.
func NewClient ¶
NewClient returns a client for host. The API base URL can be overridden with GITOPS_GITHUB_API (used by tests and trusted API proxies). The token is sent as a Bearer header to whatever the base names, so the override must be https — or http on localhost only — and is otherwise ignored.
func (*Client) CurrentUser ¶
CurrentUser returns the login of the authenticated user, or "" without a token.
func (*Client) ListRepos ¶
func (c *Client) ListRepos(ctx context.Context, owner Owner, progress func(page, total int)) ([]Repo, error)
ListRepos returns every repository of owner visible to the caller, sorted by name. progress, if non-nil, is called after each page.
func (*Client) LookupOwner ¶
LookupOwner resolves a login to its canonical spelling and account type.
func (*Client) LookupRepo ¶ added in v1.2.0
LookupRepo fetches one repository by name. It exists to answer a question the org listing cannot: whether a repository the listing omitted is really gone. A repository that was renamed or transferred still resolves — the API redirects to its current location — so the returned FullName distinguishes a rename from a deletion, and a 404 is the only thing that means "gone".
The returned Repo is display-only: FullName may name a different owner after a transfer, so it is not passed through sanitizeRepo (which rebuilds URLs from an assumed owner) and its clone URLs are cleared rather than trusted.
func (*Client) Overridden ¶ added in v1.1.0
Overridden reports whether the API base came from GITOPS_GITHUB_API. When it is set, the token is sent to that endpoint and its repository URLs are taken at face value, so callers should make the override visible.
type Owner ¶
type Owner struct {
Login string `json:"login"`
Type string `json:"type"` // "Organization" or "User"
}
Owner is the resolved account as reported by the API.
type OwnerRef ¶
OwnerRef is an organization or user account on a GitHub host.
func ParseOwner ¶
ParseOwner accepts the many ways people write an org: a bare login ("acme"), "github.com/acme", any https://github.com/acme[/...] URL (including /orgs/acme), an SSH remote ("git@github.com:acme/repo.git"), or a GitHub Enterprise host ("https://ghe.example.com/acme").
func (OwnerRef) URL ¶
URL returns the browsable URL of the owner, e.g. https://github.com/acme.
type Repo ¶
type Repo struct {
Name string `json:"name"`
FullName string `json:"full_name"`
Private bool `json:"private"`
Archived bool `json:"archived"`
Fork bool `json:"fork"`
DefaultBranch string `json:"default_branch"`
CloneURL string `json:"clone_url"`
SSHURL string `json:"ssh_url"`
}
Repo is the subset of the repository object gitops uses.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package githubtest provides a fake GitHub API server for tests.
|
Package githubtest provides a fake GitHub API server for tests. |