Documentation
¶
Overview ¶
Package github provides a client for the GitHub REST API, with a focus on the Actions endpoints (runs, jobs, runners).
Index ¶
- Constants
- func NewJobsScanner(owner, repo string, runID int64, filter string, perPage int, ...) *operations.Scanner[JobsResponse]
- func NewRunnersScanner(owner, repo string, perPage int, opts ...operations.Option) *operations.Scanner[RunnersResponse]
- func NewRunsScanner(owner, repo string, perPage int, filter RunsFilter, opts ...operations.Option) *operations.Scanner[WorkflowRunsResponse]
- func VerifyWebhookSignature(secret string, body []byte, signature string) bool
- type Actor
- type BearerToken
- type CreateWebhookRequest
- type HeadCommit
- type Job
- type JobsResponse
- type Meta
- type MetaDomains
- type MockWebhook
- type RegistrationToken
- type Repository
- type Runner
- type RunnerLabel
- type RunnersResponse
- type RunsFilter
- type SSHKeyFingerprints
- type Step
- type Webhook
- type WebhookConfig
- type WorkflowJobEvent
- type WorkflowRun
- type WorkflowRunEvent
- type WorkflowRunsResponse
Constants ¶
const APIHost = "https://api.github.com"
Variables ¶
This section is empty.
Functions ¶
func NewJobsScanner ¶
func NewJobsScanner(owner, repo string, runID int64, filter string, perPage int, opts ...operations.Option) *operations.Scanner[JobsResponse]
NewJobsScanner returns an operations.Scanner that iterates over jobs for the specified workflow run. filter may be "latest" (the default) or "all" to include jobs from all prior run attempts.
func NewRunnersScanner ¶
func NewRunnersScanner(owner, repo string, perPage int, opts ...operations.Option) *operations.Scanner[RunnersResponse]
NewRunnersScanner returns an operations.Scanner that iterates over self-hosted runners registered for the specified owner and repo.
func NewRunsScanner ¶
func NewRunsScanner(owner, repo string, perPage int, filter RunsFilter, opts ...operations.Option) *operations.Scanner[WorkflowRunsResponse]
NewRunsScanner returns an operations.Scanner that iterates over workflow runs for the specified owner and repo, one page at a time. Non-empty fields in filter are sent as query parameters so the GitHub API performs server-side filtering before any results are returned.
Types ¶
type BearerToken ¶
BearerToken implements operations.Auth for GitHub personal access tokens and GitHub Apps installation tokens. The token is retrieved from the context via the apitokens package using the configured KeyID.
func (BearerToken) WithAuthorization ¶
WithAuthorization implements operations.Auth. It sets the Authorization header and the required GitHub API headers on the request.
type CreateWebhookRequest ¶
type CreateWebhookRequest struct {
Name string `json:"name"`
Active bool `json:"active"`
Events []string `json:"events"`
Config WebhookConfig `json:"config"`
}
CreateWebhookRequest is the request body for creating a repository webhook.
type HeadCommit ¶
type HeadCommit struct {
ID string `json:"id"`
Message string `json:"message"`
Timestamp string `json:"timestamp"`
Author struct {
Name string `json:"name"`
Email string `json:"email"`
} `json:"author"`
}
HeadCommit contains information about the commit that triggered a run.
type Job ¶
type Job struct {
ID int64 `json:"id"`
RunID int64 `json:"run_id"`
Name string `json:"name"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
StartedAt *time.Time `json:"started_at"`
CompletedAt *time.Time `json:"completed_at"`
HTMLURL string `json:"html_url"`
Steps []Step `json:"steps"`
RunnerName string `json:"runner_name"`
RunnerGroupName string `json:"runner_group_name"`
WorkflowName string `json:"workflow_name"`
HeadBranch string `json:"head_branch"`
HeadSHA string `json:"head_sha"`
}
Job represents a single GitHub Actions job within a workflow run.
type JobsResponse ¶
JobsResponse is the response from the list jobs for a workflow run endpoint.
type Meta ¶
type Meta struct {
VerifiablePasswordAuthentication bool `json:"verifiable_password_authentication"`
SSHKeyFingerprints SSHKeyFingerprints `json:"ssh_key_fingerprints"`
SSHKeys []string `json:"ssh_keys"`
Hooks []string `json:"hooks"`
Web []string `json:"web"`
API []string `json:"api"`
Git []string `json:"git"`
Packages []string `json:"packages"`
Pages []string `json:"pages"`
Importer []string `json:"importer"`
Actions []string `json:"actions"`
Dependabot []string `json:"dependabot"`
Domains MetaDomains `json:"domains"`
}
Meta is the response from the GET /meta endpoint. IP ranges are in CIDR notation.
type MetaDomains ¶
type MetaDomains struct {
Website []string `json:"website"`
Codespaces []string `json:"codespaces"`
Copilot []string `json:"copilot"`
Packages []string `json:"packages"`
}
MetaDomains holds the domain names used by various GitHub services.
type MockWebhook ¶
type MockWebhook struct {
// contains filtered or unexported fields
}
MockWebhook creates signed HTTP POST requests that mimic GitHub webhook deliveries. It is intended for testing webhook relays and handlers.
func NewMockWebhook ¶
func NewMockWebhook(owner, repo, secret string) *MockWebhook
NewMockWebhook returns a MockWebhook for the given owner/repo. secret is the webhook secret used to produce X-Hub-Signature-256 headers; pass an empty string to skip signing.
func (*MockWebhook) JobRequest ¶
func (m *MockWebhook) JobRequest(ctx context.Context, targetURL, action string, job Job) (*http.Request, error)
JobRequest returns a signed HTTP POST request to targetURL for a workflow_job event. action must be one of "queued", "in_progress", or "completed".
func (*MockWebhook) RunRequest ¶
func (m *MockWebhook) RunRequest(ctx context.Context, targetURL, action string, run WorkflowRun) (*http.Request, error)
RunRequest returns a signed HTTP POST request to targetURL for a workflow_run event. action must be one of "requested", "in_progress", or "completed".
type RegistrationToken ¶
type RegistrationToken struct {
Token string `json:"token"`
ExpiresAt time.Time `json:"expires_at"`
}
RegistrationToken is the response from the runner registration-token endpoint.
func CreateRegistrationToken ¶
func CreateRegistrationToken(ctx context.Context, owner, repo string, opts ...operations.Option) (RegistrationToken, error)
CreateRegistrationToken requests a new runner registration token for the given owner/repo. Options (including WithAuth) follow the same pattern as NewRunsScanner, NewRunnersScanner, and the other functions in this package.
type Repository ¶
type Repository struct {
ID int64 `json:"id"`
Name string `json:"name"`
FullName string `json:"full_name"`
HTMLURL string `json:"html_url"`
Private bool `json:"private"`
Owner Actor `json:"owner"`
}
Repository represents the repository information included in webhook payloads.
type Runner ¶
type Runner struct {
ID int64 `json:"id"`
Name string `json:"name"`
OS string `json:"os"`
Status string `json:"status"`
Busy bool `json:"busy"`
Labels []RunnerLabel `json:"labels"`
}
Runner represents a GitHub Actions self-hosted runner.
type RunnerLabel ¶
type RunnerLabel struct {
ID int64 `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
}
RunnerLabel represents a label assigned to a self-hosted runner.
type RunnersResponse ¶
type RunnersResponse struct {
TotalCount int `json:"total_count"`
Runners []Runner `json:"runners"`
}
RunnersResponse is the response from the list runners endpoint.
type RunsFilter ¶
RunsFilter holds optional server-side filter parameters for listing workflow runs.
type SSHKeyFingerprints ¶
type SSHKeyFingerprints struct {
SHA256RSA string `json:"SHA256_RSA"`
SHA256DSA string `json:"SHA256_DSA"`
SHA256ECDSA string `json:"SHA256_ECDSA"`
SHA256ED25519 string `json:"SHA256_ED25519"`
}
SSHKeyFingerprints holds the SHA256 fingerprints for each of GitHub's host keys.
type Step ¶
type Step struct {
Name string `json:"name"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
Number int `json:"number"`
StartedAt *time.Time `json:"started_at"`
CompletedAt *time.Time `json:"completed_at"`
}
Step represents a single step within a GitHub Actions job.
type Webhook ¶
type Webhook struct {
ID int64 `json:"id"`
Name string `json:"name"`
Active bool `json:"active"`
Events []string `json:"events"`
Config WebhookConfig `json:"config"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
}
Webhook is the response from the create/get repository webhook endpoints.
func CreateWebhook ¶
func CreateWebhook(ctx context.Context, owner, repo string, request CreateWebhookRequest, opts ...operations.Option) (Webhook, error)
CreateWebhook creates a new webhook for the given owner/repo. The Name field in the request must be "web" for HTTP webhooks. GitHub returns 201 Created on success.
type WebhookConfig ¶
type WebhookConfig struct {
URL string `json:"url"`
ContentType string `json:"content_type,omitempty"`
Secret string `json:"secret,omitempty"`
InsecureSSL string `json:"insecure_ssl,omitempty"`
}
WebhookConfig holds the delivery configuration for a repository webhook.
type WorkflowJobEvent ¶
type WorkflowJobEvent struct {
Action string `json:"action"`
WorkflowJob Job `json:"workflow_job"`
Repository Repository `json:"repository"`
Sender Actor `json:"sender"`
}
WorkflowJobEvent is the payload delivered to a webhook for workflow_job events. Action is one of "queued", "in_progress", or "completed".
type WorkflowRun ¶
type WorkflowRun struct {
ID int64 `json:"id"`
Name string `json:"name"`
HeadBranch string `json:"head_branch"`
HeadSHA string `json:"head_sha"`
RunNumber int `json:"run_number"`
RunAttempt int `json:"run_attempt"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
WorkflowID int64 `json:"workflow_id"`
WorkflowName string `json:"workflow_name"`
URL string `json:"url"`
HTMLURL string `json:"html_url"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
RunStartedAt *time.Time `json:"run_started_at"`
Event string `json:"event"`
Actor Actor `json:"actor"`
HeadCommit HeadCommit `json:"head_commit"`
}
WorkflowRun represents a single GitHub Actions workflow run.
func MockRun ¶
func MockRun(owner, repo string) WorkflowRun
MockRun returns a WorkflowRun populated with typical values for use in tests. Callers may overwrite any field before passing it to MockWebhook.RunRequest.
type WorkflowRunEvent ¶
type WorkflowRunEvent struct {
Action string `json:"action"`
WorkflowRun WorkflowRun `json:"workflow_run"`
Repository Repository `json:"repository"`
Sender Actor `json:"sender"`
}
WorkflowRunEvent is the payload delivered to a webhook for workflow_run events. Action is one of "requested", "in_progress", or "completed".
type WorkflowRunsResponse ¶
type WorkflowRunsResponse struct {
TotalCount int `json:"total_count"`
WorkflowRuns []WorkflowRun `json:"workflow_runs"`
}
WorkflowRunsResponse is the response from the list workflow runs endpoint.