github

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 15 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 small GitHub REST client bedrock needs: the organization's installed apps, its Actions secrets, its rulesets and its policy on immutable releases, a repository's rulesets, its refs, tags, comparisons and directory listings, whether it is empty, its workflows, the check runs on a commit, its deployment environments, its issues, its pull requests with their comments and deployments, and a GitHub App's installation token. It speaks to one API host with one token, sends a read again when GitHub stalls or answers a gateway error, and translates the API's refusals into errors that carry the status and the message.

Index

Constants

View Source
const (
	// DefaultBase is the public API host.
	DefaultBase = "https://api.github.com"
	// TokenEnv is the variable a token is read from before gh is asked.
	TokenEnv = "GITHUB_TOKEN"
)
View Source
const (
	ImmutableReleasesAll      = "all"
	ImmutableReleasesNone     = "none"
	ImmutableReleasesSelected = "selected"
)

What an organization's policy on immutable releases holds to them: every repository of the organization, none of them (each repository's own setting decides), or the ones an owner selected.

View Source
const (
	VisibilityAll     = "all"
	VisibilityPrivate = "private"
)

VisibilityAll is a variable's or a runner group's visibility when every repository of the organization sees it; VisibilityPrivate a variable's when its private repositories alone do.

View Source
const (
	RulesetTargetBranch  = "branch"
	RulesetTargetTag     = "tag"
	RulesetActive        = "active"
	BypassIntegration    = "Integration"
	BypassAlways         = "always"
	DefaultBranchPattern = "~DEFAULT_BRANCH"
)

The words the API uses for a ruleset on branches or on tags, in force, and an app as a bypass actor that always bypasses.

View Source
const AllRepositories = "all"

AllRepositories is an installation's repository selection when it covers every repository of the account, the ones made after it included.

View Source
const VisibilitySelected = "selected"

VisibilitySelected is a secret's visibility when only the repositories selected for it see it.

Variables

This section is empty.

Functions

func BotAccount

func BotAccount(ctx context.Context, open func(token string) *Client, token, organization string) (string, error)

BotAccount reads whose the token is and that the account owns the organization, through a client opened with it, and answers the login: the GitHub Bot Account, whose token every Cloud Build connection authorizes with. A token an app was issued is refused first, by its prefix, as not a personal access token, whatever account it names; so are a token of no member and a member's that is not an owner's.

func IssuedByApp

func IssuedByApp(token string) string

IssuedByApp says what a token that an app was issued is, by its prefix, or answers "" for any other token (a personal access token among them).

func ManifestFormURL

func ManifestFormURL(organization, state string) string

ManifestFormURL is where the browser posts a manifest to make an app owned by the organization: GitHub's page for a new app of the organization, carrying the state the redirect gives back, so the receiver knows the code is its own.

func Moved

func Moved(err error) bool

Moved reports whether the error is the API's redirect (301 for a repository renamed away from the name asked for, whose old name GitHub forwards until a new repository takes it). The client follows no redirect, so a renamed repository is never mistaken for the one named (the lab, 2026-11-05: the bootstrap read the renamed hand-built root's repository under the new root's name).

func NotAccessible added in v0.1.3

func NotAccessible(err error) bool

NotAccessible reports whether the error is GitHub's refusal of a token that lacks the permission a request takes: a 403 whose message says so. GitHub gives that answer before it looks for what the request names, so it says nothing of whether that stands. A 403 for another reason (a rate limit, an organization's single sign-on) is not one.

func NotFound

func NotFound(err error) bool

NotFound reports whether the error is the API's 404.

func Token

func Token(ctx context.Context) (string, error)

Token is the token the account has: GITHUB_TOKEN when set, else the token gh holds for its signed-in account. With neither it refuses.

Types

type Account

type Account struct {
	Login string `json:"login"`
	// Type is User or Organization.
	Type string `json:"type"`
}

Account is a user or an organization on GitHub, by its login.

type App

type App struct {
	ID       int64   `json:"id"`
	Slug     string  `json:"slug"`
	Name     string  `json:"name"`
	ClientID string  `json:"client_id"`
	HTMLURL  string  `json:"html_url"`
	Owner    Account `json:"owner"`
	// Permissions are the app's, by GitHub's name of each (contents, administration,
	// organization_self_hosted_runners) to its level (read, write, admin).
	Permissions map[string]string `json:"permissions"`
	// Events are the webhook events the app subscribes to; none for an app without a
	// webhook.
	Events        []string `json:"events"`
	PEM           string   `json:"pem,omitempty"`
	ClientSecret  string   `json:"client_secret,omitempty"`
	WebhookSecret string   `json:"webhook_secret,omitempty"`
}

App is a GitHub App as GitHub describes it to the app itself (GET /app), or as the conversion of a manifest hands it over: then with the private key, the client secret and the webhook secret, which GitHub gives that once and never again.

type Branch

type Branch struct {
	Name   string `json:"name"`
	Commit Object `json:"commit"`
}

Branch is one of the repository's branches with the commit it points at.

type BranchPolicy

