github

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRepoExists = errors.New("repository already exists")

ErrRepoExists is returned when CreateRepo encounters a 422 "name already exists" error.

Functions

This section is empty.

Types

type AuthenticatedUser

type AuthenticatedUser struct {
	Login  string
	Emails []string
}

AuthenticatedUser describes the token owner used for author checks.

type Client

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

Client wraps the go-github client with Scribe-specific helpers.

func NewClient

func NewClient(ctx context.Context, configToken string) *Client

NewClient creates a GitHub client using the auth chain:

  1. gh auth token (piggyback on gh CLI if installed)
  2. GITHUB_TOKEN environment variable
  3. token argument (pass "" to skip — loaded from config by caller)
  4. unauthenticated (public repos only)

func (*Client) AuthenticatedUser

func (c *Client) AuthenticatedUser(ctx context.Context) (AuthenticatedUser, error)

AuthenticatedUser returns the login and visible email addresses for the current token. Private email addresses may be unavailable depending on token scopes, so callers should also check local git config when enforcing author.

func (*Client) CreateRepo

func (c *Client) CreateRepo(ctx context.Context, owner, name, description string, private bool) (*github.Repository, error)

CreateRepo creates a new GitHub repository under the given owner. If owner matches the authenticated user, it creates a personal repo. Returns ErrRepoExists if the repo name is already taken.

func (*Client) DownloadReleaseAsset

func (c *Client) DownloadReleaseAsset(ctx context.Context, owner, repo string, id int64) (io.ReadCloser, error)

DownloadReleaseAsset downloads a release asset by ID, following redirects.

func (*Client) FetchDirectory

func (c *Client) FetchDirectory(ctx context.Context, owner, repo, dirPath, ref string) ([]SkillFile, error)

FetchDirectory downloads all files under dirPath at the given ref. Uses the Git Trees API (recursive) to enumerate files, then fetches each one.

func (*Client) FetchFile

func (c *Client) FetchFile(ctx context.Context, owner, repo, path, ref string) ([]byte, error)

FetchFile fetches a single file's content from a GitHub repo.

func (*Client) FileExists

func (c *Client) FileExists(ctx context.Context, owner, repo, path, ref string) (bool, error)

FileExists checks whether a file exists in a GitHub repo at the given ref.

func (*Client) GetTree

func (c *Client) GetTree(ctx context.Context, owner, repo, ref string) ([]TreeEntry, error)

GetTree returns a recursive tree listing for the given ref. Uses the GitHub Trees API with recursive=true for a single API call.

func (*Client) HasPushAccess

func (c *Client) HasPushAccess(ctx context.Context, owner, repo string) (bool, error)

HasPushAccess checks whether the authenticated user has push (write) access to the given repository. Returns false if unauthenticated or access denied.

func (*Client) IsAuthenticated

func (c *Client) IsAuthenticated() bool

IsAuthenticated returns true if the client has a GitHub token.

func (*Client) LatestCommitSHA

func (c *Client) LatestCommitSHA(ctx context.Context, owner, repo, branch string) (string, error)

LatestCommitSHA returns the current HEAD SHA for a branch. Used to detect updates for branch-pinned skills (e.g. @main).

func (*Client) LatestRelease

func (c *Client) LatestRelease(ctx context.Context, owner, repo string) (*github.RepositoryRelease, error)

LatestRelease fetches the latest published release for a repository.

func (*Client) PushFiles

func (c *Client) PushFiles(ctx context.Context, owner, repo string, files map[string]string, message string) error

PushFiles pushes files to a GitHub repo via the Git Trees API. Handles both empty repos (initial commit) and repos with existing content.

func (*Client) PushFilesAtomic

func (c *Client) PushFilesAtomic(ctx context.Context, owner, repo, branch string, files map[string][]byte, message, expectedHead string) (CommitResult, error)

PushFilesAtomic creates a single commit containing all file updates and moves refs/heads/<branch> to it. If expectedHead is non-empty and the branch moved since the caller checked it, the push is refused.

func (*Client) ReleaseAssetDigest

func (c *Client) ReleaseAssetDigest(ctx context.Context, owner, repo string, id int64) (string, error)

ReleaseAssetDigest returns GitHub's SHA-256 digest for a release asset.

func (*Client) RepositoryDefaultBranch

func (c *Client) RepositoryDefaultBranch(ctx context.Context, owner, repo string) (string, error)

RepositoryDefaultBranch returns a repository's default branch.

func (*Client) RepositoryIsPrivate

func (c *Client) RepositoryIsPrivate(ctx context.Context, owner, repo string) (bool, error)

RepositoryIsPrivate returns the GitHub repository privacy flag.

type CommitResult

type CommitResult struct {
	SHA string
	URL string
}

CommitResult describes a pushed GitHub commit.

type SkillFile

type SkillFile struct {
	Path    string // relative to the skill root (e.g. "scripts/deploy.sh")
	Content []byte
}

SkillFile is a single file within a downloaded skill directory.

type TreeEntry

type TreeEntry struct {
	Path string // full path from repo root (e.g. "skills/deploy/SKILL.md")
	Type string // "blob" or "tree"
	SHA  string
}

TreeEntry represents a single entry from a recursive Git tree listing.

Jump to

Keyboard shortcuts

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