profile

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 32 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package profile composes the reviewer's guide from blocks: the loop's bundled ones, then the user's profile, each addressed by a path of the conditions under which it applies.

Index

Constants

View Source
const (
	Applies    = "applies"
	NeedsBrief = "needs the brief"
	Trimmed    = "dropped: over the judgment limit"
	Overridden = "replaced by an override"
	Depends    = "depends on the pull request"
	Elsewhere  = "not in this repository"
)
View Source
const (
	PluginProfileDir = "profile"
	PluginsDir       = "plugins"
)

PluginProfileDir is a plugin directory's profile layer, and PluginsDir the directory of a user profile that holds the user's layer of each plugin, by id.

View Source
const (
	PartialsDir = "partials"
	PromptsDir  = "prompts"
)

The profile directories whose files resolve through the layers, a file of a higher layer replacing the bundled file of the same path: the text agents read around an intent's instructions, and the prompts of the loop's own calls.

View Source
const (
	BlockMax    = 16 << 10
	JudgmentMax = 48 << 10
	IncludeMax  = 8
)
View Source
const LabelsFile = "labels.toml"

LabelsFile is the profile file that names the headings of a block's conditions.

View Source
const LocalesDir = "locales"

LocalesDir holds a layer's translations, locales/<tag>/<rel> mirroring each localizable file rel.

Variables

View Source
var Aliases = []Alias{
	{DimOrganization, "pr.owner"},
	{DimRepo, "pr.repo_name"},
	{DimUser, "pr.author"},
	{DimTeam, "pr.requested_teams"},
	{DimAssociation, "pr.association"},
	{DimLabel, "pr.labels"},
	{DimBase, "pr.base"},
	{DimStage, "turn.stage"},
	{DimReviewer, "pr.address.reviewers"},
	{DimKind, "brief.kind"},
	{DimSize, "brief.size"},
	{DimRisk, "brief.risk"},
}

Aliases are the dimensions of today's block paths, in their rank.

View Source
var Dims = func() []Dim {
	out := make([]Dim, len(Aliases))
	for i, a := range Aliases {
		out[i] = a.Dim
	}
	return out
}()

Dims lists the aliased dimensions in their canonical order.

Functions

func Apply

func Apply(dir string, changes []Change, backup func(path string, raw []byte) (string, error), intents *dintent.Registry, broken []dintent.Name) error

Apply writes changes to the layer at dir, then loads it; when it no longer loads, every file gets its previous bytes back and the load error is returned. backup, when not nil, keeps a copy of each file it overwrites or renames.

func BundledSHA

func BundledSHA(kind Kind) string

BundledSHA hashes the bundled guide of kind, to tell when a new version changed a guide a profile replaces.

func Conditions

func Conditions(p BlockPath, paths []string) string

Conditions says in words when a block of p applies, with the paths its front matter asks for.

func Diff

func Diff(c Change) string

Diff is c as a unified diff, from /dev/null for a new file.

func DimsOf

func DimsOf(intents *dintent.Registry, kind Kind) []string

DimsOf are the gated dimensions valid under kind: those the manifests of its intents list.

func Files added in v0.2.0

func Files(layers []Layer, dir string) (map[string]Resolved, error)

Files are the files under dir, a slash path such as partials, resolved through layers, by their path relative to the profile.

func NormalizeTag

func NormalizeTag(kv string) (string, error)

NormalizeTag reads a key=value tag as its one spelling, key:value.

func PathOf

func PathOf(p BlockPath, intents *dintent.Registry) (string, error)

PathOf writes p's canonical path, the one ParsePath reads back as p.

func PluginLayer added in v0.3.0

func PluginLayer(id string) string

PluginLayer is the name of plugin id's own layer.

func ReadDir added in v0.3.0

func ReadDir(l Layer, dir string) ([]fs.DirEntry, error)

ReadDir lists dir, a slash path, of l; a layer without dir has no entries.

func Splice added in v0.4.0

func Splice(src []byte, values map[string]string) ([]byte, error)

