github

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 9 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) CancelRun added in v1.10.0

func (c *Client) CancelRun(runID int64) error

CancelRun stops a run that is still going.

func (*Client) GetLatestRun

func (c *Client) GetLatestRun(workflowFile string) (*WorkflowRun, error)

GetLatestRun fetches the most recent run of a workflow file, or the most recent run in the repository when workflowFile is empty.

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) 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) ListEnvironments added in v1.10.0

func (c *Client) ListEnvironments() ([]string, error)

ListEnvironments names the repository's deployment environments, which is what a workflow input of type "environment" has to be one of. A repository that declares none answers with an empty list rather than an error.

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) PullRequestsInScope added in v1.9.0

func (c *Client) PullRequestsInScope(scope PRScope) ([]PullRequest, error)

PullRequestsInScope returns every pull request matching scope, each with its own check rollup.

The rollup is the answer rather than a run listing because runs are keyed by branch: one page of a repository's recent runs is filled by whichever branch ran last, so every other pull request in it reports nothing.

func (*Client) Repo

func (c *Client) Repo() string

Repo returns the repository name.

func (*Client) RerunFailedJobs added in v1.10.0

func (c *Client) RerunFailedJobs(runID int64) error

RerunFailedJobs re-runs only the failed jobs of a run, which is what a run that failed on one flaky job needs rather than a whole second run.

type Job

type Job = forge.Job

Job is one job of a workflow run, as aragonite models it.

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 PullRequest added in v1.9.0

type PullRequest = forge.PullRequest

PullRequest is aragonite's pull request model, which already carries the check rollup that answers whether a pull request is green.

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 Step

type Step = forge.Step

Step is one step of a job, as aragonite models it.

type WorkflowRun

type WorkflowRun = forge.WorkflowRun

WorkflowRun is one Actions run, as aragonite models it. Every read in this package goes through aragonite, so a local struct would only be a conversion of this one.

Jump to

Keyboard shortcuts

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