github

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package github provides a client for interacting with GitHub API operations.

Index

Constants

View Source
const (
	StatusQueued     = "queued"
	StatusInProgress = "in_progress"
	StatusCompleted  = "completed"
)

RunStatus constants.

View Source
const (
	ConclusionSuccess   = "success"
	ConclusionFailure   = "failure"
	ConclusionCancelled = "cancelled" //nolint:misspell // matches GitHub Actions API's actual conclusion value
	ConclusionSkipped   = "skipped"
)

Conclusion constants.

Variables

View Source
var ErrInvalidRepositoryFormat = errors.New("invalid repository format (expected owner/repo)")

ErrInvalidRepositoryFormat indicates a repository string was not in "owner/repo" format.

View Source
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

func NewClient(repoFullName string) (*Client, error)

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

func (c *Client) GetWorkflowRunJobs(runID int64) ([]Job, error)

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

func (c *Client) LatestRunsForPRs(scope PRScope, within time.Duration) ([]WorkflowRun, error)

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

func (c *Client) LatestRunsOnBranch(branch string, within time.Duration) ([]WorkflowRun, error)

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.

func (*Client) ListRuns added in v1.3.0

func (c *Client) ListRuns(q RunQuery) ([]WorkflowRun, error)

ListRuns fetches recent workflow runs matching q, newest first.

func (*Client) Owner

func (c *Client) Owner() string

Owner returns the repository owner.

func (*Client) Repo

func (c *Client) Repo() string

Repo returns the repository name.

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

type JobsResponse struct {
	Jobs       []Job `json:"jobs"`
	TotalCount int   `json:"total_count"`
}

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.

const (
	PRScopeMine      PRScope = "is:open author:@me"
	PRScopeReviewing PRScope = "is:open review-requested:@me"
)

Pull request scopes worth a saved view.

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.

Jump to

Keyboard shortcuts

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