type BranchPolicy struct {
	ProtectedBranches    bool `json:"protected_branches"`
	CustomBranchPolicies bool `json:"custom_branch_policies"`
}

BranchPolicy is how an environment limits the branches that deploy to it: to the repository's protected branches, or to the branches its own patterns name (EnvironmentBranches). GitHub takes one of the two, never both.

type BypassActor

type BypassActor struct {
	ActorID    int64  `json:"actor_id"`
	ActorType  string `json:"actor_type"`
	BypassMode string `json:"bypass_mode"`
}

BypassActor is one actor the rules do not hold for.

type CheckApp

type CheckApp struct {
	ID   int64  `json:"id"`
	Slug string `json:"slug"`
}

CheckApp is the GitHub App a check run was reported by: its App ID, which a required check names its reporter by, and its slug.

type CheckRun

type CheckRun struct {
	Name       string   `json:"name"`
	Status     string   `json:"status"`
	Conclusion string   `json:"conclusion"`
	App        CheckApp `json:"app"`
}

CheckRun is one check run on a commit: the check's name, its status (queued, in_progress, completed), its conclusion once it completed (success, failure, skipped and GitHub's other words for how a run ended; empty until then) and the app that reported it.

type Client

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

Client speaks to one GitHub API host with one token.

func New

func New(base, token string) *Client

New is a client over the API at base, authenticated with the token; with none (""), its requests carry no credential, which the conversion of an app manifest alone takes (ConvertManifest). It carries a transport of its own, a copy of the default one, so nothing that closes the default transport's idle connections (a test server's close does) touches a request of its in flight.

func Open

func Open(ctx context.Context) (*Client, error)

Open finds a token and returns a client over the public API: GITHUB_TOKEN when set, else the token gh holds for its signed-in account. With neither it refuses.

func (*Client) AddEnvironmentBranch

func (c *Client) AddEnvironmentBranch(ctx context.Context, owner, repo, name, pattern string) error

AddEnvironmentBranch lets the branches the pattern names deploy to the environment. GitHub documents two refusals worth knowing: 404 for an environment that is absent or does not keep patterns of its own (PutEnvironment makes it one that does), and 303 for a pattern the environment already has, which the client, following no redirect, returns as an error Moved reports; so a caller adds only what EnvironmentBranches lacks.

func (*Client) App

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

App is the app the client's JWT signs as: GitHub's answer to the app itself, which it gives for a JWT signed with the app's own key alone. The client's token is the app's JWT, not an installation token.

func (*Client) AppBySlug

func (c *Client) AppBySlug(ctx context.Context, slug string) (*App, error)

AppBySlug reads a public app by its slug (github.com/apps/<slug>): Google's Cloud Build app, whose id a required check names as its reporter.

func (*Client) AppInstallations

func (c *Client) AppInstallations(ctx context.Context) ([]Installation, error)

AppInstallations lists where the app the client's JWT signs as is installed. One page holds a hundred, and an app bedrock acts as is installed on one organization.

func (*Client) Archive

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

Archive marks the repository archived: read-only on GitHub, with its code, pull requests and releases kept, until a person unarchives it in the repository's settings. GitHub answers the repository as it now stands, which is discarded.

func (*Client) Base

func (c *Client) Base() string

Base is the API host the client speaks to.

func (*Client) CheckRuns

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

CheckRuns lists the check runs on the commit ref names (a commit SHA, or a branch or tag by name, whose head it is), every page of them. GitHub lists the latest run of each check, not the runs a later one replaced.

func (*Client) CloseIssue

func (c *Client) CloseIssue(ctx context.Context, owner, repo string, number int) error

CloseIssue closes the issue with the number; one already closed stays closed.

func (*Client) Compare

func (c *Client) Compare(ctx context.Context, owner, repo, base, head string) (*Comparison, error)

Compare compares head against base (a commit, branch or tag each).

func (*Client) Contents

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

Contents reads the file at path as it is at ref.

func (*Client) ConvertManifest

func (c *Client) ConvertManifest(ctx context.Context, code string) (*App, error)

ConvertManifest makes the app a manifest describes, from the code GitHub sent the browser to the manifest's redirect URL once a person submitted the form (the code is good for an hour, once). The answer carries the app's private key and client secret; the client needs no token for it.

func (*Client) CreateBlob

func (c *Client) CreateBlob(ctx context.Context, owner, repo string, content []byte) (string, error)

CreateBlob stores the content and returns its SHA.

func (*Client) CreateComment

func (c *Client) CreateComment(ctx context.Context, owner, repo string, number int, body string) error

CreateComment posts a comment on an issue or pull request as the token's account.

func (*Client) CreateCommit

func (c *Client) CreateCommit(ctx context.Context, owner, repo, message, tree string, parents []string) (string, error)

CreateCommit makes a commit of the tree on the parents and returns its SHA. The author is the token's account.

func (*Client) CreateDeployment

func (c *Client) CreateDeployment(ctx context.Context, owner, repo string, d *DeploymentRequest) (int64, error)

CreateDeployment creates the deployment and answers its id.

func (*Client) CreateDeploymentStatus

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

CreateDeploymentStatus adds a status to the deployment.

