filter

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: May 26, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortByField

func SortByField(notifications []*github.Notification, field SortField, direction SortDirection) []*github.Notification

SortByField sorts notifications by a single field

Types

type AllFilter

type AllFilter struct{}

AllFilter matches all notifications

func (*AllFilter) Apply

func (f *AllFilter) Apply(notification *github.Notification) bool

Apply returns true for all notifications

func (*AllFilter) Description

func (f *AllFilter) Description() string

Description returns a human-readable description of the filter

type AndFilter

type AndFilter struct {
	// Filters is the list of filters to combine
	Filters []Filter
}

AndFilter combines multiple filters with AND logic

func (*AndFilter) Apply

func (f *AndFilter) Apply(notification *github.Notification) bool

Apply returns true if all filters match

func (*AndFilter) Description

func (f *AndFilter) Description() string

Description returns a human-readable description of the filter

type CompositeFilter

type CompositeFilter struct {
	Filters  []Filter
	Operator Operator
}

CompositeFilter combines multiple filters with a logical operator

func (*CompositeFilter) Apply

func (f *CompositeFilter) Apply(n *github.Notification) bool

Apply applies the composite filter to a notification

func (*CompositeFilter) Description

func (f *CompositeFilter) Description() string

Description returns a human-readable description of the composite filter

type Engine

type Engine struct {
	// Concurrency controls the number of worker goroutines
	Concurrency int
	// BatchSize controls the size of notification batches
	BatchSize int
	// Timeout controls the maximum time to spend filtering
	Timeout time.Duration
	// FilterExpr is the filter to apply
	FilterExpr Filter
	// IndexEnabled controls whether to use indexing
	IndexEnabled bool
	// contains filtered or unexported fields
}

Engine is a high-performance notification filtering engine

func NewEngine

func NewEngine() *Engine

NewEngine creates a new filtering engine

func (*Engine) Filter

func (e *Engine) Filter(ctx context.Context, notifications []*github.Notification) ([]*github.Notification, error)

Filter filters notifications using the configured filter

func (*Engine) OptimizeFilter

func (e *Engine) OptimizeFilter(filter Filter) Filter

OptimizeFilter optimizes a filter for better performance

func (*Engine) WithBatchSize

func (e *Engine) WithBatchSize(batchSize int) *Engine

WithBatchSize sets the batch size for the engine

func (*Engine) WithConcurrency

func (e *Engine) WithConcurrency(concurrency int) *Engine

WithConcurrency sets the concurrency for the engine

func (*Engine) WithFilter

func (e *Engine) WithFilter(filter Filter) *Engine

WithFilter sets the filter for the engine

func (*Engine) WithIndexing

func (e *Engine) WithIndexing(enabled bool) *Engine

WithIndexing enables or disables indexing

func (*Engine) WithTimeout

func (e *Engine) WithTimeout(timeout time.Duration) *Engine

WithTimeout sets the timeout for the engine

type Filter

type Filter interface {
	// Apply applies the filter to a notification
	Apply(*github.Notification) bool
	// Description returns a human-readable description of the filter
	Description() string
}

Filter represents a notification filter

type FilterBuilder

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

FilterBuilder helps build complex filters

func NewFilterBuilder

func NewFilterBuilder() *FilterBuilder

NewFilterBuilder creates a new filter builder

func (*FilterBuilder) And

func (b *FilterBuilder) And(filter Filter) *FilterBuilder

And adds a filter with AND logic

func (*FilterBuilder) Build

func (b *FilterBuilder) Build() Filter

Build builds the final filter

func (*FilterBuilder) Not

func (b *FilterBuilder) Not(filter Filter) *FilterBuilder

Not adds a filter with NOT logic

func (*FilterBuilder) Or

func (b *FilterBuilder) Or(filter Filter) *FilterBuilder

Or adds a filter with OR logic

type FilterFunc

type FilterFunc func(*github.Notification) bool

FilterFunc is a function that filters notifications

type NotFilter

type NotFilter struct {
	// Filter is the filter to negate
	Filter Filter
}

NotFilter negates a filter

func (*NotFilter) Apply