Splice is the TOML document src with each string value at a key of values (its path's segments joined by "\x00") replaced, every other byte and every line number kept.

func UseBundledPlugins added in v0.3.0

func UseBundledPlugins(ps []PluginFS)

UseBundledPlugins makes ps the layers the binary bundles, which Chain adds for an enabled plugin whose directory holds no layer or that no directory on disk holds. It is set once, before the profile loads.

func UsePlugins added in v0.3.0

func UsePlugins(ps []PluginDir)

UsePlugins makes ps the plugins whose layers Chain adds. The composition root sets it once, after it discovers the plugins and before the profile loads.

Types

type Addition

type Addition struct {
	Intents []Kind
	Path    BlockPath
	// Section names the "## " heading the text goes under; "" appends at the end.
	Section  string
	Title    string
	Override bool
	Paths    []string
	Text     string
}

Addition is a rule to put in the block of each of Intents at Path.

func (Addition) Plan

func (a Addition) Plan(dir string, intents *dintent.Registry) ([]Change, error)

Plan gives the change to each intent's block in the layer at dir; nothing is written.

type Alias added in v0.2.0

type Alias struct {
	Dim  Dim
	Fact string
}

Alias binds one of today's dimension names to the fact it reads.

type Block

type Block struct {
	Layer Layer
	// File is the block's full path, or "embedded <rel>" in the bundled layer.
	File     string
	Path     BlockPath
	FM       FrontMatter
	Text     string
	Includes []Include
}

func (Block) Rel

func (b Block) Rel() string

Rel is the block's path relative to its layer.

type BlockPath

type BlockPath struct {
	Conds  []Cond
	Tags   []string
	Intent Kind
}

BlockPath is where a block sits in a layer: its conditions in canonical order, its tags as key:value sorted, and its intent.

func ParsePath

func ParsePath(rel string, intents *dintent.Registry) (p BlockPath, ok bool, err error)

ParsePath reads rel, a slash-separated path relative to a layer's directory, against the intents of the registry. ok is false for a file that is not a block; err names a file that claims to be one and breaks the grammar.

func (BlockPath) Root

func (p BlockPath) Root() bool

Root says the block has no condition, so it applies to every pull request.

type Change

type Change struct {
	File, Rel     string
	Before, After []byte
	// From is the old relative path of a rename, "" otherwise.
	From string
}

type Cond

type Cond struct {
	Dim   Dim
	Value string
}

type Dim

type Dim string
const (
	DimOrganization Dim = "organization"
	DimRepo         Dim = "repo"
	DimUser         Dim = "user"
	DimTeam         Dim = "team"
	DimAssociation  Dim = "association"
	DimLabel        Dim = "label"
	DimBase         Dim = "base"
	DimStage        Dim = dintent.DimStage
	DimReviewer     Dim = dintent.DimReviewer
	DimKind         Dim = "kind"
	DimSize         Dim = "size"
	DimRisk         Dim = "risk"
)

type DimDef added in v0.2.0

type DimDef struct {
	Name Dim
	Fact string
	// Providers are those whose intents a block may name the dim under;
	// nil for every provider.
	Providers []unit.ProviderID
	Closed    map[unit.ProviderID][]string
	// List says the fact is a list, which a condition matches by one element.
	List bool
	// Brief says the value comes from the brief: a turn without one skips the block.
	Brief bool
	// Gated says only an intent whose manifest's dims list it may name it.
	Gated bool
	// Extra is the name of the brief intent's extra field the dim reads; ""
	// for a fact of the table.
	Extra string
}

DimDef is a block path condition: an alias, a fact flagged dim, or an enum field of a brief intent's extra.

func Vocabulary added in v0.2.0

func Vocabulary(intents *dintent.Registry) []DimDef

Vocabulary is every dimension a block path may name for the intents of the registry: the aliases in their rank, then the facts flagged dim and the brief intents' enum extras, by name.

type Facts

type Facts struct {
	Values      map[string]any
	Tags, Files []string
	HasBrief    bool
}

Facts are what a block's conditions are matched against. Values are the facts the dimensions read, by fact name, each a string or a []string. Tags (key:value) and Files come from the brief; they, and the values of brief facts, count only when HasBrief is true.

type FrontMatter

type FrontMatter struct {
	Override bool
	Title    string
	// Include lists files relative to the block's file.
	Include []string
	// Paths are globs, ** allowed, one of which a changed file must match.
	Paths     []string
	Delegates map[string][]string
}

type FrontMatterError

type FrontMatterError struct {
	File, Key, Problem string
	Line, Col          int
}

FrontMatterError carries Line and Col (1-based) when the problem has a position in the file.

func (FrontMatterError) Error

func (e FrontMatterError) Error() string

type Guide

type Guide struct {
	Kind  Kind
	Parts []Part
	// Delegates come from the last part that declares them.
	Delegates     map[string][]string
	DelegatesFrom string
	// Skipped lists, as "<layer>: <file>", the blocks that need a brief the
	// pull request does not have.
	Skipped []string
	// Dropped lists the blocks left out to keep the judgment within JudgmentMax.
	Dropped []string
}

func (Guide) Sources

func (g Guide) Sources() []string

Sources lists one "<layer>: <file>" per part, in the text's order.

type Guides

type Guides struct {
	Tree func() (Tree, error)
}

Guides composes the guide of a pull request from a profile tree read once for the registry in force.

func (Guides) Check

func (g Guides) Check() error

Check reports the error of reading the tree, so a broken block stops a round before anything is touched for it.

func (Guides) Guide

func (g Guides) Guide(kind Kind, f Facts) (Guide, error)

type Include

type Include struct{ Name, Text string }

type Kind

type Kind string

Kind is an intent with judgment blocks, the profile a manifest names.

func Kinds

func Kinds(intents *dintent.Registry) []Kind

Kinds lists the intents a block can be written for: every profile an intent of the registry names, sorted.

type Labels added in v0.2.0

type Labels struct {
	Other  string            `toml:"other"`
	Tag    string            `toml:"tag"`
	Dims   map[string]string `toml:"dims"`
	Values map[string]string `toml:"values"`
}

Labels are the headings of a block's conditions, as labels.toml writes them.

func LoadLabels added in v0.2.0

func LoadLabels(chain []Layer, vocab []DimDef) (Labels, error)

LoadLabels reads labels.toml from each layer of chain, a higher layer's keys replacing a lower one's; a heading names a dimension of vocab.

type Layer

type Layer struct {
	// Name is bundled, user, or plugin:<id> and user:<id> for a plugin's
	// layer and the user's over it.
	Name string
	// Source is "embedded" for the bundled layer, the path in the binary
	// for a layer FS holds, else Dir.
	Source string
	// Dir is the directory of a layer on disk, "" for a layer the binary
	// holds.
	Dir string
	// FS holds a plugin's layer the binary bundles; nil for the bundled
	// layer and a layer on disk.
	FS fs.FS
}

func BundledChain added in v0.3.0

func BundledChain() []Layer

BundledChain is the profile the release ships: the bundled layer and the layer of every plugin the binary bundles.

func Chain

func Chain(cfg config.Config) []Layer

Chain is the bundled layer, the profile layer of each enabled plugin, the user's profile when one is set, then the user's plugins/<id>/ of each enabled plugin. A plugin's layer is its directory's profile/, else the one the binary bundles for it. A disabled plugin's layers are left out.

func EveryPlugin added in v0.4.0

func EveryPlugin(cfg config.Config) []Layer

EveryPlugin is Chain with every installed and bundled plugin's layers, enabled or not.

func (Layer) Bundled added in v0.3.0

func (l Layer) Bundled() bool

Bundled says whether l is the bundled layer, which every reader takes from the embedded default profile.

func (Layer) Embedded added in v0.3.0

func (l Layer) Embedded() bool

Embedded says whether the binary holds l: the bundled layer or a bundled plugin's.

func (Layer) FSys added in v0.3.0

func (l Layer) FSys() (fs.FS, error)

FSys is the files of l, relative to the layer.

func (Layer) FileName added in v0.3.0

func (l Layer) FileName(rel string) string

FileName is where rel, a slash path, is in l, as a problem names it: a path on disk for a layer on disk, else its path in the binary.

func (Layer) Plugin added in v0.3.0

func (l Layer) Plugin() bool

Plugin says whether l is a plugin's own layer, not the user's over it.

func (Layer) PluginID added in v0.4.0

func (l Layer) PluginID() string

PluginID is the plugin whose words l holds: its own layer's or the user's layer of it; "" for any other.

type Listed

type Listed struct {
	Block      Block
	Conditions string
	State      string
}

Listed is a block of the tree with its conditions in words and what it does for a pull request with given facts.

type MissingError

type MissingError struct{ Layer, Dir string }

func (MissingError) Error

func (e MissingError) Error() string

type Part

type Part struct {
	Layer Layer
	File  string
	// Path is the block's path relative to its layer.
	Path     string
	Label    string
	Level    int
	Override bool
	Text     string
}

type PathError

type PathError struct{ File, Problem, Fix string }

func (PathError) Error

func (e PathError) Error() string

type PluginDir added in v0.3.0

type PluginDir struct {
	ID, Dir string
}

PluginDir is a plugin's directory, which holds its profile layer.

type PluginFS added in v0.3.0

type PluginFS struct {
	ID, Source string
	FS         fs.FS
}

PluginFS is the profile layer the binary bundles for a plugin; Source is its path in the binary.

type Problems added in v0.4.0

type Problems []TextProblem

Problems are the TextProblems of a localization.

type Resolved added in v0.2.0

type Resolved struct {
	// Layer is the layer the file came from; Path is where it is, as
	// Layer.FileName names it.
	Layer Layer
	Path  string
	Body  []byte
	// Locale is the locale of the locales/<tag>/ mirror Texts served; "" for the file itself.
	Locale string
}

Resolved is a profile file as the layers resolve it.

func ReadFile added in v0.3.0

func ReadFile(l Layer, rel string) (Resolved, error)

ReadFile reads rel, a slash path, from l. An error wraps fs.ErrNotExist when l does not hold it.

func Resolve added in v0.2.0

func Resolve(layers []Layer, rel string) (Resolved, error)

Resolve reads rel, a slash path such as partials/record.md.tmpl, from the last of layers that holds it, the bundled layer reading the embedded profile. An error wraps fs.ErrNotExist when no layer holds it.

type SizeError

type SizeError struct {
	File string
	Size int
}

func (SizeError) Error

func (e SizeError) Error() string

type TextKeys added in v0.4.0

type TextKeys func(rel string, path []string) bool

TextKeys says whether the key at path of profile file rel holds a text a person reads.

type TextProblem added in v0.4.0

type TextProblem struct{ File, Key, Msg string }

TextProblem is a locale file's key Texts refuses.

type Texts added in v0.4.0

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

Texts resolves the texts a person reads, per key and per locale, across a profile's layers.

For each text the walk goes from the highest layer down: a layer that holds the text in the locale wins; a layer whose English text differs from the one below it wins with that text; the bottom layer ends with its locale text, else its English one. The keys of a plugin's file Localize reads in its own layer or in the user's layer of it walk only the layers of no plugin and that plugin's: plugins share file names such as ui.toml, never texts. Every other read, Text, Forms and the whole files, walks every layer.

func NewTexts added in v0.4.0

func NewTexts(layers []Layer, bundled fs.FS, locale string, keys TextKeys) *Texts

NewTexts resolves the texts keys names across layers, the bundled layer reading bundled, in locale.

func (*Texts) Available added in v0.4.0

func (t *Texts) Available() []string

Available are "en" and every locale any layer holds a locales/<tag>/ directory of.

func (*Texts) File added in v0.4.0

func (t *Texts) File(rel string) (Resolved, error)

File is the whole-file text rel in t's locale, by the same rule.

func (*Texts) FileAt added in v0.4.0

func (t *Texts) FileAt(l Layer, rel string) (Resolved, error)

FileAt is File as layer l's level reads it, the way Localize reads a key. A whole-file text lives under its workflow's directory, whose name no two plugins share, so the walk reads every layer, whatever plugin l is.

func (*Texts) Forms added in v0.4.0

func (t *Texts) Forms(rel string, path []string) (map[string]string, bool)

Forms is the text at path of rel in t's locale as its CLDR plural forms, by the layer rule, the whole text resolved as one: a translation may name forms its English text has not, or be plural where the English text is a string; false when no layer holds it.

func (*Texts) Locale added in v0.4.0

func (t *Texts) Locale() string

Locale is the locale t resolves texts in.

func (*Texts) Localize added in v0.4.0

func (t *Texts) Localize(l Layer, rel string, src []byte) ([]byte, Problems)

Localize is src, layer l's file rel, with each text key's value replaced by the text l's level resolves to: the layer rule over l and the layers below it, and the translations of the layers above it for the texts they hold no English of. Its problems are those of rel's locale files in every layer, reported by the first of Localize and Problems to read rel.

func (*Texts) PluginForms added in v0.4.0

func (t *Texts) PluginForms(id, rel string, path []string) (map[string]string, bool)

PluginForms is Forms of plugin id's file rel, walking only the layers of no plugin and of id.

func (*Texts) Problems added in v0.4.0

func (t *Texts) Problems(rel string) Problems

Problems are the problems of rel's locale files in every layer, the first time any read of t asks for them; nil after.

func (*Texts) Text added in v0.4.0

func (t *Texts) Text(rel string, path []string) (string, bool)

Text is the text at path of rel in t's locale, by the layer rule; false when no layer holds it.

func (*Texts) Translates added in v0.4.0

func (t *Texts) Translates() bool

Translates says whether some layer holds texts in t's locale, or in the one nearest it; when false every text reads as its layers write it.

type Tree

type Tree struct {
	Chain  []Layer
	Blocks []Block
	// Labels are the headings of the blocks' conditions; Dims what their
	// conditions may name. Load fills both; a tree built without them
	// reads the bundled labels and the dimensions of no brief intent.
	Labels *Labels
	Dims   []DimDef
}

func Load

func Load(chain []Layer, intents *dintent.Registry, broken []dintent.Name) (Tree, error)

Load reads and checks every block of the chain's layers, lowest layer first; intents are the registry blocks are written for, loaded first. Blocks of a broken intent are skipped, so its manifest's problems stay its own.

func (Tree) Compose

func (t Tree) Compose(kind Kind, f Facts) Guide

Compose matches the blocks of kind against f and puts them in the text's order: depth first through the tree of paths, a node's own blocks (lower layer first) before its children by dimension rank and value, tags last. An override drops the blocks before it whose path is an ancestor of its own. Over JudgmentMax, blocks other than the root ones are dropped from the end.

func (Tree) List

func (t Tree) List(kind Kind, f Facts) []Listed

List gives every block of kind, in the tree's order, with what it does for a pull request with facts f.

Jump to

Keyboard shortcuts

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