github

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIBaseFromEnv

func APIBaseFromEnv() string

func DisplayOwners

func DisplayOwners(repos []Repo) []string

DisplayOwners returns sorted github.com/owner labels for unique repository owners.

func DisplayTarget

func DisplayTarget(path string) string

DisplayTarget returns a user-facing label for an audit path.

func DisplayTargets

func DisplayTargets(inputs []string) ([]string, error)

DisplayTargets returns user-facing labels for github subcommand inputs.

func IsAuditRef

func IsAuditRef(input string) bool

IsAuditRef reports whether input resolves to a single repository (not org-wide).

func IsExplicitAuditRef

func IsExplicitAuditRef(input string) bool

IsExplicitAuditRef reports whether input is an explicit GitHub repository reference (github:/gh: prefix or github.com URL), not a bare owner/repo slug that could be mistaken for a local path.

func ParallelWorkers

func ParallelWorkers(token string) int

ParallelWorkers returns a safe concurrency limit for GitHub API fetches. Unauthenticated access is capped lower to avoid exhausting the ~60 req/hr budget.

func RepoSkipReason

func RepoSkipReason(err error) string

RepoSkipReason returns a short human-readable reason for repository resolution failure.

func TokenFromEnv

func TokenFromEnv() string

Types

type APIError

type APIError struct {
	StatusCode  int
	Endpoint    string
	Body        string
	RateLimited bool
	RateLimit   rateLimitInfo
}

APIError is returned for non-success GitHub REST responses.

func AsAPIError

func AsAPIError(err error) (*APIError, bool)

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) IsRateLimited

func (e *APIError) IsRateLimited() bool

func (*APIError) NotFound

func (e *APIError) NotFound() bool

type Client

type Client struct {
	HTTPClient *http.Client
	APIBase    string
	Token      string
	UserAgent  string
	CacheTTL   time.Duration
	PollEvery  time.Duration
}

Client fetches dependency-graph SBOM exports from GitHub.

func NewClient

func NewClient(userAgent, token string, timeout time.Duration) *Client

func (*Client) AuthenticatedLogin

func (c *Client) AuthenticatedLogin(ctx context.Context) (string, error)

AuthenticatedLogin returns the GitHub username for the configured token.

func (*Client) FetchLockfiles

func (c *Client) FetchLockfiles(ctx context.Context, repo Repo, opts FetchOptions) ([]string, error)

func (*Client) FetchSBOM

func (c *Client) FetchSBOM(ctx context.Context, repo Repo, opts FetchOptions) (string, error)

FetchSBOM returns a cached or freshly downloaded SPDX JSON path for the repo.

func (*Client) ListAccessibleRepos

func (c *Client) ListAccessibleRepos(ctx context.Context, limit int) ([]Repo, error)

ListAccessibleRepos lists repositories the authenticated token can access.

func (*Client) ListOwnerRepos

func (c *Client) ListOwnerRepos(ctx context.Context, owner string, limit int) ([]Repo, error)

ListOwnerRepos lists repositories for a GitHub org or user.

func (*Client) ResolveRepos

func (c *Client) ResolveRepos(ctx context.Context, inputs []string, limit int) ([]Repo, error)

ResolveRepos expands github subcommand targets into concrete repositories. With no inputs and an authenticated client, lists repositories the token can access.

func (*Client) ResolveSources

func (c *Client) ResolveSources(ctx context.Context, repo Repo, opts FetchOptions) ([]string, error)

ResolveSources returns local scan paths for a repo: SBOM when available, otherwise lockfiles discovered in the repository tree.

type FetchOptions

type FetchOptions struct {
	CacheDir string
	OnStatus func(string)
}

type Repo

type Repo struct {
	Owner string
	Name  string
}

Repo identifies a GitHub repository for dependency graph SBOM export.

func ParseRepo

func ParseRepo(input string) (Repo, bool)

ParseRepo parses a single repository reference. Returns false for org-only targets.

func (Repo) AuditRef

func (r Repo) AuditRef() string

AuditRef returns the canonical depx internal label for this repository.

func (Repo) CachePath

func (r Repo) CachePath(cacheDir string) string

func (Repo) DisplayTarget

func (r Repo) DisplayTarget() string

DisplayTarget returns a schema-less GitHub label for results output.

func (Repo) String

func (r Repo) String() string

func (Repo) URL

func (r Repo) URL() string

type Target

type Target struct {
	Owner string
	Name  string // empty when scanning all repos for Owner
}

Target is a GitHub repository or an org/user to expand into repositories.

func ParseTarget

func ParseTarget(input string) (Target, error)

ParseTarget parses github subcommand inputs:

func (Target) IsOrg

func (t Target) IsOrg() bool

func (Target) Repo

func (t Target) Repo() (Repo, bool)

Jump to

Keyboard shortcuts

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