Documentation
¶
Overview ¶
Package github is the service's view of GitHub: what it reads, as the organization's GitHub App installation, with every answer classed as confirmed or not. Only GitHub's confirmed answers may decide anything (specs/0002-machines.md, Scope).
Index ¶
- Constants
- Variables
- func IsUnavailable(err error) bool
- type API
- type Actions
- type Approval
- type Client
- func (c *Client) AttemptJobs(ctx context.Context, repo Repository, runID int64, attempt int) ([]Job, error)
- func (c *Client) AttemptTrigger(ctx context.Context, repo Repository, runID int64, attempt int) (string, error)
- func (c *Client) Blob(ctx context.Context, repo Repository, sha string) ([]byte, error)
- func (c *Client) Bot(ctx context.Context) (string, error)
- func (c *Client) BranchHead(ctx context.Context, repo Repository, branch string) (string, error)
- func (c *Client) CancelRun(ctx context.Context, repo Repository, runID int64) error
- func (c *Client) Compare(ctx context.Context, repo Repository, base, head string) (string, error)
- func (c *Client) CreateRunnerGroup(ctx context.Context, name string, repositoryID int64) (RunnerGroup, error)
- func (c *Client) DeleteRunner(ctx context.Context, id int64) error
- func (c *Client) File(ctx context.Context, repo Repository, path, commit string) ([]byte, error)
- func (c *Client) ForceCancelRun(ctx context.Context, repo Repository, runID int64) error
- func (c *Client) ForkApprovalPolicy(ctx context.Context) (string, error)
- func (c *Client) GroupRunners(ctx context.Context, groupID int64) ([]Runner, error)
- func (c *Client) JITConfig(ctx context.Context, groupID int64, name string, labels []string) (Runner, string, error)
- func (c *Client) Job(ctx context.Context, repo Repository, id int64) (Job, error)
- func (c *Client) OpenPullRequests(ctx context.Context, repo Repository) ([]PullRequest, error)
- func (c *Client) PullRequest(ctx context.Context, repo Repository, number int) (PullRequest, error)
- func (c *Client) PullRequestCommits(ctx context.Context, repo Repository, number int) ([]string, error)
- func (c *Client) Repositories(ctx context.Context) ([]Repository, error)
- func (c *Client) RepositoryByID(ctx context.Context, id int64) (Repository, error)
- func (c *Client) RerunFailedJobs(ctx context.Context, repo Repository, runID int64) error
- func (c *Client) RunApprovals(ctx context.Context, repo Repository, runID int64) ([]Approval, error)
- func (c *Client) RunJobs(ctx context.Context, repo Repository, runID int64) ([]Job, error)
- func (c *Client) RunnerGroupRepositories(ctx context.Context, groupID int64) ([]int64, error)
- func (c *Client) RunnerGroups(ctx context.Context) ([]RunnerGroup, error)
- func (c *Client) Runs(ctx context.Context, repo Repository, status string) ([]WorkflowRun, error)
- func (c *Client) RunsCreated(ctx context.Context, repo Repository, status string, from, to time.Time) ([]WorkflowRun, error)
- func (c *Client) SetRunnerGroupRepositories(ctx context.Context, groupID int64, ids []int64) error
- func (c *Client) WorkflowRun(ctx context.Context, repo Repository, id int64) (WorkflowRun, error)
- type Job
- type Options
- type PullRequest
- type Repository
- type Runner
- type RunnerGroup
- type Unavailable
- type WorkflowRun
Constants ¶
const MaxFile = 10 << 20
MaxFile bounds what File and Blob read: .github/runners.json and the files a family's key lists.
Variables ¶
var ErrConflict = errors.New("conflict on GitHub")
ErrConflict is GitHub's confirmed answer that a change conflicts with what's there: a runner group or runner of that name exists, or a run to cancel has already finished.
var ErrDirectory = errors.New("a directory")
ErrDirectory is GitHub's answer that a path File asked for is a directory. It's ErrNotFound too, since there's no such file, but a caller that deletes on a file's absence tells the two apart.
var ErrIncomplete = errors.New("more than GitHub lists")
ErrIncomplete is an answer GitHub couldn't give in full: a list of more runs than it lists for one filter, in a span that can't be split.
var ErrNotFound = errors.New("not found on GitHub")
ErrNotFound is GitHub's confirmed answer that something doesn't exist. Any error that isn't Unavailable is a confirmed answer of some kind.
var ErrRefused = errors.New("refused by GitHub")
ErrRefused is GitHub's confirmed refusal of a change, such as removing a runner that's running a job.
Functions ¶
func IsUnavailable ¶
IsUnavailable reports whether err is an Unavailable.
Types ¶
type API ¶
type API interface {
RepositoryByID(ctx context.Context, id int64) (Repository, error)
WorkflowRun(ctx context.Context, repo Repository, id int64) (WorkflowRun, error)
PullRequest(ctx context.Context, repo Repository, number int) (PullRequest, error)
OpenPullRequests(ctx context.Context, repo Repository) ([]PullRequest, error)
// PullRequestCommits lists a pull request's commits; GitHub lists at
// most 250.
PullRequestCommits(ctx context.Context, repo Repository, number int) ([]string, error)
// BranchHead is a branch's commit, by its full ref, so a tag of the
// same name can't stand in for it.
BranchHead(ctx context.Context, repo Repository, branch string) (string, error)
// Compare is GitHub's comparison of two commits: identical, ahead,
// behind or diverged.
Compare(ctx context.Context, repo Repository, base, head string) (string, error)
// File reads a file at a commit, of at most MaxFile bytes.
File(ctx context.Context, repo Repository, path, commit string) ([]byte, error)
// Blob reads a blob by its SHA, of at most MaxFile bytes.
Blob(ctx context.Context, repo Repository, sha string) ([]byte, error)
Actions
}
API is what the service reads from GitHub.
type Actions ¶
type Actions interface {
// Repositories lists the repositories the installation can reach.
Repositories(ctx context.Context) ([]Repository, error)
// Runs lists a repository's runs with a status, such as queued.
Runs(ctx context.Context, repo Repository, status string) ([]WorkflowRun, error)
// RunsCreated lists a repository's runs with a status that were created
// from from to to, both included, to the second. GitHub answers a
// filtered list with at most 1,000 runs, so a span that holds more is
// split; one that can't be is ErrIncomplete.
RunsCreated(ctx context.Context, repo Repository, status string, from, to time.Time) ([]WorkflowRun, error)
// RunJobs lists the jobs of a run's latest attempt.
RunJobs(ctx context.Context, repo Repository, runID int64) ([]Job, error)
// AttemptJobs lists the jobs of one of a run's attempts.
AttemptJobs(ctx context.Context, repo Repository, runID int64, attempt int) ([]Job, error)
Job(ctx context.Context, repo Repository, id int64) (Job, error)
// RunApprovals is a run's review history: who approved or rejected its
// deployments to which environments.
RunApprovals(ctx context.Context, repo Repository, runID int64) ([]Approval, error)
// CancelRun and ForceCancelRun return ErrConflict if the run has
// already finished.
CancelRun(ctx context.Context, repo Repository, runID int64) error
ForceCancelRun(ctx context.Context, repo Repository, runID int64) error
// RerunFailedJobs starts a finished run's next attempt, rerunning its
// failed jobs and those that depend on them.
RerunFailedJobs(ctx context.Context, repo Repository, runID int64) error
// AttemptTrigger is the login of whoever triggered one of a run's
// attempts, such as a maintainer who reran it, or the App's bot.
AttemptTrigger(ctx context.Context, repo Repository, runID int64, attempt int) (string, error)
// Bot is the login of the App's own bot user.
Bot(ctx context.Context) (string, error)
// ForkApprovalPolicy is the organization's setting for which outside
// contributors' fork pull request workflows need a maintainer's
// approval.
ForkApprovalPolicy(ctx context.Context) (string, error)
RunnerGroups(ctx context.Context) ([]RunnerGroup, error)
// CreateRunnerGroup makes a group that only repositoryID may use;
// ErrConflict means one of that name exists.
CreateRunnerGroup(ctx context.Context, name string, repositoryID int64) (RunnerGroup, error)
RunnerGroupRepositories(ctx context.Context, groupID int64) ([]int64, error)
SetRunnerGroupRepositories(ctx context.Context, groupID int64, ids []int64) error
GroupRunners(ctx context.Context, groupID int64) ([]Runner, error)
// DeleteRunner removes a runner registration; ErrNotFound means it's
// gone already, and ErrRefused that it's running a job.
DeleteRunner(ctx context.Context, id int64) error
// JITConfig registers a just-in-time runner in a group and returns it
// with its encoded configuration, which is a credential. ErrConflict
// means a runner of that name exists.
JITConfig(ctx context.Context, groupID int64, name string, labels []string) (Runner, string, error)
}
Actions is what the service reads and does in GitHub Actions, as the App's installation on the organization.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is API over GitHub's REST API.
func NewAppClient ¶
NewAppClient returns a client that acts as the App's installation on the organization, found by the organization's ID when first needed.
func (*Client) AttemptJobs ¶
func (c *Client) AttemptJobs(ctx context.Context, repo Repository, runID int64, attempt int) ([]Job, error)
AttemptJobs implements Actions.
func (*Client) AttemptTrigger ¶
func (c *Client) AttemptTrigger(ctx context.Context, repo Repository, runID int64, attempt int) (string, error)
AttemptTrigger implements Actions.
func (*Client) Bot ¶
Bot is the login of the App's bot user, which acts for its installation, such as when it reruns a run: <slug>[bot].
func (*Client) BranchHead ¶
BranchHead implements API.
func (*Client) CancelRun ¶
CancelRun implements Actions. GitHub answers 202 Accepted, which go-github reports as an AcceptedError: the cancellation has started.
func (*Client) CreateRunnerGroup ¶
func (c *Client) CreateRunnerGroup(ctx context.Context, name string, repositoryID int64) (RunnerGroup, error)
CreateRunnerGroup implements Actions. The group allows public repositories, since a consumer may be one, and only repositoryID may use it.
func (*Client) DeleteRunner ¶
DeleteRunner implements Actions.
func (*Client) ForceCancelRun ¶
ForceCancelRun implements Actions; go-github has no call for it.
func (*Client) ForkApprovalPolicy ¶
ForkApprovalPolicy implements Actions.
func (*Client) GroupRunners ¶
GroupRunners implements Actions.
func (*Client) JITConfig ¶
func (c *Client) JITConfig(ctx context.Context, groupID int64, name string, labels []string) (Runner, string, error)
JITConfig implements Actions.
func (*Client) OpenPullRequests ¶
func (c *Client) OpenPullRequests(ctx context.Context, repo Repository) ([]PullRequest, error)
OpenPullRequests implements API.
func (*Client) PullRequest ¶
func (c *Client) PullRequest(ctx context.Context, repo Repository, number int) (PullRequest, error)
PullRequest implements API.
func (*Client) PullRequestCommits ¶
func (c *Client) PullRequestCommits(ctx context.Context, repo Repository, number int) ([]string, error)
PullRequestCommits implements API.
func (*Client) Repositories ¶
func (c *Client) Repositories(ctx context.Context) ([]Repository, error)
Repositories implements Actions.
func (*Client) RepositoryByID ¶
RepositoryByID implements API.
func (*Client) RerunFailedJobs ¶
RerunFailedJobs implements Actions. GitHub answers 201 Created, and a plain 403 when it won't rerun the run, such as one still running, which is a confirmed refusal, ErrRefused; its rate limits are Unavailable.
func (*Client) RunApprovals ¶
func (c *Client) RunApprovals(ctx context.Context, repo Repository, runID int64) ([]Approval, error)
RunApprovals implements Actions. go-github has no call for the review history, so it's asked for directly.
func (*Client) RunnerGroupRepositories ¶
RunnerGroupRepositories implements Actions.
func (*Client) RunnerGroups ¶
func (c *Client) RunnerGroups(ctx context.Context) ([]RunnerGroup, error)
RunnerGroups implements Actions.
func (*Client) Runs ¶
func (c *Client) Runs(ctx context.Context, repo Repository, status string) ([]WorkflowRun, error)
Runs implements Actions.
func (*Client) RunsCreated ¶
func (c *Client) RunsCreated(ctx context.Context, repo Repository, status string, from, to time.Time) ([]WorkflowRun, error)
RunsCreated implements Actions.
func (*Client) SetRunnerGroupRepositories ¶
SetRunnerGroupRepositories implements Actions.
func (*Client) WorkflowRun ¶
func (c *Client) WorkflowRun(ctx context.Context, repo Repository, id int64) (WorkflowRun, error)
WorkflowRun implements API.
type Job ¶
type Job struct {
ID int64
RunID int64
RunAttempt int
Name string
Status string
Conclusion string
Labels []string
RunnerID int64
RunnerName string
RunnerGroupID int64
CreatedAt time.Time
StartedAt time.Time
CompletedAt time.Time
}
Job is a workflow job, as GitHub records it. RunnerID and RunnerName are the runner GitHub handed it to, once it shows the assignment.
type Options ¶
type Options struct {
// BaseURL is GitHub's API, https://api.github.com in production.
BaseURL string
AppID int64
// PrivateKey is the App's PEM private key.
PrivateKey []byte
// OrganizationID is the account the App is installed on.
OrganizationID int64
// Transport is the underlying transport; nil means the default.
Transport http.RoundTripper
}
Options say how to reach GitHub as the App.
type PullRequest ¶
type PullRequest struct {
Number int
State string
ClosedAt time.Time
BaseRepositoryID int64
HeadRepositoryID int64
HeadSHA string
// BaseRef is the branch the pull request targets.
BaseRef string
BaseSHA string
Commits int
}
PullRequest is a pull request. HeadRepositoryID is 0 once the head repository is deleted. ClosedAt is when it was last closed, zero while it's open.
type Repository ¶
Repository is a repository, as GitHub reports it.
type RunnerGroup ¶
type RunnerGroup struct {
ID int64
Name string
Visibility string
Default bool
AllowsPublicRepositories bool
RestrictedToWorkflows bool
}
RunnerGroup is one of the organization's runner groups.
type Unavailable ¶
Unavailable wraps every other failure: GitHub couldn't be reached, timed out, limited the service's requests, or answered in a way that confirms nothing. A caller must not decide anything from it.
func (*Unavailable) Error ¶
func (u *Unavailable) Error() string
func (*Unavailable) Unwrap ¶
func (u *Unavailable) Unwrap() error
type WorkflowRun ¶
type WorkflowRun struct {
ID int64
RepositoryID int64
Event string
Status string
Conclusion string
Attempt int
HeadBranch string
HeadSHA string
HeadRepositoryID int64
// PullRequests are the numbers of the pull requests GitHub's record of
// the run lists: for a same-repository pull request's run, those whose
// head is the run's. GitHub lists none for a fork's.
PullRequests []int
CreatedAt time.Time
// UpdatedAt is when GitHub last changed it, such as when it finished.
UpdatedAt time.Time
}
WorkflowRun is a workflow run, as GitHub records it. For a pull_request_target run, its head is the base branch's.