Documentation
¶
Overview ¶
Package github is github-scout's GitHub REST API client. It exposes exactly the reads the scout needs — discover an owner's repos, list a repo's completed workflow runs, search open PRs and issues across all of them, and list a repo's code-scanning alerts — over the cplieger/httpx retry transport. Public repos and (with a token that can see them) private repos are both covered, which is the whole reason this exists: the Grafana GitHub-datasource plugin cannot enumerate "all workflows across all repos", and private repos have no org-level alert endpoint.
Attribution: the auth-header set and the page-count pagination approach follow patterns common to the MIT-licensed community GitHub exporters (githubexporter/github-exporter, xrstf/github_exporter). See NOTICE.
Index ¶
- type Client
- func (c *Client) ListCodeScanningAlerts(ctx context.Context, repo model.Repo) ([]model.CodeScanningAlert, error)
- func (c *Client) ListRepos(ctx context.Context, owner string) ([]model.Repo, error)
- func (c *Client) ListRuns(ctx context.Context, repo model.Repo, since time.Time) ([]model.WorkflowRun, error)
- func (c *Client) SearchOpenIssues(ctx context.Context, owner, exclude string) ([]model.Issue, error)
- func (c *Client) SearchOpenPRs(ctx context.Context, owner, exclude string) ([]model.PullRequest, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client reads the GitHub REST API. Construct via NewClient; the zero value is not usable.
func NewClient ¶
func NewClient(client *http.Client, token string, retryOpts []httpx.Option, logger *slog.Logger) *Client
NewClient returns a Client using the provided *http.Client for all requests, authenticating with token, and applying retryOpts to each call. A nil logger falls back to slog.Default.
func (*Client) ListCodeScanningAlerts ¶ added in v1.1.0
func (c *Client) ListCodeScanningAlerts(ctx context.Context, repo model.Repo) ([]model.CodeScanningAlert, error)
ListCodeScanningAlerts returns open code-scanning alerts for repo. A repo that never ran code scanning returns 404 (no analyses); that is a benign "no data" outcome rather than a read failure, so it is surfaced as model.ErrNoCodeScanning (the collector treats such a repo as neither readable nor blind). A 403 is surfaced as a generic error: it can mean GitHub Advanced Security is disabled (expected on a private repo without a GHAS license) OR a missing token scope OR a rate-limit, and silently reporting zero alerts would hide a security signal. The collector treats a per-repo 403 as a degraded read and escalates only when code scanning is blind for EVERY repo that has it; silence an expected, persistent 403 (a private repo without GHAS) via EXCLUDE_REPOS.
func (*Client) ListRepos ¶
ListRepos returns every non-archived repo owned by the authenticated token whose owner login equals owner. It uses /user/repos (not /users/{owner}/repos) so private repos are included — failed Actions runs in a private repo are just as actionable as public ones, and the public endpoint omits them. Results are filtered to owner so a token with org memberships doesn't pull in repos the operator didn't ask for.
func (*Client) ListRuns ¶ added in v1.1.0
func (c *Client) ListRuns(ctx context.Context, repo model.Repo, since time.Time) ([]model.WorkflowRun, error)
ListRuns returns all completed workflow runs for repo created at or after since, in a single paginated query. status=completed catches every conclusion (success, failure, timed_out, cancelled, …) in one request, so the former per-conclusion fan-out is gone: the collector emits each run once and classifies failures via model.IsFailureConclusion, and the dashboard derives both the failures view and the failure rate from the one all-runs stream. The Actions API returns runs newest-first, so a repo that exceeds maxPages*perPage completed runs inside the lookback window has its oldest runs truncated — acceptable, since that volume is itself a signal worth investigating directly.
func (*Client) SearchOpenIssues ¶ added in v1.1.0
func (c *Client) SearchOpenIssues(ctx context.Context, owner, exclude string) ([]model.Issue, error)
SearchOpenIssues returns every open issue across the owner's repos in a single cross-repo query. exclude filters bot/auto-generated noise (e.g. "-author:app/renovate -label:renovate -label:auto-generated").
func (*Client) SearchOpenPRs ¶ added in v1.1.0
func (c *Client) SearchOpenPRs(ctx context.Context, owner, exclude string) ([]model.PullRequest, error)
SearchOpenPRs returns every open pull request across the owner's repos in a single cross-repo query. exclude is appended raw to the search query (e.g. "-author:app/renovate") so the caller controls noise filtering.