github

package
v0.7.13 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 23 Imported by: ? 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 mounts driver for GitHub repositories, read and written through GitHub's REST API. A mount's Source is "github://owner/repo".

A snapshot mount pins a commit. When the mount is made, the driver downloads the commit's tarball into a blob store and writes a manifest, so the mount serves the same bytes for its whole life, and after a restart, without asking GitHub again. A live mount reads a branch through the Contents API, and each Put or Delete is one commit on it.

The driver sends each request with the token source the registry hands it, which comes from the mount's connection. A private repo answers 404 to a request without a valid token, so the driver reports ErrNotFound for it, as GitHub intends.

Index

Constants

View Source
const DefaultBaseURL = "https://api.github.com"

DefaultBaseURL is GitHub's API root. GitHub Enterprise and tests set another with WithBaseURL.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver serves mounts.KindGitHub mounts. It implements mounts.Preparer, mounts.Writer and mounts.Localizer. Share one Driver per process, since it caches manifests and builds each snapshot's folder view once.

func New

func New(store blobs.Store, opts ...Option) *Driver

New returns a GitHub driver keeping snapshots in store. A nil store serves live mounts only, and Prepare refuses a snapshot with ErrInvalidArgument.

func (*Driver) CanRead

func (d *Driver) CanRead(ctx context.Context, baseURL, source string, ts oauth2.TokenSource) (bool, error)

CanRead reports whether ts can read the repo at source. It fits connections.ReadCheck, so an app passes it to connections.WithReadCheck.

baseURL is the connection's API root, empty for github.com. A connection to another host than this driver serves gets false with no request, since its token means nothing here. A 404 is a definite no, and it is also how GitHub answers a private repo the token can't see. Any other failure, a rejected token included, is an error, since it says nothing about access.

func (*Driver) Delete

Delete removes req.Path as one commit on the mount's branch. IfMatch must be the file's current version or AnyVersion; a stale one returns ErrConflict, and an empty one ErrInvalidArgument.

func (*Driver) HostPath

func (d *Driver) HostPath(m mounts.Mount, p string) (string, error)

HostPath returns where p of a snapshot mount is on disk, in the folder WithViews set. The first call for a mount builds its view there, as hard links to the blob store (copies where the filesystem refuses links), so a restart that lost the folder rebuilds it from the manifest without asking GitHub. A live mount, or a driver without WithViews or a linking blob store, returns ErrNotLocal.

func (*Driver) Kind

func (d *Driver) Kind() mounts.Kind

Kind returns mounts.KindGitHub.

func (*Driver) Modes

func (d *Driver) Modes() []mounts.Mode

Modes returns snapshot first, so a mount made with no mode is pinned.

func (*Driver) Open

func (d *Driver) Open(ctx context.Context, m mounts.Mount, ts oauth2.TokenSource) (fs.FS, error)

Open returns the mount's files: a snapshot's from its manifest and the blob store, or a live mount's from the Contents API at its branch. A live mount's fs.FS keeps ctx and ts for the requests it makes later.

func (*Driver) Prepare

func (d *Driver) Prepare(ctx context.Context, m mounts.Mount, ts oauth2.TokenSource) (mounts.Mount, error)

Prepare finishes a new mount after Resolve. For a snapshot it downloads m.Version's tarball into the blob store and sets m.Manifest. For a live mount it sets m.Ref to the default branch when it is empty, so later writes name the branch. A live mount's Ref must be a branch, since GitHub commits a write onto a branch.

func (*Driver) Put

Put writes req.Data to req.Path as one commit on the mount's branch. An empty IfMatch sends no sha, so GitHub refuses to replace an existing file and Put returns ErrConflict. A stale IfMatch returns ErrConflict too. The result names the new commit and the file's new blob sha.

func (*Driver) Resolve

func (d *Driver) Resolve(ctx context.Context, source, ref string, ts oauth2.TokenSource) (string, error)

Resolve checks the repo and returns the commit ref points at. An empty ref means the repo's default branch. A missing repo or ref returns ErrNotFound, and so does a private repo the token can't read.

func (*Driver) Stat

Stat returns the file's git blob sha, the version a Put or Delete passes as IfMatch. A folder returns ErrInvalidArgument, and a missing file ErrNotFound. A snapshot mount returns ErrReadOnly, since its files have no versions to write against.

type Option

type Option func(*Driver)

Option configures a Driver.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL points the driver at another API root, such as a GitHub Enterprise host ("https://ghe.example.com/api/v3") or a test's fake.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets the client for every request. The default is http.DefaultClient.

func WithLimits

func WithLimits(l mounts.Limits) Option

WithLimits caps a snapshot's size and file count. A zero field keeps mounts.DefaultLimits' value. Past either, Prepare returns ErrTooLarge and stores no manifest.

func WithViews

func WithViews(dir string) Option

WithViews sets the folder where HostPath builds each snapshot's view, as hard links to its blobs, at <dir>/<mount name>/<commit>. It needs a blob store that is a blobs.Linker. Without it, HostPath returns ErrNotLocal, and the snapshot is served only as an fs.FS.

Directories

Path Synopsis
Package githubtest is a fake GitHub for tests of code that reads and writes repos: the mounts GitHub driver, the storage example app, and consumers' own tests.
Package githubtest is a fake GitHub for tests of code that reads and writes repos: the mounts GitHub driver, the storage example app, and consumers' own tests.

Jump to

Keyboard shortcuts

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