filter

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package filter provides notification filtering based on configurable rules.

Package filter provides notification filtering based on configurable rules.

Package filter provides notification filtering based on configurable rules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompiledRule

type CompiledRule struct {
	Name       string         // Human-readable name of the rule
	Reasons    ValueFilter    // Filter for notification reason (assigned, mentioned, etc.)
	Repos      ValueFilter    // Filter for repository name
	Types      ValueFilter    // Filter for notification type (Issue, PullRequest, etc.)
	TitleRegex *regexp.Regexp // Optional regex pattern for notification title
}

CompiledRule is a filter rule with pre-compiled regular expressions for efficient matching. All conditions within a rule use AND logic; all must match for the rule to apply.

type Config

type Config struct {
	DaysAgo int    `yaml:"since_days_ago"` // Number of days to look back for notifications
	Filters []Rule `yaml:"filters"`        // List of filter rules to apply
}

Config represents the top-level configuration for notification filtering. It specifies the time range for fetching notifications and the filter rules to apply.

func LoadDefault

func LoadDefault() (*Config, error)

LoadDefault loads the configuration from the default location (~/.config/gh-quoi/config.yaml). Returns an error if the file cannot be read or parsed.

func LoadFile

func LoadFile(path string) (*Config, error)

LoadFile loads and parses the configuration from the specified file path. Returns an error if the file cannot be read or contains invalid YAML.

type Matcher

type Matcher struct {
	// contains filtered or unexported fields
}

Matcher evaluates notifications against a set of compiled filter rules. It determines whether a notification should be displayed based on the configured criteria.

func NewMatcher

func NewMatcher(cfg *Config) (*Matcher, error)

NewMatcher creates a new Matcher from the provided configuration. It compiles all regular expressions and returns an error if any regex is invalid.

func (*Matcher) Match

func (m *Matcher) Match(n model.Notification) bool

Match returns true if the notification matches at least one configured rule. Rules use OR logic: a match on any rule means the notification should be displayed.

type Rule

type Rule struct {
	Name       string      `yaml:"name"`        // Human-readable name for the rule
	Reasons    ValueFilter `yaml:"reasons"`     // Filter by notification reason
	Repos      ValueFilter `yaml:"repos"`       // Filter by repository name
	Types      ValueFilter `yaml:"types"`       // Filter by notification type
	TitleRegex string      `yaml:"title_regex"` // Regular expression to match title
}

Rule defines a single filter rule that can be applied to notifications. All fields are optional. When multiple fields are specified, all conditions must match (AND logic) for the rule to apply.

type ValueFilter

type ValueFilter struct {
	Any []string `yaml:"-"`   // Patterns to match (glob-style). Empty means match all.
	Not []string `yaml:"not"` // Patterns to exclude (glob-style)
}

ValueFilter specifies which values to include or exclude using patterns. Supports both simple list format and explicit include/exclude format.

Examples:

  • Simple list: reasons: ["assigned", "mentioned"]
  • With exclusions: repos: {any: ["org/*"], not: ["org/archived-*"]}

func (*ValueFilter) UnmarshalYAML

func (vf *ValueFilter) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements custom YAML unmarshaling to support two formats:

  1. Simple list: reasons: ["assigned", "mention"]
  2. Object with any/not: repos: {any: ["org/*"], not: ["org/old-*"]}

Jump to

Keyboard shortcuts

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