github

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 13 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 little of GitHub's REST API that mcloud needs: read files, and commit several file changes at once to a branch.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned for a missing repo, branch or file.

Functions

func Token

func Token() (string, error)

Token finds a GitHub token: $GH_TOKEN, $GITHUB_TOKEN, or the GitHub CLI's login (`gh auth token`).

Types

type Change

type Change struct {
	Path    string
	Content []byte
}

Change is one file in a commit. A nil Content deletes the file.

type Client

type Client struct {
	BaseURL string // https://api.github.com
	Token   string
	HTTP    *http.Client
}

func New

func New(token string) *Client

func (*Client) Commit

func (c *Client) Commit(ctx context.Context, repo Repo, branch, message string, plan func(Reader) ([]Change, error)) (string, error)

Commit builds one commit on branch from the changes plan returns, and moves the branch to it. If the branch moves in the meantime, it starts over from the new head, so plan must be safe to call more than once. A plan that returns no changes makes no commit. Returns the new commit's SHA.

func (*Client) Commits added in v0.17.0

func (c *Client) Commits(ctx context.Context, repo Repo, ref, path string, n int) ([]Commit, error)

Commits lists the newest commits reachable from ref (a branch or SHA) that change path, newest first, at most n (up to 100).

func (*Client) Dir added in v0.17.0

func (c *Client) Dir(ctx context.Context, repo Repo, ref, dir string) ([]string, error)

Dir lists the names of the files in a directory at ref; ErrNotFound if there's no such directory.

func (*Client) Dispatch

func (c *Client) Dispatch(ctx context.Context, repo Repo, workflow, ref string) error

Dispatch starts a workflow that has a workflow_dispatch trigger.

func (*Client) Exists

func (c *Client) Exists(ctx context.Context, repo Repo, ref, p string) (bool, error)

Exists reports whether a file or directory exists at ref.

func (*Client) File

func (c *Client) File(ctx context.Context, repo Repo, ref, file string) ([]byte, error)

File reads a file at ref (a branch name or commit SHA).

func (*Client) Head

func (c *Client) Head(ctx context.Context, repo Repo, branch string) (string, error)

Head is the commit a branch points at.

func (*Client) RepoExists

func (c *Client) RepoExists(ctx context.Context, repo Repo) (bool, error)

RepoExists reports whether the token can see the repo.

func (*Client) RestoreDir added in v0.17.0

func (c *Client) RestoreDir(ctx context.Context, repo Repo, branch, dir, from, message string) (string, error)

RestoreDir commits dir on branch as it was at commit from: one new commit on top of the branch's head (no history is rewritten), with the files from then and without those added since. The rest of the repo stays as it is. Returns the new commit's SHA, or "" if dir is already like that.

func (*Client) Run

func (c *Client) Run(ctx context.Context, repo Repo, id int64) (*Run, error)

Run reads one workflow run.

func (*Client) RunsFor

func (c *Client) RunsFor(ctx context.Context, repo Repo, sha string) ([]Run, error)

RunsFor lists the workflow runs for a commit, newest first.

type Commit added in v0.17.0

type Commit struct {
	SHA     string
	Message string
	Author  string // GitHub login, else the git author's name
	Date    time.Time
}

Commit is one commit, as a history lists it.

func (Commit) Subject added in v0.17.0

func (c Commit) Subject() string

Subject is the message's first line.

type Reader

type Reader func(path string) ([]byte, error)

Reader reads a file as of the commit being built on; ErrNotFound if absent.

type Repo

type Repo string

Repo is "<owner>/<name>".

type Run

type Run struct {
	ID         int64  `json:"id"`
	Name       string `json:"name"`
	Status     string `json:"status"`     // queued, in_progress, completed, ...
	Conclusion string `json:"conclusion"` // success, failure, cancelled, ...
	HTMLURL    string `json:"html_url"`
	Event      string `json:"event"`
	Path       string `json:"path"` // the workflow file: .github/workflows/deploy.yaml
}

Run is a GitHub Actions workflow run.

Jump to

Keyboard shortcuts

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