github

package
v0.0.0-...-58f053a Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppJWT

func AppJWT(secret Secret) (string, error)

AppJWT signs the short-lived JWT that authenticates a GitHub App.

func BlobDigest

func BlobDigest(data []byte, length int) string

BlobDigest returns the Git object ID of a blob; length selects SHA-1 (40) or SHA-256 (64) repositories.

func ErrorCode

func ErrorCode(e error) string

ErrorCode maps err to a stable, non-sensitive failure code.

func RetryAt

func RetryAt(err error) time.Time

RetryAt returns the rate-limit deadline carried by err, if any.

func VerifiedTreeFile

func VerifiedTreeFile(source Tree, p, expected string) (string, error)

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

func NewForTest(base string, hc *http.Client) *Client

NewForTest returns a client for a local test server.

func (*Client) Blob

func (g *Client) Blob(ctx context.Context, repo, sha, token string) ([]byte, error)

Blob downloads the blob sha, bounded in size, and decodes its content.

func (*Client) Head

func (g *Client) Head(ctx context.Context, repo, branch, token string) (string, error)

Head returns the commit ID at the tip of branch.

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

func (g *Client) Repository(ctx context.Context, repo, token string) (RepositoryInfo, error)

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) Tree

func (g *Client) Tree(ctx context.Context, repo, head, token string) (Tree, error)

Tree returns the recursive file tree of the commit head.

func (*Client) UpdateBranch

func (g *Client) UpdateBranch(ctx context.Context, repo, branch, before, after, token string) error

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.

func (*Client) VerifyAccount

func (g *Client) VerifyAccount(ctx context.Context, secret Secret) (string, error)

VerifyAccount checks the credential against GitHub and returns the account login it belongs to.

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

type RemoteError struct {
	Code    string
	Status  int
	RetryAt time.Time
}

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.

type Tree

type Tree struct {
	SHA       string      `json:"sha"`
	Tree      []TreeEntry `json:"tree"`
	Truncated bool        `json:"truncated"`
}

Tree is a complete recursive Git tree.

type TreeEntry

type TreeEntry struct {
	Path string `json:"path"`
	Mode string `json:"mode"`
	Type string `json:"type"`
	SHA  string `json:"sha"`
	Size int64  `json:"size"`
}

TreeEntry is one path of a Git tree.

Directories

Path Synopsis
Package githubtest provides an in-memory GitHub server for tests.
Package githubtest provides an in-memory GitHub server for tests.

Jump to

Keyboard shortcuts

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