discover

package
v0.0.0-...-7ced6bb Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package discover adapts downstream's package-specific ecosyste.ms lookup and configuration format to github.com/git-pkgs/dependents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reconcile

func Reconcile(existing *config.Config, pkg config.Package, cands []Candidate) *config.Config

Reconcile merges discovered candidates with an existing config. Manual entries are kept verbatim. Discover entries that are still in the candidate set get their comment refreshed but keep any ref/subdir/test/skip_baseline overrides the user added. Discover entries that fell out are dropped. New candidates not in the existing file are appended at the end with the New flag set.

If existing is nil, all candidates are returned as a fresh config.

Types

type AnalyzeOptions

type AnalyzeOptions struct {
	Upstream string // package name the candidates depend on
	Workdir  string // clones go under here; temp dir if empty
	Limit    int    // final number to keep after re-ranking
	Keep     bool   // leave clones for a follow-up downstream test
	Checkout dependents.Checkout
}

AnalyzeOptions controls phase-two scoring.

type Candidate

type Candidate struct {
	Name              string
	Repo              string
	Stars             int
	DependentPackages int
	DependentRepos    int
	Downloads         int64
	PushedAt          time.Time
	Language          string

	TestFiles   int
	ImportFiles int
	Analyzed    bool
	New         bool
}

Candidate contains the downstream-specific presentation fields for a repository candidate. Selection, ranking, and analysis are delegated to the dependents package.

func Analyze

func Analyze(ctx context.Context, candidates []Candidate, opts AnalyzeOptions, log func(string, ...any)) ([]Candidate, error)

Analyze delegates checkout and source analysis to dependents, then applies downstream's requirement that analyzed repositories contain tests and references to the upstream package. Checkout failures retain their popularity score instead of aborting discovery.

func Discover

func Discover(ctx context.Context, opts Options) ([]Candidate, error)

Discover fetches package dependents, then uses the dependents package to combine repositories, apply downstream's repository policy, and rank the result.

func (Candidate) Comment

func (c Candidate) Comment() string

func (Candidate) Dependent

func (c Candidate) Dependent() config.Dependent

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
	UserAgent  string
	MaxRetries int
	Backoff    time.Duration // initial backoff; doubles per retry
}

Client talks to packages.ecosyste.ms. The dependent_packages endpoint times out for popular packages until ecosyste-ms/packages#1657 is deployed; retries with backoff are applied but a hard error is returned once they're exhausted.

func NewClient

func NewClient() *Client

func (*Client) DependentPackages

func (c *Client) DependentPackages(ctx context.Context, ecosystem, pkg string, limit int) ([]Package, error)

DependentPackages fetches up to limit dependents of pkg in the given ecosystem, sorted server-side by the ecosystem's popularity proxy. It pages until limit is reached or the server returns an empty page.

type Options

type Options struct {
	Ecosystem string // go, npm, rubygems, ...
	Package   string // module path or package name
	Limit     int    // final number of dependents to keep
	Pool      int    // candidates to fetch before filtering; defaults to Limit*poolMultiplier
	MaxAge    time.Duration
	Client    *Client
	Stderr    io.Writer
}

type Package

type Package struct {
	Name                   string       `json:"name"`
	Ecosystem              string       `json:"ecosystem"`
	RepositoryURL          string       `json:"repository_url"`
	DependentPackagesCount int          `json:"dependent_packages_count"`
	DependentReposCount    int          `json:"dependent_repos_count"`
	Downloads              int64        `json:"downloads"`
	LatestRelease          string       `json:"latest_release_number"`
	Status                 string       `json:"status"`
	RepoMetadata           RepoMetadata `json:"repo_metadata"`
}

Package is the subset of the packages.ecosyste.ms package object we care about.

type RepoMetadata

type RepoMetadata struct {
	FullName        string    `json:"full_name"`
	HTMLURL         string    `json:"html_url"`
	Fork            bool      `json:"fork"`
	Archived        bool      `json:"archived"`
	MirrorURL       string    `json:"mirror_url"`
	StargazersCount int       `json:"stargazers_count"`
	PushedAt        time.Time `json:"pushed_at"`
	Language        string    `json:"language"`
	SourceName      string    `json:"source_name"`
}

func (*RepoMetadata) UnmarshalJSON

func (r *RepoMetadata) UnmarshalJSON(data []byte) error

UnmarshalJSON tolerates repo_metadata being null or an empty array (the API returns [] when the repo hasn't been synced).

Jump to

Keyboard shortcuts

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