filter

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package filter implements the TaskCreationFilter chain.

Package filter implements the TaskCreationFilter chain — predicates that decide whether a vault task should be created for a PR at all.

This is one of two decision chains in the watcher:

  1. TaskCreationFilter (this package): "should we create a task?"
  2. trust.Trust (sibling package): "given we create a task, should it auto-process or route to human_review?"

See docs/watcher-decision-chains.md for the full split rationale.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseRepoAllowlist

func ParseRepoAllowlist(_ context.Context, raw string) ([]string, error)

ParseRepoAllowlist parses a comma-separated allowlist string into a slice of host-qualified repo keys. Whitespace is trimmed; empty entries are skipped. Returns (nil, nil) for empty input (allow-all). Entry well-formedness is NOT validated here — repoallowlist.IsAllowed handles malformed entries gracefully at match time (logs and skips).

Types

type PR

type PR struct {
	AuthorLogin string
	IsDraft     bool
	Title       string
	UpdatedAt   libtime.DateTime
	RepoKey     string
}

PR is the filter-evaluation input derived from a GitHub pull request. Only the fields needed for task-creation filter decisions are included.

type TaskCreationFilter

type TaskCreationFilter interface {
	// Skip returns true if the PR should be excluded from task creation.
	Skip(pr PR) bool
	// Name returns the filter's stable identity, used in the skip log line
	// so an operator can tell which member of the chain fired. It is a
	// mandatory interface method (not an optional secondary interface): an
	// optional one would let a future filter skip silently without naming
	// itself, which is the exact defect this identity fixes.
	Name() string
}

TaskCreationFilter decides whether a single PR should be skipped (no vault task created). Implementations return true to skip.

func NewAgeFilter

func NewAgeFilter(maxAge libtime.Duration, referenceTime libtime.DateTime) TaskCreationFilter

NewAgeFilter returns a filter that skips PRs whose UpdatedAt is older than (referenceTime - maxAge). A zero maxAge disables the filter.

referenceTime is the watcher's startTime — captured once at process start and threaded through factory.CreateWatcher. This avoids any CurrentDateTimeGetter injection: a watcher pod's lifetime is bounded by its restart cadence (hours), and the age filter's granularity is days, so sub-day clock drift is irrelevant.

func NewBotAuthorFilter

func NewBotAuthorFilter(allowlist []string) TaskCreationFilter

NewBotAuthorFilter returns a filter that skips PRs whose author matches any entry in the configured allowlist (exact match). An empty allowlist never skips.

func NewDraftFilter

func NewDraftFilter() TaskCreationFilter

NewDraftFilter returns a filter that skips draft PRs (the author is signaling "not ready for review"). GitHub's draft state is the primary signal; literal "WIP" prefixes in the title are handled by a separate WIP filter (see wip_title_filter.go when added).

func NewRepoAllowlistFilter

func NewRepoAllowlistFilter(allowlist []string) TaskCreationFilter

NewRepoAllowlistFilter returns a TaskCreationFilter that skips PRs whose RepoKey is not in the allowlist. An empty allowlist never skips (allow-all).

func NewWIPTitleFilter

func NewWIPTitleFilter() TaskCreationFilter

NewWIPTitleFilter returns a filter that skips PRs whose title starts with "WIP:" or "WIP ". The author has explicitly signaled the PR is not ready for review.

type TaskCreationFilterFunc

type TaskCreationFilterFunc func(pr PR) bool

TaskCreationFilterFunc adapts a function to the TaskCreationFilter interface (function-as-implementation, useful for inline filters).

func (TaskCreationFilterFunc) Name added in v0.13.0

func (f TaskCreationFilterFunc) Name() string

Name implements TaskCreationFilter for the function adapter. Inline function filters carry no distinct identity, so they all report "inline".

func (TaskCreationFilterFunc) Skip

func (f TaskCreationFilterFunc) Skip(pr PR) bool

Skip implements TaskCreationFilter for the function adapter.

type TaskCreationFilters

type TaskCreationFilters []TaskCreationFilter

TaskCreationFilters is a slice composite: skip if ANY member votes skip. An empty slice never skips (no filters configured = process every PR).

func (TaskCreationFilters) Name added in v0.13.0

func (fs TaskCreationFilters) Name() string

Name implements TaskCreationFilter for the composite (the chain is assigned to the TaskCreationFilter interface in main.go). The chain is not a leaf predicate, so this identity is only a defensive fallback: the skip log line names the first voting member via SkippingFilter, never the chain itself.

func (TaskCreationFilters) Skip

func (fs TaskCreationFilters) Skip(pr PR) bool

Skip returns true if any contained filter votes skip. Iteration is short-circuit on first hit (filters are pure predicates with no side effects, so there is no audit-trail concern). Re-expressed via SkippingFilter so the chain has a single notion of "who voted skip".

func (TaskCreationFilters) SkippingFilter added in v0.13.0

func (fs TaskCreationFilters) SkippingFilter(pr PR) TaskCreationFilter

SkippingFilter returns the first member that votes skip, or nil when the chain passes. Skip() collapses that identity to a bool, and the chain returns on the first hit, so only the first voter is ever reachable.

Jump to

Keyboard shortcuts

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