Documentation
¶
Overview ¶
Package subscription matches release events to subscription filters.
Filters have the approved watch-file shape (docs/watch-file.md section 2.5). Matching is pure. Input is the minimal event view the future release event (#106) maps to.
Index ¶
Constants ¶
const ( PrereleaseInherit = "" // subscription only: no opinion, keep what the watch admitted PrereleaseNone = "none" // final versions only PrereleaseOnly = "only" // pre-releases only PrereleaseInclude = "include" // both )
Pre-release modes, the same words as the watch policy's prerelease key.
const MaxCooldown = policy.MaxCooldown
MaxCooldown is the longest cooldown, the watch's limit.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
// Type is the event type; "release.yanked" is not subject to Policy.
Type string
// Prerelease reports whether the version is a pre-release.
Prerelease bool
// WatchPrerelease is the watch policy's prerelease mode ("none", "only"
// or "include"); empty means unknown and is not checked.
WatchPrerelease string
// CooldownStart is the instant the watch policy's cooldown counts from.
// The #106 match step must fill it from
// Release.CooldownFrom(policy.TrustsPublishedAt(kind)). Zero (unknown)
// fails closed: Evaluate counts from now, holding for the full
// subscription cooldown.
CooldownStart time.Time
// WatchCooldown is the cooldown the watch policy applied.
WatchCooldown time.Duration
}
Event is what Evaluate needs of the event and of the watch policy's result for it. None of it needs I/O.
type Filter ¶
type Filter struct {
// Source lists accepted source kinds; empty means any.
Source []string `json:"source"`
// Labels must all be present on the input with equal values.
Labels map[string]string `json:"labels"`
// Bump lists accepted bumps; empty means any.
Bump []string `json:"bump"`
// Package is a path.Match glob on the package name; empty means any.
// The match is case-sensitive and "*" does not cross "/", so "@angular/*"
// matches "@angular/core" but not "@angular/core/testing".
Package string `json:"package"`
// Type lists accepted event types; empty means any. The watch-file loader
// fills in [release.published] when the file omits it, so a stored filter
// normally has it set; this package adds no default.
Type []string `json:"type"`
}
Filter selects events. Every non-empty field must match. The zero value matches everything. Field names and meaning follow the watch file.
func FromJSON ¶
FromJSON decodes a stored filter (subscription.filter_json). Unknown keys are errors, so a typo is not silently a match-everything filter. Empty or "null" input yields the zero (match-all) filter.
type Input ¶
type Input struct {
// Source is the source kind of the watch ("npm", "pypi", ...), the
// "ecosystem" of the PRD.
Source string `json:"source"`
// Package is the package name as the source normalised it ("@angular/core").
Package string `json:"package"`
// Labels are the labels of the watch that produced the event.
Labels map[string]string `json:"labels"`
// Bump is the classifier's result: "major", "minor", "patch",
// "prerelease" or "other", or empty when unclassified. A filter with a
// Bump list matches only a value in that list, so "prerelease", "other"
// and "" never match it.
Bump string `json:"bump"`
// Type is the event type: "release.published", "release.yanked" or
// "release.prerelease".
Type string `json:"type"`
}
Input is what a filter looks at. It is the minimal shape the future release event (#106) maps to; none of the fields needs I/O to fill.
type Matcher ¶
type Matcher struct {
// contains filtered or unexported fields
}
Matcher holds a set of subscriptions and finds those accepting an input. It is immutable after construction and safe for concurrent use.
func NewMatcher ¶
func NewMatcher(subs []Subscription) *Matcher
NewMatcher builds a matcher over subs. Filters are deep-copied, so callers may reuse their slices and maps afterwards.
type Policy ¶
type Policy struct {
// Prerelease is "", "none", "only" or "include". "" and "include"
// narrow nothing.
Prerelease string `json:"prerelease"`
// Cooldown is the minimum age of a version, from the same start as the
// watch's cooldown: the effective hold is max(watch, subscription).
Cooldown time.Duration `json:"-"`
}
Policy is the narrowing policy of a subscription (ADR 0014). It can only receive less, later, than the watch policy admitted: Evaluate intersects it with the watch's result, so no value widens. The bump key is not here; it is Filter.Bump.
func PolicyFromJSON ¶
PolicyFromJSON decodes subscription.policy_json. Empty, "null" and "{}" give the zero policy (inherit everything). Unknown keys are errors. The result is clamped.
func (Policy) Clamp ¶
Clamp returns the policy with useless values cut to the nearest useful one: a negative cooldown becomes 0 and one above MaxCooldown becomes MaxCooldown. It never fails (ADR 0014 decision 2).
func (Policy) Evaluate ¶
Evaluate decides what a subscription with policy p does with an event at time now: Drop when the pre-release mode of the watch or of the subscription excludes it, Hold until CooldownStart + max(WatchCooldown, p.Cooldown) when that is still ahead, Admit otherwise. The result is always a subset of what the watch admitted: the watch's mode is applied first, a cooldown shorter than the watch's changes nothing, and a yank notice ignores p. It is pure; the match step of #106 calls it once per matching subscription.
func (Policy) MarshalJSON ¶
MarshalJSON writes the stored form, defaults filled.
type Subscription ¶
Subscription is a filter with the id of the subscription it belongs to.