func (*Client) CreateHostedRunner

func (c *Client) CreateHostedRunner(ctx context.Context, org string, in HostedRunnerRequest) (*HostedRunner, error)

CreateHostedRunner makes the runner and answers it with its id.

func (*Client) CreateIssue

func (c *Client) CreateIssue(ctx context.Context, owner, repo, title, body string) (*Issue, error)

CreateIssue opens an issue with the title and the body as the token's account, and answers it with its number.

func (*Client) CreateOrgRuleset

func (c *Client) CreateOrgRuleset(ctx context.Context, org string, in *Ruleset) (*Ruleset, error)

CreateOrgRuleset makes the ruleset on the organization and answers it with its id. GitHub wants the repositories named beside the branches or tags in the conditions of a ruleset on either (Conditions.RepositoryName).

func (*Client) CreateOrgVariable

func (c *Client) CreateOrgVariable(ctx context.Context, org string, v Variable) error

CreateOrgVariable makes the variable.

func (*Client) CreatePullRequest

func (c *Client) CreatePullRequest(ctx context.Context, owner, repo string, in PullRequestRequest) (*PullRequest, error)

CreatePullRequest opens a pull request as the token's account.

func (*Client) CreateRef

func (c *Client) CreateRef(ctx context.Context, owner, repo, ref, sha string) error

CreateRef creates the full reference (refs/heads/...) at the commit.

func (*Client) CreateRepository

func (c *Client) CreateRepository(ctx context.Context, org string, in RepositoryRequest) (*Repository, error)

CreateRepository creates the repository in the organization (POST /orgs/{org}/repos; the token's app needs the Administration repository permission).

func (*Client) CreateRuleset

func (c *Client) CreateRuleset(ctx context.Context, owner, repo string, in *Ruleset) (*Ruleset, error)

CreateRuleset makes the ruleset on the repository and answers it with its id.

func (*Client) CreateRunnerGroup

func (c *Client) CreateRunnerGroup(ctx context.Context, org string, in RunnerGroup) (*RunnerGroup, error)

CreateRunnerGroup makes the group and answers it with its id.

func (*Client) CreateTree

func (c *Client) CreateTree(ctx context.Context, owner, repo, baseTree string, entries []TreeEntry) (string, error)

CreateTree makes a tree from the base tree with the entries changed, or from the entries alone when baseTree is empty (the field is left out then: GitHub refuses an empty one as not a tree id, 422), and returns its SHA.

func (*Client) DeleteEnvironmentSecret

func (c *Client) DeleteEnvironmentSecret(ctx context.Context, owner, repo, environment, name string) error

DeleteEnvironmentSecret removes the environment's secret.

func (*Client) DeleteHostedRunner added in v0.1.2

func (c *Client) DeleteHostedRunner(ctx context.Context, org string, id int64) error

DeleteHostedRunner removes the runner. GitHub takes the removal (202) and the listing shows the runner as Deleting until it is gone, whether or not the runner is running a job; a job it is running finishes.

func (*Client) DeleteOrgRuleset

func (c *Client) DeleteOrgRuleset(ctx context.Context, org string, id int64) error

DeleteOrgRuleset removes the organization's ruleset with the id; its rules stop holding on every repository it named.

func (*Client) DeleteOrgSecret

func (c *Client) DeleteOrgSecret(ctx context.Context, org, name string) error

DeleteOrgSecret removes the organization's secret.

func (*Client) DeleteOrgVariable

func (c *Client) DeleteOrgVariable(ctx context.Context, org, name string) error

DeleteOrgVariable removes the variable.

func (*Client) Deployments

func (c *Client) Deployments(ctx context.Context, owner, repo, environment string) ([]int64, error)

Deployments lists the ids of the environment's deployments, newest first, up to a hundred.

func (*Client) Directory

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

Directory lists the directory at path as it is at ref. A path that is not there is the API's 404 (NotFound reports it); a path that names a file is refused.

func (*Client) DispatchWorkflow

func (c *Client) DispatchWorkflow(ctx context.Context, owner, repo, file, ref string, inputs map[string]string) error

DispatchWorkflow starts the workflow file's workflow_dispatch event on ref, with the inputs the workflow declares.

func (*Client) Empty

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

Empty reports whether the repository has no branch: nothing has been pushed to it yet. GitHub lists no branch for such a repository (and answers its commits with 409, Git Repository is empty), so the first branch alone is asked for.

func (*Client) EnforceImmutableReleases added in v0.1.2

func (c *Client) EnforceImmutableReleases(ctx context.Context, org string) error

EnforceImmutableReleases sets the organization's policy to every repository (PUT /orgs/{org}/settings/immutable-releases, which takes write access to the organization's Administration): the repositories it has and the ones made after. There is no call here that narrows the policy or turns it off: bedrock never does.

func (*Client) Environment

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

Environment reads the repository's environment; an absent one is NotFound.

func (*Client) EnvironmentBranches

func (c *Client) EnvironmentBranches(ctx context.Context, owner, repo, name string) ([]string, error)

