Documentation
¶
Overview ¶
Package github provides a client for interacting with GitHub API operations.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) GetLatestRun(workflowName string) (*WorkflowRun, error)
- func (c *Client) GetWorkflowRun(runID int64) (*WorkflowRun, error)
- func (c *Client) GetWorkflowRunJobs(runID int64) ([]Job, error)
- func (c *Client) LatestRunsForPRs(scope PRScope, within time.Duration) ([]WorkflowRun, error)
- func (c *Client) LatestRunsOnBranch(branch string, within time.Duration) ([]WorkflowRun, error)
- func (c *Client) ListRuns(q RunQuery) ([]WorkflowRun, error)
- func (c *Client) Owner() string
- func (c *Client) Repo() string
- type Job
- type JobsResponse
- type PRScope
- type RunQuery
- type RunsResponse
- type Step
- type WorkflowRun
Constants ¶
const ( StatusQueued = "queued" StatusInProgress = "in_progress" StatusCompleted = "completed" )
RunStatus constants.
const ( ConclusionSuccess = "success" ConclusionFailure = "failure" ConclusionCancelled = "cancelled" //nolint:misspell // matches GitHub Actions API's actual conclusion value ConclusionSkipped = "skipped" )
Conclusion constants.
Variables ¶
var ErrInvalidRepositoryFormat = errors.New("invalid repository format (expected owner/repo)")
ErrInvalidRepositoryFormat indicates a repository string was not in "owner/repo" format.
var ErrNoWorkflowRuns = errors.New("no workflow runs found")
ErrNoWorkflowRuns indicates no workflow runs matched the query.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the GitHub API via gh CLI.
func NewClient ¶
NewClient creates a new GitHub API client for the specified repository. Uses the real gh CLI executor by default.
func NewClientWithExecutor ¶
func NewClientWithExecutor(repoFullName string, executor exec.CommandExecutor) (*Client, error)
NewClientWithExecutor creates a new GitHub API client with a custom executor. This allows injecting a mock executor for testing.
func (*Client) GetLatestRun ¶
func (c *Client) GetLatestRun(workflowName string) (*WorkflowRun, error)
GetLatestRun fetches the most recent workflow run, optionally filtered by workflow name.
func (*Client) GetWorkflowRun ¶
func (c *Client) GetWorkflowRun(runID int64) (*WorkflowRun, error)
GetWorkflowRun fetches a single workflow run by ID.
func (*Client) GetWorkflowRunJobs ¶
GetWorkflowRunJobs fetches the jobs for a workflow run, with the per-step timings the timeline lays out.
func (*Client) LatestRunsForPRs ¶ added in v1.7.0
LatestRunsForPRs returns the current state of each workflow on the head branch of every pull request matching scope.
It reads one page of the repository's recent runs rather than a page per branch, so a pull request whose last run has aged out of that page reports nothing rather than costing another round trip.
func (*Client) LatestRunsOnBranch ¶ added in v1.6.0
LatestRunsOnBranch returns the newest run of each workflow on a branch, which is the branch's current state rather than its history. A run older than within is dropped unless it is still going; a zero within keeps every age.
type Job ¶
type Job struct {
StartedAt time.Time `json:"started_at"`
// CompletedAt is the zero time while the job is still running.
CompletedAt time.Time `json:"completed_at"`
Name string `json:"name"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
Steps []Step `json:"steps"`
ID int64 `json:"id"`
}
Job represents a job within a workflow run.
type JobsResponse ¶
JobsResponse represents the API response for listing jobs.
type PRScope ¶ added in v1.7.0
type PRScope string
PRScope names which pull requests a run listing should cover. Both are search queries rather than API filters, because "mine" and "awaiting my review" are questions only the search index answers.
type RunQuery ¶ added in v1.3.0
type RunQuery struct {
// Workflow is a workflow filename ("ci.yml"), not its display name.
Workflow string
Branch string
Status string
Event string
Limit int
}
RunQuery narrows a run listing. A zero value lists the most recent runs across every workflow.
type RunsResponse ¶
type RunsResponse struct {
WorkflowRuns []WorkflowRun `json:"workflow_runs"`
TotalCount int `json:"total_count"`
}
RunsResponse represents the API response for listing runs.
type Step ¶
type Step struct {
StartedAt time.Time `json:"started_at"`
// CompletedAt is the zero time while the step is still running, and
// StartedAt is zero for a step that has not begun.
CompletedAt time.Time `json:"completed_at"`
Name string `json:"name"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
Number int `json:"number"`
}
Step represents a step within a job.
type WorkflowRun ¶
type WorkflowRun struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Name string `json:"name"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
HTMLURL string `json:"html_url"`
HeadBranch string `json:"head_branch"`
// Event is what started the run ("workflow_dispatch", "pull_request"), and
// Path is the workflow's bare filename ("ci.yml").
Event string `json:"event,omitempty"`
Path string `json:"path,omitempty"`
ID int64 `json:"id"`
}
WorkflowRun represents a GitHub Actions workflow run.
func (WorkflowRun) IsActive ¶
func (r WorkflowRun) IsActive() bool
IsActive returns true if the run is still in progress.
func (WorkflowRun) IsSuccess ¶
func (r WorkflowRun) IsSuccess() bool
IsSuccess returns true if the run completed successfully.