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
- func BotAccount(ctx context.Context, open func(token string) *Client, ...) (string, error)
- func IssuedByApp(token string) string
- func ManifestFormURL(organization, state string) string
- func Moved(err error) bool
- func NotFound(err error) bool
- func Token(ctx context.Context) (string, error)
- type Account
- type App
- type Branch
- type BranchPolicy
- type BypassActor
- type CheckApp
- type CheckRun
- type Client
- func (c *Client) AddEnvironmentBranch(ctx context.Context, owner, repo, name, pattern string) error
- func (c *Client) App(ctx context.Context) (*App, error)
- func (c *Client) AppBySlug(ctx context.Context, slug string) (*App, error)
- func (c *Client) AppInstallations(ctx context.Context) ([]Installation, error)
- func (c *Client) Archive(ctx context.Context, owner, repo string) error
- func (c *Client) Base() string
- func (c *Client) CheckRuns(ctx context.Context, owner, repo, ref string) ([]CheckRun, error)
- func (c *Client) CloseIssue(ctx context.Context, owner, repo string, number int) error
- func (c *Client) Compare(ctx context.Context, owner, repo, base, head string) (*Comparison, error)
- func (c *Client) Contents(ctx context.Context, owner, repo, path, ref string) ([]byte, error)
- func (c *Client) ConvertManifest(ctx context.Context, code string) (*App, error)
- func (c *Client) CreateBlob(ctx context.Context, owner, repo string, content []byte) (string, error)
- func (c *Client) CreateComment(ctx context.Context, owner, repo string, number int, body string) error
- func (c *Client) CreateCommit(ctx context.Context, owner, repo, message, tree string, parents []string) (string, error)
- func (c *Client) CreateDeployment(ctx context.Context, owner, repo string, d *DeploymentRequest) (int64, error)
- func (c *Client) CreateDeploymentStatus(ctx context.Context, owner, repo string, id int64, s *DeploymentStatus) error
- func (c *Client) CreateHostedRunner(ctx context.Context, org string, in HostedRunnerRequest) (*HostedRunner, error)
- func (c *Client) CreateIssue(ctx context.Context, owner, repo, title, body string) (*Issue, error)
- func (c *Client) CreateOrgRuleset(ctx context.Context, org string, in *Ruleset) (*Ruleset, error)
- func (c *Client) CreateOrgVariable(ctx context.Context, org string, v Variable) error
- func (c *Client) CreatePullRequest(ctx context.Context, owner, repo string, in PullRequestRequest) (*PullRequest, error)
- func (c *Client) CreateRef(ctx context.Context, owner, repo, ref, sha string) error
- func (c *Client) CreateRepository(ctx context.Context, org string, in RepositoryRequest) (*Repository, error)
- func (c *Client) CreateRuleset(ctx context.Context, owner, repo string, in *Ruleset) (*Ruleset, error)
- func (c *Client) CreateRunnerGroup(ctx context.Context, org string, in RunnerGroup) (*RunnerGroup, error)
- func (c *Client) CreateTree(ctx context.Context, owner, repo, baseTree string, entries []TreeEntry) (string, error)
- func (c *Client) DeleteEnvironmentSecret(ctx context.Context, owner, repo, environment, name string) error
- func (c *Client) DeleteHostedRunner(ctx context.Context, org string, id int64) error
- func (c *Client) DeleteOrgRuleset(ctx context.Context, org string, id int64) error
- func (c *Client) DeleteOrgSecret(ctx context.Context, org, name string) error
- func (c *Client) DeleteOrgVariable(ctx context.Context, org, name string) error
- func (c *Client) Deployments(ctx context.Context, owner, repo, environment string) ([]int64, error)
- func (c *Client) Directory(ctx context.Context, owner, repo, path, ref string) ([]DirEntry, error)
- func (c *Client) DispatchWorkflow(ctx context.Context, owner, repo, file, ref string, inputs map[string]string) error
- func (c *Client) Empty(ctx context.Context, owner, repo string) (bool, error)
- func (c *Client) EnforceImmutableReleases(ctx context.Context, org string) error
- func (c *Client) Environment(ctx context.Context, owner, repo, name string) (*Environment, error)
- func (c *Client) EnvironmentBranches(ctx context.Context, owner, repo, name string) ([]string, error)
- func (c *Client) EnvironmentPatterns(ctx context.Context, owner, repo, name string) (branches, tags []string, err error)
- func (c *Client) EnvironmentSecret(ctx context.Context, owner, repo, environment, name string) (*EnvironmentSecret, error)
- func (c *Client) GetCommit(ctx context.Context, owner, repo, sha string) (*Commit, error)
- func (c *Client) HostedRunners(ctx context.Context, org string) ([]HostedRunner, error)
- func (c *Client) InstallationToken(ctx context.Context, installation int64) (string, error)
- func (c *Client) IssueComments(ctx context.Context, owner, repo string, number int) ([]Comment, error)
- func (c *Client) LatestPullRequest(ctx context.Context, owner, repo, base string) (*PullRequest, error)
- func (c *Client) OpenIssue(ctx context.Context, owner, repo, title string) (*Issue, error)
- func (c *Client) OpenRunnerGroup(ctx context.Context, org string, id int64, public bool) error
- func (c *Client) OrgImmutableReleases(ctx context.Context, org string) (string, error)
- func (c *Client) OrgInstallations(ctx context.Context, org string) ([]OrgInstallation, error)
- func (c *Client) OrgMembership(ctx context.Context, org string) (string, error)
- func (c *Client) OrgRuleset(ctx context.Context, org string, id int64) (*Ruleset, error)
- func (c *Client) OrgRulesets(ctx context.Context, org string) ([]Ruleset, error)
- func (c *Client) OrgSecret(ctx context.Context, org, name string) (*OrgSecret, error)
- func (c *Client) OrgSecretRepositories(ctx context.Context, org, name string) ([]Repository, error)
- func (c *Client) OrgVariable(ctx context.Context, org, name string) (*Variable, error)
- func (c *Client) PullRequestState(ctx context.Context, owner, repo string, number int) (string, error)
- func (c *Client) PullRequestsFrom(ctx context.Context, owner, repo, branch string) ([]PullRequest, error)
- func (c *Client) PutEnvironment(ctx context.Context, owner, repo, name string) error
- func (c *Client) PutEnvironmentSecret(ctx context.Context, owner, repo, environment, name string, value []byte) error
- func (c *Client) PutOrgSecret(ctx context.Context, org, name string, value []byte, repositoryIDs []int64) error
- func (c *Client) Ref(ctx context.Context, owner, repo, ref string) (*Ref, error)
- func (c *Client) Release(ctx context.Context, owner, repo, tag string) (*Release, error)
- func (c *Client) RenameBranch(ctx context.Context, owner, repo, branch, newName string) error
- func (c *Client) Repository(ctx context.Context, owner, repo string) (*Repository, error)
- func (c *Client) RepositoryInstallation(ctx context.Context, owner, repo string) (int64, error)
- func (c *Client) RepositorySettings(ctx context.Context, owner, repo string) (*RepositorySettings, error)
- func (c *Client) Ruleset(ctx context.Context, owner, repo string, id int64) (*Ruleset, error)
- func (c *Client) Rulesets(ctx context.Context, owner, repo string) ([]Ruleset, error)
- func (c *Client) RunnerGroups(ctx context.Context, org string) ([]RunnerGroup, error)
- func (c *Client) SetOrgSecretRepositories(ctx context.Context, org, name string, repositoryIDs []int64) error
- func (c *Client) SetRepositoryPrivate(ctx context.Context, owner, repo string, private bool) error
- func (c *Client) TagCommit(ctx context.Context, owner, repo, tag string) (string, error)
- func (c *Client) Tags(ctx context.Context, owner, repo string) ([]Tag, error)
- func (c *Client) UpdateComment(ctx context.Context, owner, repo string, id int64, body string) error
- func (c *Client) UpdateHostedRunner(ctx context.Context, org string, id, group int64, maximum int) error
- func (c *Client) UpdateOrgRuleset(ctx context.Context, org string, id int64, in *Ruleset) error
- func (c *Client) UpdateOrgVariable(ctx context.Context, org string, v Variable) error
- func (c *Client) UpdateRef(ctx context.Context, owner, repo, ref, sha string, force bool) error
- func (c *Client) UpdateRepositorySettings(ctx context.Context, owner, repo string, in *RepositorySettings) error
- func (c *Client) UpdateRuleset(ctx context.Context, owner, repo string, id int64, in *Ruleset) error
- func (c *Client) User(ctx context.Context) (string, error)
- func (c *Client) Workflows(ctx context.Context, owner, repo string) ([]Workflow, error)
- type ClientFunc
- type Comment
- type Commit
- type ComparedFile
- type Comparison
- type DeploymentRequest
- type DeploymentStatus
- type DirEntry
- type Environment
- type EnvironmentSecret
- type Error
- type HookAttributes
- type HostedRunner
- type HostedRunnerRequest
- type Installation
- type Issue
- type MachineSize
- type Manifest
- type Object
- type OrgInstallation
- type OrgSecret
- type PullRequest
- type PullRequestRef
- type PullRequestRequest
- type Ref
- type RefNameCondition
- type Release
- type Repository
- type RepositoryNameCondition
- type RepositoryRequest
- type RepositorySettings
- type Rule
- type Ruleset
- type RulesetConditions
- type RunnerGroup
- type RunnerImage
- type Tag
- type TokenFunc
- type TreeEntry
- type User
- type Variable
- type WaitFunc
- type Workflow
Constants ¶
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" )
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.
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.
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.
const AllRepositories = "all"
AllRepositories is an installation's repository selection when it covers every repository of the account, the ones made after it included.
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 ¶
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 ¶
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 ¶
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).
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 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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) CheckRuns ¶
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 ¶
CloseIssue closes the issue with the number; one already closed stays closed.
func (*Client) ConvertManifest ¶
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 ¶
CreateIssue opens an issue with the title and the body as the token's account, and answers it with its number.
func (*Client) CreateOrgRuleset ¶
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 ¶
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) 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
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 ¶
DeleteOrgRuleset removes the organization's ruleset with the id; its rules stop holding on every repository it named.
func (*Client) DeleteOrgSecret ¶
DeleteOrgSecret removes the organization's secret.
func (*Client) DeleteOrgVariable ¶
DeleteOrgVariable removes the variable.
func (*Client) Deployments ¶
Deployments lists the ids of the environment's deployments, newest first, up to a hundred.
func (*Client) Directory ¶
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 ¶
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
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 ¶
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) HostedRunners ¶
HostedRunners lists the organization's GitHub-hosted runners.
func (*Client) InstallationToken ¶
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 ¶
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 ¶
OpenRunnerGroup opens the group to the organization's public repositories, or closes it to them.
func (*Client) OrgImmutableReleases ¶ added in v0.1.2
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
OrgSecret reads the organization's secret, without its value; an absent one is NotFound.
func (*Client) OrgSecretRepositories ¶
OrgSecretRepositories lists the repositories selected for the organization's secret, every page of them.
func (*Client) OrgVariable ¶
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 ¶
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 ¶
Ref reads the reference named without its refs/ prefix (heads/master, tags/v1.0.0). An absent reference is NotFound.
func (*Client) RenameBranch ¶
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 ¶
Repository reads the repository; an absent one is NotFound.
func (*Client) RepositoryInstallation ¶
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) Rulesets ¶
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 ¶
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 ¶
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 ¶
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) 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 ¶
UpdateOrgRuleset replaces the organization's ruleset with the id by what in says.
func (*Client) UpdateOrgVariable ¶
UpdateOrgVariable sets the variable's value and visibility.
func (*Client) UpdateRef ¶
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.
type ClientFunc ¶
ClientFunc opens the client: the CLI wires Open, tests a client over a test server.
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 ¶
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 HookAttributes ¶
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 ¶
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 ¶
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 ¶
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 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 ¶
RunnerImage is a hosted runner's image, by GitHub's id of it and its source.
type Tag ¶
Tag is one of the repository's tags with the commit it names (resolved through the tag object when the tag is annotated).
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 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 ¶
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.
Source Files
¶
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. |