func (f *NotFilter) Apply(notification *github.Notification) bool

Apply returns true if the filter does not match

func (*NotFilter) Description

func (f *NotFilter) Description() string

Description returns a human-readable description of the filter

type Operator

type Operator int

Operator represents a logical operator for combining filters

const (
	// And represents logical AND
	And Operator = iota
	// Or represents logical OR
	Or
	// Not represents logical NOT
	Not
)

type OrFilter

type OrFilter struct {
	// Filters is the list of filters to combine
	Filters []Filter
}

OrFilter combines multiple filters with OR logic

func (*OrFilter) Apply

func (f *OrFilter) Apply(notification *github.Notification) bool

Apply returns true if any filter matches

func (*OrFilter) Description

func (f *OrFilter) Description() string

Description returns a human-readable description of the filter

type OrgFilter

type OrgFilter struct {
	// Org is the organization name to match
	Org string
}

OrgFilter filters notifications by organization

func (*OrgFilter) Apply

func (f *OrgFilter) Apply(notification *github.Notification) bool

Apply returns true if the notification is from the specified organization

func (*OrgFilter) Description

func (f *OrgFilter) Description() string

Description returns a human-readable description of the filter

type OrganizationFilter

type OrganizationFilter struct {
	Pattern glob.Glob
	Raw     string
}

OrganizationFilter filters notifications by organization name

func NewOrganizationFilter

func NewOrganizationFilter(pattern string) (*OrganizationFilter, error)

NewOrganizationFilter creates a new organization filter

func (*OrganizationFilter) Apply

Apply applies the organization filter to a notification

func (*OrganizationFilter) Description

func (f *OrganizationFilter) Description() string

Description returns a human-readable description of the organization filter

type ReadFilter

type ReadFilter struct {
	// Read is true to match read notifications, false to match unread
	Read bool
}

ReadFilter filters notifications by read status

func (*ReadFilter) Apply

func (f *ReadFilter) Apply(notification *github.Notification) bool

Apply returns true if the notification matches the read status

func (*ReadFilter) Description

func (f *ReadFilter) Description() string

Description returns a human-readable description of the filter

type ReasonFilter

type ReasonFilter struct {
	// Reason is the notification reason to match
	Reason string
}

ReasonFilter filters notifications by reason

func (*ReasonFilter) Apply

func (f *ReasonFilter) Apply(notification *github.Notification) bool

Apply returns true if the notification has the specified reason

func (*ReasonFilter) Description

func (f *ReasonFilter) Description() string

Description returns a human-readable description of the filter

type RegexFilter

type RegexFilter struct {
	Pattern *regexp.Regexp
	Field   string
}

RegexFilter filters notifications by a regular expression

func NewRegexFilter

func NewRegexFilter(pattern string, field string) (*RegexFilter, error)

NewRegexFilter creates a new regex filter

func (*RegexFilter) Apply

func (f *RegexFilter) Apply(n *github.Notification) bool

Apply applies the regex filter to a notification

func (*RegexFilter) Description

func (f *RegexFilter) Description() string

Description returns a human-readable description of the regex filter

type RepoFilter

type RepoFilter struct {
	// Repo is the repository name to match
	Repo string
}

RepoFilter filters notifications by repository

func (*RepoFilter) Apply

func (f *RepoFilter) Apply(notification *github.Notification) bool

Apply returns true if the notification is from the specified repository

func (*RepoFilter) Description

func (f *RepoFilter) Description() string

Description returns a human-readable description of the filter

type RepositoryFilter

type RepositoryFilter struct {
	Pattern glob.Glob
	Raw     string
}

RepositoryFilter filters notifications by repository name

func NewRepositoryFilter

func NewRepositoryFilter(pattern string) (*RepositoryFilter, error)

NewRepositoryFilter creates a new repository filter

func (*RepositoryFilter) Apply

Apply applies the repository filter to a notification

func (*RepositoryFilter) Description

func (f *RepositoryFilter) Description() string

Description returns a human-readable description of the repository filter

type SortCriterion

type SortCriterion struct {
	Field     SortField
	Direction SortDirection
}

