Documentation
¶
Overview ¶
Package github is the GitHub REST client used by synchronization: token exchange for GitHub App and personal credentials, repository and tree reads, and the write operations behind publication.
Index ¶
- func AppJWT(secret Secret) (string, error)
- func BlobDigest(data []byte, length int) string
- func ErrorCode(e error) string
- func RetryAt(err error) time.Time
- func VerifiedTreeFile(source Tree, p, expected string) (string, error)
- type Client
- func (g *Client) Blob(ctx context.Context, repo, sha, token string) ([]byte, error)
- func (g *Client) Head(ctx context.Context, repo, branch, token string) (string, error)
- func (g *Client) Push(ctx context.Context, repo, branch, base, treeSHA, p, content, token string, ...) (string, error)
- func (g *Client) PushFiles(ctx context.Context, repo, branch, base, treeSHA string, ...) (string, error)
- func (g *Client) Remove(ctx context.Context, repo, branch, base string, source Tree, ...) (string, error)
- func (g *Client) Repository(ctx context.Context, repo, token string) (RepositoryInfo, error)
- func (g *Client) RepositoryByID(ctx context.Context, id int64, token string) (RepositoryInfo, error)
- func (g *Client) Token(ctx context.Context, secret *Secret, repo string, write bool) (string, error)
- func (g *Client) Tree(ctx context.Context, repo, head, token string) (Tree, error)
- func (g *Client) UpdateBranch(ctx context.Context, repo, branch, before, after, token string) error
- func (g *Client) VerifyAccount(ctx context.Context, secret Secret) (string, error)
- type Commit
- type RemoteError
- type RepositoryInfo
- type Secret
- type Tree
- type TreeEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BlobDigest ¶
BlobDigest returns the Git object ID of a blob; length selects SHA-1 (40) or SHA-256 (64) repositories.
func VerifiedTreeFile ¶
remove creates a deletion commit only when the complete source tree contains exactly the expected regular file. The caller must persist the prepared commit and observe the deletion in a subsequent complete pull.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the GitHub REST and GraphQL APIs.
func New ¶
func New() *Client
New returns a client for api.github.com with bounded timeouts and no redirects or proxies.
func NewForTest ¶
NewForTest returns a client for a local test server.
func (*Client) Push ¶
func (g *Client) Push(ctx context.Context, repo, branch, base, treeSHA, p, content, token string, prepare func(string) error) (string, error)
Push commits one file at path p on top of base and moves branch to the new commit, returning its ID. prepare may veto the write before it is sent.
func (*Client) PushFiles ¶
func (g *Client) PushFiles(ctx context.Context, repo, branch, base, treeSHA string, files map[string][]byte, token string, prepare func(string) error) (string, error)
PushFiles commits all files on top of base in one commit and moves branch to it, returning the new commit ID. prepare may veto the write before it is sent.
func (*Client) Remove ¶
func (g *Client) Remove(ctx context.Context, repo, branch, base string, source Tree, p, expected, token string, prepare func(string) error) (string, error)
Remove commits the deletion of the file p on top of base, provided its blob still matches expected, and returns the new commit ID.
func (*Client) Repository ¶
Repository reads the repository metadata: default branch, visibility and archive state.
func (*Client) RepositoryByID ¶
func (g *Client) RepositoryByID(ctx context.Context, id int64, token string) (RepositoryInfo, error)
RepositoryByID reads the repository metadata by its numeric identity, the handle that survives a rename on GitHub. The answer must describe that identity.
func (*Client) Token ¶
func (g *Client) Token(ctx context.Context, secret *Secret, repo string, write bool) (string, error)
Token returns the bearer token for repo: the personal token itself, or a short-lived installation token for a GitHub App credential. A nil secret means anonymous read access.
func (*Client) UpdateBranch ¶
updateBranch uses an exact old-head precondition; REST's non-force update alone also accepts a branch rewound to an ancestor of the prepared commit.
type Commit ¶
type Commit struct {
SHA string `json:"sha"`
Tree struct {
SHA string `json:"sha"`
} `json:"tree"`
}
Commit is the part of a Git commit that names its tree.
type RemoteError ¶
RemoteError reports a failure of the GitHub API or of its response.
func (*RemoteError) Error ¶
func (e *RemoteError) Error() string
Error returns the stable error code.
type RepositoryInfo ¶
type RepositoryInfo struct {
ID int64 `json:"id"`
FullName string `json:"full_name"`
Private *bool `json:"private"`
DefaultBranch string `json:"default_branch"`
Archived bool `json:"archived"`
Permissions struct {
Push bool `json:"push"`
} `json:"permissions"`
Visibility string `json:"visibility"`
}
RepositoryInfo is the validated subset of a repository response.
type Secret ¶
type Secret struct {
Kind string `json:"kind"`
Token string `json:"token,omitempty"`
AppID int64 `json:"app_id,omitempty"`
InstallationID int64 `json:"installation_id,omitempty"`
PrivateKey string `json:"private_key,omitempty"`
}
Secret is credential material for a GitHub account. It is never returned in API responses; the store keeps only an opaque reference to it.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package githubtest provides an in-memory GitHub server for tests.
|
Package githubtest provides an in-memory GitHub server for tests. |