prfilter

package
v0.2.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 9 Imported by: 0

README

prfilter

The pull-request filter language in Go: repo=acme/app is!=draft (review=approved OR risk>=4) flaky. It parses a query (Parse, Problem), tests index entries against it (Compile, Matches) and folds an inbox's parts into one query (FoldedQuery), so the daemon can match inboxes as the app does.

The TypeScript parser in app/src/pr-filter.ts (with foldedQuery in app/src/inboxes.ts) is the twin of this package. Error messages, matching and folding must be identical. testdata/cases.json holds the shared cases: this package's tests and app/src/pr-filter-fixtures.test.ts both run every one. A change to the language changes both implementations and the fixtures; regenerate the expected values from the TypeScript side and check the Go side agrees.

Documentation

Overview

Package prfilter reads and applies the pull-request filter language, such as `repo=acme/app is!=draft (review=approved OR risk>=4) flaky`. It is the Go twin of app/src/pr-filter.ts: the two must agree, and the shared testdata/cases.json keeps them so.

Index

Constants

View Source
const (
	KindAnd  = "and"
	KindOr   = "or"
	KindNot  = "not"
	KindTerm = "term"
	KindText = "text"
)

Expr kinds.

View Source
const MaxQuery = 500

MaxQuery is the longest query, in UTF-16 units as JavaScript counts them.

Variables

This section is empty.

Functions

func FoldedQuery

func FoldedQuery(p Parts) string

FoldedQuery is an inbox's parts as one query: what it holds (waiting= or, for the person's own, author=@me), owners (org=), risk (risk>=), repositories (repo=) and bots (is!=bot), then its own query.

func Matches

func Matches(query string, e reviewindex.Entry, kind string) bool

Matches reports whether the pull request passes the query.

func Problem

func Problem(query string) string

Problem says why the query cannot be saved: it does not read, or is longer than the daemon keeps. "" when it can.

Types

type Expr

type Expr = *Node

Expr is a parsed filter; nil is the empty filter.

func Parse

func Parse(query string) (Expr, error)

Parse reads a query. A nil Expr and nil error mean an empty query; an error carries the same message as the TypeScript parser's. The result is shared and must not be changed.

type Matcher

type Matcher func(e reviewindex.Entry, kind string) bool

Matcher reports whether a pull request passes a compiled query; kind is what it waits for in an inbox's queue ("" for none, where waiting holds for nothing).

func Compile

func Compile(query string) Matcher

Compile parses the query once. A query that cannot be read, or an empty one, narrows nothing.

type Node

type Node struct {
	Kind string
	// Items are the operands of an and/or; Item is the operand of a not.
	Items []Expr
	Item  Expr
	// A term's field, operator and values.
	Key    string
	Op     string
	Values []string
	// Text is the word a text expression looks for.
	Text string
	// Grouped is set on an expression written in parentheses of its own.
	Grouped bool
}

Node is a parsed filter expression.

type Parts

type Parts struct {
	What         string
	Owners       []string
	Risk         string
	Repositories []string
	Query        string
	NoBots       bool
}

Parts are the fields of an inbox that FoldedQuery folds into one query.

Jump to

Keyboard shortcuts

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