EnvironmentBranches lists the name patterns of the branches that may deploy to the environment (master, release/*), up to a hundred; tags' patterns are left out (EnvironmentPatterns answers both). An absent environment is NotFound.

func (*Client) EnvironmentPatterns

func (c *Client) EnvironmentPatterns(ctx context.Context, owner, repo, name string) (branches, tags []string, err error)

EnvironmentPatterns lists the name patterns of what may deploy to the environment, up to a hundred: the branches' (master, release/*) and the tags' (v*). A workflow that runs on a ref either list matches is handed the environment's secrets, so a caller that keeps a secret there reads both. An absent environment is NotFound.

func (*Client) EnvironmentSecret

func (c *Client) EnvironmentSecret(ctx context.Context, owner, repo, environment, name string) (*EnvironmentSecret, error)

EnvironmentSecret reads the environment's secret, without its value; an absent one is NotFound, and so is any secret of an environment the repository lacks.

func (*Client) GetCommit

func (c *Client) GetCommit(ctx context.Context, owner, repo, sha string) (*Commit, error)

GetCommit reads the commit.

func (*Client) HostedRunners

func (c *Client) HostedRunners(ctx context.Context, org string) ([]HostedRunner, error)

HostedRunners lists the organization's GitHub-hosted runners.

func (*Client) InstallationToken

func (c *Client) InstallationToken(ctx context.Context, installation int64) (string, error)

InstallationToken mints a token for the installation, good for an hour. The client's token is the app's JWT.

func (*Client) IssueComments

func (c *Client) IssueComments(ctx context.Context, owner, repo string, number int) ([]Comment, error)

IssueComments lists the latest comments on an issue or pull request, oldest first: the last page of a hundred, and the page before it when the last holds fewer than five, so the instruction a build ran on is found without walking a long thread.

func (*Client) LatestPullRequest

func (c *Client) LatestPullRequest(ctx context.Context, owner, repo, base string) (*PullRequest, error)

LatestPullRequest is the pull request opened last into the base branch, whatever its state (open, closed or merged), with its head's commit; it answers nil when the repository has none into that branch.

func (*Client) OpenIssue

func (c *Client) OpenIssue(ctx context.Context, owner, repo, title string) (*Issue, error)

OpenIssue finds the repository's open issue whose title is exactly title, the newest when several carry it, and answers nil when none does. It reads the open issues, every page of them until the title is found; GitHub lists the open pull requests among them, each marked with a pull_request key, and those are passed over.

func (*Client) OpenRunnerGroup

func (c *Client) OpenRunnerGroup(ctx context.Context, org string, id int64, public bool) error

OpenRunnerGroup opens the group to the organization's public repositories, or closes it to them.

func (*Client) OrgImmutableReleases added in v0.1.2

func (c *Client) OrgImmutableReleases(ctx context.Context, org string) (string, error)

OrgImmutableReleases reads which repositories the organization's policy holds to immutable releases: all, none or selected (GET /orgs/{org}/settings/immutable-releases, which takes read access to the organization's Administration: GitHub names the permission in its answer, X-Accepted-Github-Permissions: organization_administration=read). A token with that access is answered the policy and a token without it not found (read 2026-11-12: an owner is answered {"enforced_repositories":"none"}, a member who is no owner 404), so NotFound here says the token cannot read the policy, never that the policy is off.

func (*Client) OrgInstallations

func (c *Client) OrgInstallations(ctx context.Context, org string) ([]OrgInstallation, error)

OrgInstallations lists the apps installed on the organization. The token needs the organization's administration read: an owner's, or an app's with the Administration organization permission.

func (*Client) OrgMembership

func (c *Client) OrgMembership(ctx context.Context, org string) (string, error)

OrgMembership is the role the client's token's user holds in the organization (admin for an owner, member), or NotFound when the user is not a member.

func (*Client) OrgRuleset

func (c *Client) OrgRuleset(ctx context.Context, org string, id int64) (*Ruleset, error)

OrgRuleset reads one of the organization's rulesets whole: its actors, conditions and rules. An id the organization has no ruleset under is NotFound.

func (*Client) OrgRulesets

func (c *Client) OrgRulesets(ctx context.Context, org string) ([]Ruleset, error)

OrgRulesets lists the organization's rulesets, each with its id, name, target and enforcement, up to a hundred; the rules are read one ruleset at a time (OrgRuleset).

func (*Client) OrgSecret

func (c *Client) OrgSecret(ctx context.Context, org, name string) (*OrgSecret, error)

OrgSecret reads the organization's secret, without its value; an absent one is NotFound.

func (*Client) OrgSecretRepositories

func (c *Client) OrgSecretRepositories(ctx context.Context, org, name string) ([]Repository, error)

OrgSecretRepositories lists the repositories selected for the organization's secret, every page of them.

func (*Client) OrgVariable

func (c *Client) OrgVariable(ctx context.Context, org, name string) (*Variable, error)

OrgVariable reads the organization's variable; an absent one is NotFound.

func (*Client) PullRequestState

func (c *Client) PullRequestState(ctx context.Context, owner, repo string, number int) (string, error)

PullRequestState is the pull request's state: open or closed (merged is closed).

func (*Client) PullRequestsFrom

func (c *Client) PullRequestsFrom(ctx context.Context, owner, repo, branch string) ([]PullRequest, error)

PullRequestsFrom lists the pull requests whose head is the branch, open and closed, newest first.

func (*Client) PutEnvironment

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

PutEnvironment makes the repository's environment, or sets the one there is, as an environment only the branches its patterns name may deploy to: none until AddEnvironmentBranch names one.

func (*Client) PutEnvironmentSecret

func (c *Client) PutEnvironmentSecret(ctx context.Context, owner, repo, environment, name string, value []byte) error

PutEnvironmentSecret makes the environment's secret, or replaces its value. It reads the environment's public key and sends the value sealed with it, as PutOrgSecret does an organization's, so the value crosses the wire readable by GitHub alone. The value is in no error this returns.

func (*Client) PutOrgSecret

func (c *Client) PutOrgSecret(ctx context.Context, org, name string, value []byte, repositoryIDs []int64) error

PutOrgSecret makes the organization's secret, or replaces its value and its selection, visible to the repositories with the ids alone (none sees it when there are none). It reads the organization's public key and sends the value sealed with it (a libsodium sealed box, the only form GitHub takes), so the value crosses the wire readable by GitHub alone. The value is in no error this returns.

func (*Client) Ref

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

Ref reads the reference named without its refs/ prefix (heads/master, tags/v1.0.0). An absent reference is NotFound.

func (*Client) Release

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

Release reads the release a tag belongs to; a tag without one is NotFound.

func (*Client) RenameBranch

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

RenameBranch renames the branch (POST /repos/{owner}/{repo}/branches/{branch}/rename), which makes the new name the default when the branch was. A new repository's initial branch is named after the organization's setting whatever the creation asks (the lab, 2026-11-06), so a creator renames it to the branch it wants.

func (*Client) Repository

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

Repository reads the repository; an absent one is NotFound.

func (*Client) RepositoryInstallation

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

RepositoryInstallation is the id of the GitHub App's installation on the repository. The client's token is the app's JWT, not an installation token.

func (*Client) RepositorySettings

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

RepositorySettings reads the repository's merge settings.

func (*Client) Ruleset

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

Ruleset reads one ruleset whole: its actors, conditions and rules.

func (*Client) Rulesets

func (c *Client) Rulesets(ctx context.Context, owner, repo string) ([]Ruleset, error)

Rulesets lists the repository's own rulesets, each with its id, name and enforcement; the rules are read one ruleset at a time (Ruleset).

func (*Client) RunnerGroups

func (c *Client) RunnerGroups(ctx context.Context, org string) ([]RunnerGroup, error)

RunnerGroups lists the organization's runner groups.

func (*Client) SetOrgSecretRepositories

func (c *Client) SetOrgSecretRepositories(ctx context.Context, org, name string, repositoryIDs []int64) error

SetOrgSecretRepositories replaces the selection of the organization's secret with the repositories with the ids: the ones left out stop seeing it, and none sees it when there are none. The value stays as it is.

func (*Client) SetRepositoryPrivate

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

SetRepositoryPrivate makes the repository private, or public when private is false (PATCH /repos/{owner}/{repo} with private alone, so nothing else of the repository changes). GitHub documents a 422 for a token that is not an owner's where the organization keeps the change of a repository's visibility to its owners.

func (*Client) TagCommit

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

TagCommit resolves the tag to the commit it names: a lightweight tag points at the commit, an annotated tag at a tag object that names it.

func (*Client) Tags

func (c *Client) Tags(ctx context.Context, owner, repo string) ([]Tag, error)

Tags lists the repository's tags, every page of them.

func (*Client) UpdateComment

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

UpdateComment replaces the body of a comment on an issue or pull request, by the comment's id, as the token's account.

func (*Client) UpdateHostedRunner

func (c *Client) UpdateHostedRunner(ctx context.Context, org string, id, group int64, maximum int) error

UpdateHostedRunner moves the runner to the group and sets its ceiling; the size and the image cannot change in place.

func (*Client) UpdateOrgRuleset

func (c *Client) UpdateOrgRuleset(ctx context.Context, org string, id int64, in *Ruleset) error

UpdateOrgRuleset replaces the organization's ruleset with the id by what in says.

func (*Client) UpdateOrgVariable

func (c *Client) UpdateOrgVariable(ctx context.Context, org string, v Variable) error

UpdateOrgVariable sets the variable's value and visibility.

func (*Client) UpdateRef

func (c *Client) UpdateRef(ctx context.Context, owner, repo, ref, sha string, force bool) error

UpdateRef moves the reference (heads/master, without its refs/ prefix) to the commit; a fast-forward unless force is set.

func (*Client) UpdateRepositorySettings

func (c *Client) UpdateRepositorySettings(ctx context.Context, owner, repo string, in *RepositorySettings) error

UpdateRepositorySettings sets the merge settings given (the pointers set).

func (*Client) UpdateRuleset

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

UpdateRuleset replaces the ruleset with the id by what in says.

func (*Client) User

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

User is the login the client's token belongs to.

func (*Client) Workflows

func (c *Client) Workflows(ctx context.Context, owner, repo string) ([]Workflow, error)

Workflows lists the repository's workflows, every page of them.

type ClientFunc

type ClientFunc func(ctx context.Context) (*Client, error)

ClientFunc opens the client: the CLI wires Open, tests a client over a test server.

type Comment

type Comment struct {
	ID   int64  `json:"id"`
	Body string `json:"body"`
}

Comment is one comment on an issue or a pull request.

type Commit

type Commit struct {
	SHA  string `json:"sha"`
	Tree Object `json:"tree"`
}

Commit is a commit's tree, which a new tree is built from.

type ComparedFile

type ComparedFile struct {
	Filename string `json:"filename"`
}

ComparedFile is one file a comparison lists.

type Comparison

type Comparison struct {
	Status          string         `json:"status"`
	MergeBaseCommit Object         `json:"merge_base_commit"`
	Files           []ComparedFile `json:"files"`
}

Comparison is how head relates to base: identical, ahead (head has commits base lacks), behind, or diverged; the commit the two share; and the files that differ between the merge base and head (the API lists up to 300).

type DeploymentRequest

type DeploymentRequest struct {
	Ref                  string   `json:"ref"`
	Environment          string   `json:"environment"`
	Description          string   `json:"description"`
	TransientEnvironment bool     `json:"transient_environment"`
	AutoMerge            bool     `json:"auto_merge"`
	RequiredContexts     []string `json:"required_contexts"`
}

DeploymentRequest is a deployment to create: the commit it deploys and the environment it goes to. A transient environment is one that goes away (a pull request's).

type DeploymentStatus

type DeploymentStatus struct {
	State          string `json:"state"`
	EnvironmentURL string `json:"environment_url,omitempty"`
	LogURL         string `json:"log_url,omitempty"`
	Description    string `json:"description,omitempty"`
	AutoInactive   bool   `json:"auto_inactive,omitempty"`
}

DeploymentStatus is a deployment's state (success, inactive, failure) with where the environment is served and where the build's log is. AutoInactive marks the earlier deployments of the environment inactive when this one succeeds.

type DirEntry

type DirEntry struct {
	Name string `json:"name"`
	SHA  string `json:"sha"`
	Type string `json:"type"`
}

DirEntry is one entry of a directory as a commit holds it: its name, its git object SHA (for a file, the blob's, which git hash-object computes from the content) and its type (file, dir, symlink, submodule).

type Environment

type Environment struct {
	Name         string        `json:"name"`
	BranchPolicy *BranchPolicy `json:"deployment_branch_policy"`
}

Environment is a deployment environment of a repository: its name and which branches may deploy to it. BranchPolicy is nil for an environment any branch may deploy to.

type EnvironmentSecret

type EnvironmentSecret struct {
	Name      string    `json:"name"`
	UpdatedAt time.Time `json:"updated_at"`
}

EnvironmentSecret is an Actions secret of a deployment environment as the API describes it: its name and when its value was last written. The value itself is never read back.

type Error

type Error struct {
	Status  int
	Message string
	Method  string
	Path    string
}

Error is the API's refusal: the status it answered and the message it gave.

func (*Error) Error

func (e *Error) Error() string

type HookAttributes

type HookAttributes struct {
	URL    string `json:"url,omitempty"`
	Active bool   `json:"active"`
}

HookAttributes is the manifest's webhook: off (Active false) for an app that is only ever a credential.

type HostedRunner

type HostedRunner struct {
	ID             int64        `json:"id,omitempty"`
	Name           string       `json:"name"`
	RunnerGroupID  int64        `json:"runner_group_id"`
	Image          RunnerImage  `json:"image"`
	MachineSize    *MachineSize `json:"machine_size_details,omitempty"`
	MaximumRunners int          `json:"maximum_runners,omitempty"`
	Status         string       `json:"status,omitempty"`
}

HostedRunner is a GitHub-hosted runner of the organization: its image, its machine size, its group and how many may run at once.

type HostedRunnerRequest

type HostedRunnerRequest struct {
	Name           string      `json:"name"`
	Image          RunnerImage `json:"image"`
	Size           string      `json:"size"`
	RunnerGroupID  int64       `json:"runner_group_id"`
	MaximumRunners int         `json:"maximum_runners,omitempty"`
	EnableStaticIP bool        `json:"enable_static_ip"`
}

HostedRunnerRequest makes a hosted runner: GitHub's image, the machine size (4-core, 8-core, as GitHub names them), the group and the ceiling.

type Installation

type Installation struct {
	ID      int64   `json:"id"`
	AppID   int64   `json:"app_id"`
	Account Account `json:"account"`
	// RepositorySelection is all or selected.
	RepositorySelection string `json:"repository_selection"`
}

Installation is one installation of an app: on which account, and on all of its repositories or a selection of them.

type Issue

type Issue struct {
	Number  int    `json:"number"`
	Title   string `json:"title"`
	State   string `json:"state"`
	HTMLURL string `json:"html_url"`
}

Issue is an issue of a repository: its number, its title, its state (open or closed) and its page.

type MachineSize

type MachineSize struct {
	ID       string `json:"id"`
	CPUCores int    `json:"cpu_cores"`
}

MachineSize is a hosted runner's size as the listing gives it (its id is the size name the creation took: 4-core).

type Manifest

type Manifest struct {
	// Name is the app's name, unique across GitHub, at most 34 characters.
	Name string `json:"name"`
	// URL is the app's homepage.
	URL            string         `json:"url"`
	HookAttributes HookAttributes `json:"hook_attributes"`
	// RedirectURL is where GitHub sends the browser, with the code, once the app is
	// made.
	RedirectURL string `json:"redirect_url"`
	// SetupURL is where GitHub sends the browser once the app is installed, with the
	// installation's id; none leaves the browser on GitHub.
	SetupURL      string `json:"setup_url,omitempty"`
	SetupOnUpdate bool   `json:"setup_on_update"`
	Description   string `json:"description"`
	// Public says whether any account may install the app; false keeps it to the
	// organization that owns it.
	Public bool `json:"public"`
	// DefaultEvents are the webhook events; none for an app without a webhook.
	DefaultEvents []string `json:"default_events"`
	// DefaultPermissions are the app's permissions, by GitHub's name of each to its
	// level.
	DefaultPermissions map[string]string `json:"default_permissions"`
}

Manifest is a GitHub App manifest: what a browser posts to GitHub, as the manifest field of a form, for a person to make the app with one click. GitHub then sends the browser to the redirect URL with a code, which ConvertManifest turns into the app.

type Object

type Object struct {
	Type string `json:"type"`
	SHA  string `json:"sha"`
}

Object is what a ref or a tag points at: a commit, or for an annotated tag a tag object.

type OrgInstallation

type OrgInstallation struct {
	ID                  int64  `json:"id"`
	AppID               int64  `json:"app_id"`
	AppSlug             string `json:"app_slug"`
	RepositorySelection string `json:"repository_selection"`
}

OrgInstallation is one app installed on an organization, as the organization's listing describes it: the installation's id, the app's id and slug.

type OrgSecret

type OrgSecret struct {
	Name       string    `json:"name"`
	Visibility string    `json:"visibility"`
	UpdatedAt  time.Time `json:"updated_at"`
}

OrgSecret is an organization's Actions secret as the API describes it: its name, its visibility (all, private or selected) and when its value was last written. The value itself is never read back.

type PullRequest

type PullRequest struct {
	Number   int            `json:"number"`
	State    string         `json:"state"`
	HTMLURL  string         `json:"html_url"`
	MergedAt string         `json:"merged_at"`
	Title    string         `json:"title"`
	Head     PullRequestRef `json:"head"`
	Base     PullRequestRef `json:"base"`
}

PullRequest is a pull request as the API answers it: its number, its state (open or closed; a merged one is closed with MergedAt set), its page, and its head and base.

type PullRequestRef

type PullRequestRef struct {
	Ref string `json:"ref"`
	SHA string `json:"sha"`
}

PullRequestRef is a pull request's head or base: the branch and its commit.

type PullRequestRequest

type PullRequestRequest struct {
	Title string `json:"title"`
	Body  string `json:"body"`
	Head  string `json:"head"`
	Base  string `json:"base"`
}

PullRequestRequest is a pull request to open: its title, its body, the head branch (a branch of the repository) and the base branch it goes into.

type Ref

type Ref struct {
	Ref    string `json:"ref"`
	Object Object `json:"object"`
}

Ref is a git reference and the object it points at.

type RefNameCondition

type RefNameCondition struct {
	Include []string `json:"include"`
	Exclude []string `json:"exclude"`
}

RefNameCondition includes and excludes branches or tags by pattern.

type Release

type Release struct {
	TagName string `json:"tag_name"`
	Author  User   `json:"author"`
	Body    string `json:"body"`
}

Release is a GitHub Release: the tag it names, who cut it, and its notes.

type Repository

type Repository struct {
	ID            int64  `json:"id"`
	Name          string `json:"name"`
	FullName      string `json:"full_name"`
	DefaultBranch string `json:"default_branch"`
	Private       bool   `json:"private"`
	Archived      bool   `json:"archived"`
	HTMLURL       string `json:"html_url"`
}

Repository is a repository as the API describes it: its id (the number an organization secret's selection names it by, which a rename does not change), its name, its default branch, and whether it is private and whether it is archived.

type RepositoryNameCondition

type RepositoryNameCondition struct {
	Include []string `json:"include"`
	Exclude []string `json:"exclude"`
}

RepositoryNameCondition includes and excludes the organization's repositories by name pattern (acme-*, or ~ALL for every one). GitHub takes both lists as arrays, an empty one for none.

type RepositoryRequest

type RepositoryRequest struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Private     bool   `json:"private"`
	AutoInit    bool   `json:"auto_init"`
}

RepositoryRequest is a repository to create in an organization: private, and with an initial commit (a README) when AutoInit is set, so that the git data API has a commit to build on (an empty repository answers it 409). Its branch is named after the organization's setting; RenameBranch gives it the name wanted.

type RepositorySettings

type RepositorySettings struct {
	AllowMergeCommit         *bool   `json:"allow_merge_commit,omitempty"`
	AllowRebaseMerge         *bool   `json:"allow_rebase_merge,omitempty"`
	AllowSquashMerge         *bool   `json:"allow_squash_merge,omitempty"`
	SquashMergeCommitTitle   *string `json:"squash_merge_commit_title,omitempty"`
	SquashMergeCommitMessage *string `json:"squash_merge_commit_message,omitempty"`
	DeleteBranchOnMerge      *bool   `json:"delete_branch_on_merge,omitempty"`
	AllowUpdateBranch        *bool   `json:"allow_update_branch,omitempty"`
}

RepositorySettings are the merge settings the infrastructure repositories carry: squash the only merge, the squashed commit titled from the pull request and bodied from its description, the head branch deleted on merge, and the update of a branch offered on the pull request, which a ruleset's strict checks need. Each is a pointer, so that a read says which are set and an update sends what it means to change.

type Rule

type Rule struct {
	Type       string         `json:"type"`
	Parameters map[string]any `json:"parameters,omitempty"`
}

Rule is one rule of a ruleset: its type (deletion, non_fast_forward, pull_request, required_status_checks) and the parameters the type takes, none for the first two.

type Ruleset

type Ruleset struct {
	ID          int64  `json:"id,omitempty"`
	Name        string `json:"name"`
	Target      string `json:"target"`
	Enforcement string `json:"enforcement"`
	// BypassActors are who the rules do not hold for: an app (Integration) by its App
	// ID, a team or a role, each with when the bypass applies (always, pull_request).
	BypassActors []BypassActor `json:"bypass_actors"`
	// Conditions name the branches or tags the ruleset rules and, for an organization's
	// ruleset, the repositories.
	Conditions *RulesetConditions `json:"conditions,omitempty"`
	Rules      []Rule             `json:"rules"`
}

Ruleset is one ruleset of a repository or of an organization, as the API describes it in full (a listing carries the name and the enforcement alone; Ruleset and OrgRuleset read one whole).

type RulesetConditions

type RulesetConditions struct {
	RefName        RefNameCondition         `json:"ref_name"`
	RepositoryName *RepositoryNameCondition `json:"repository_name,omitempty"`
}

RulesetConditions are the ruleset's conditions: the branches or tags, by name pattern (~DEFAULT_BRANCH, refs/heads/release/*, refs/tags/v*), and for an organization's ruleset the repositories, by name pattern. A repository's own ruleset names no repository: RepositoryName is nil for it and is left out of what is sent.

type RunnerGroup

type RunnerGroup struct {
	ID                       int64  `json:"id,omitempty"`
	Name                     string `json:"name"`
	Visibility               string `json:"visibility"`
	AllowsPublicRepositories bool   `json:"allows_public_repositories"`
	Default                  bool   `json:"default,omitempty"`
}

RunnerGroup is a runner group of the organization. AllowsPublicRepositories says whether a public repository's jobs may run on the group's runners: GitHub leaves it false on a group it makes, and a job of a public repository sent to such a group waits for a runner that never takes it.

type RunnerImage

type RunnerImage struct {
	ID     string `json:"id"`
	Source string `json:"source"`
}

RunnerImage is a hosted runner's image, by GitHub's id of it and its source.

type Tag

type Tag struct {
	Name   string `json:"name"`
	Commit Object `json:"commit"`
}

Tag is one of the repository's tags with the commit it names (resolved through the tag object when the tag is annotated).

type TokenFunc

type TokenFunc func(ctx context.Context) (string, error)

TokenFunc finds the token a command runs GitHub's API with.

type TreeEntry

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

TreeEntry is one file of a tree being built.

type User

type User struct {
	Login string `json:"login"`
}

User is an account, by its login.

type Variable

type Variable struct {
	Name       string `json:"name"`
	Value      string `json:"value"`
	Visibility string `json:"visibility"`
}

Variable is an organization's Actions variable.

type WaitFunc

type WaitFunc func(ctx context.Context, d time.Duration) error

WaitFunc waits for d, or returns the context's error; a test substitutes one that does not wait.

type Workflow

type Workflow struct {
	ID    int64  `json:"id"`
	Name  string `json:"name"`
	Path  string `json:"path"`
	State string `json:"state"`
}

Workflow is one of the repository's Actions workflows. GitHub lists a workflow once a run of it exists or once a push to the default branch adds or changes its file; the push that creates the repository does not always list the files it carries (first pushes of five commits and more have listed none), so a workflow nothing runs can stay unlisted until a later push changes it.

Directories

Path Synopsis
Package githubtest is a GitHub API stand-in for tests: in-memory organizations with their installed apps, Actions secrets and rulesets, and one or more repositories with rulesets, refs, tags, check runs, environments and issues, served over httptest so the real client speaks to it unchanged.
Package githubtest is a GitHub API stand-in for tests: in-memory organizations with their installed apps, Actions secrets and rulesets, and one or more repositories with rulesets, refs, tags, check runs, environments and issues, served over httptest so the real client speaks to it unchanged.

Jump to

Keyboard shortcuts

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