github

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 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) 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) 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 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"`
}

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