scorer

package
v0.1.0-dev9 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

README

Scorer

Vendor-agnostic interface for computing success probability scores for code changes.

Interface

Scorer

Computes a success probability for a given change.

type Scorer interface {
    Score(ctx context.Context, change entity.Change) (float64, error)
}
  • change: A entity.Change identifying the code change to score.
  • Score: Returns a probability between 0.0 and 1.0 indicating the likelihood of a successful land. Returns an error if scoring fails.

Implementations

Heuristic

Scores a change by extracting a numeric value via a ValueFunc and matching it against ordered buckets. Each bucket maps a [Min, Max] range to a probability.

s := heuristic.New(
    []heuristic.Bucket{
        {Min: 0, Max: 5, Score: 0.95},
        {Min: 6, Max: 20, Score: 0.75},
        {Min: 21, Max: 100, Score: 0.5},
    },
    func(ctx context.Context, change entity.Change) (int, error) {
        // resolve the change into a numeric metric
        return filesChanged, nil
    },
)

score, err := s.Score(ctx, change)
Composite

Combines multiple named scorers into a single score using a reduce function. The reduce function receives a map[string]float64 mapping scorer names to their scores, enabling domain-aware aggregation.

Built-in reduce functions: Min, Max, Avg.

s := composite.New(
    map[string]scorer.Scorer{
        "files": fileScorer,
        "deps":  depScorer,
    },
    composite.Min,
)

score, err := s.Score(ctx, change)

Implementing a Backend

  1. Create extension/scorer/{backend}/ directory
  2. Implement the Scorer interface
  3. Accept entity.Change and resolve it into whatever data the implementation needs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// QueueName identifies the queue this Scorer serves.
	QueueName string
}

Config carries the per-queue identity handed to a Factory. The system knows only the queue name; everything an implementation needs is injected at construction by the integrator.

type Factory

type Factory interface {
	// For returns the Scorer for the given queue.
	For(cfg Config) (Scorer, error)
}

Factory builds the Scorer for a queue. Implementations are provided by integrators (and tests) and inject whatever they need at construction.

type Scorer

type Scorer interface {
	// Score returns a probability between 0.0 and 1.0 indicating the likelihood
	// of a successful land for the given batch. It is handed the batch identity
	// and resolves the batch's changes itself through an injected changeset.Resolver.
	Score(ctx context.Context, batch entity.Batch) (float64, error)
}

Scorer computes a success probability score for a batch based on its changes.

Directories

Path Synopsis
Package fake provides a scorer.Scorer that decorates an existing scorer: it delegates to the wrapped implementation for the happy path, but injects an error when a change URI carries a failure marker of the form "sq-fake=<token>":
Package fake provides a scorer.Scorer that decorates an existing scorer: it delegates to the wrapped implementation for the happy path, but injects an error when a change URI carries a failure marker of the form "sq-fake=<token>":
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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