SortCriterion represents a criterion for sorting

func NewSortCriterion

func NewSortCriterion(field SortField, direction SortDirection) SortCriterion

NewSortCriterion creates a new sort criterion

type SortDirection

type SortDirection int

SortDirection represents the direction of sorting

const (
	// Ascending sorts in ascending order
	Ascending SortDirection = iota
	// Descending sorts in descending order
	Descending
)

type SortField

type SortField string

SortField represents a field to sort by

const (
	// SortByRepository sorts by repository name
	SortByRepository SortField = "repository"
	// SortByType sorts by notification type
	SortByType SortField = "type"
	// SortByTitle sorts by notification title
	SortByTitle SortField = "title"
	// SortByTime sorts by notification time
	SortByTime SortField = "time"
	// SortByStatus sorts by notification status
	SortByStatus SortField = "status"
	// SortByReason sorts by notification reason
	SortByReason SortField = "reason"
)

type Sorter

type Sorter struct {
	// Criteria is the list of sort criteria
	Criteria []SortCriterion
	// Parallel controls whether to use parallel sorting
	Parallel bool
	// BatchSize controls the size of notification batches for parallel sorting
	BatchSize int
}

Sorter sorts notifications

func NewSorter

func NewSorter() *Sorter

NewSorter creates a new sorter

func (*Sorter) Sort

func (s *Sorter) Sort(notifications []*github.Notification) []*github.Notification

Sort sorts the notifications

func (*Sorter) WithBatchSize

func (s *Sorter) WithBatchSize(batchSize int) *Sorter

WithBatchSize sets the batch size for parallel sorting

func (*Sorter) WithCriteria

func (s *Sorter) WithCriteria(criteria ...SortCriterion) *Sorter

WithCriteria sets the sort criteria

func (*Sorter) WithParallel

func (s *Sorter) WithParallel(parallel bool) *Sorter

WithParallel enables or disables parallel sorting

type StatusFilter

type StatusFilter struct {
	Unread bool
}

StatusFilter filters notifications by read status

func NewStatusFilter

func NewStatusFilter(unread bool) *StatusFilter

NewStatusFilter creates a new status filter

func (*StatusFilter) Apply

func (f *StatusFilter) Apply(n *github.Notification) bool

Apply applies the status filter to a notification

func (*StatusFilter) Description

func (f *StatusFilter) Description() string

Description returns a human-readable description of the status filter

type TextFilter

type TextFilter struct {
	// Text is the text to search for
	Text string
}

TextFilter filters notifications by text

func (*TextFilter) Apply

func (f *TextFilter) Apply(notification *github.Notification) bool

Apply returns true if the notification contains the specified text

func (*TextFilter) Description

func (f *TextFilter) Description() string

Description returns a human-readable description of the filter

type TimeFilter

type TimeFilter struct {
	Since      time.Time
	Before     time.Time
	UsesSince  bool
	UsesBefore bool
}

TimeFilter filters notifications by time

func NewTimeFilter

func NewTimeFilter() *TimeFilter

NewTimeFilter creates a new time filter

func (*TimeFilter) Apply

func (f *TimeFilter) Apply(n *github.Notification) bool

Apply applies the time filter to a notification

func (*TimeFilter) Description

func (f *TimeFilter) Description() string

Description returns a human-readable description of the time filter

func (*TimeFilter) WithBefore

func (f *TimeFilter) WithBefore(before time.Time) *TimeFilter

WithBefore adds a before time to the filter

func (*TimeFilter) WithSince

func (f *TimeFilter) WithSince(since time.Time) *TimeFilter

WithSince adds a since time to the filter

type TypeFilter

type TypeFilter struct {
	Types []string
}

TypeFilter filters notifications by type

func NewTypeFilter

func NewTypeFilter(types ...string) *TypeFilter

NewTypeFilter creates a new type filter

func (*TypeFilter) Apply

func (f *TypeFilter) Apply(n *github.Notification) bool

Apply applies the type filter to a notification

func (*TypeFilter) Description

func (f *TypeFilter) Description() string

Description returns a human-readable description of the type filter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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