validation

package
v0.54.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NamedRoles = []string{"crew", "polecat"}

NamedRoles are agent roles that include a worker name

View Source
var RigLevelRoles = []string{"witness", "refinery"}

RigLevelRoles are agent roles that have a rig but no name

View Source
var TownLevelRoles = []string{"mayor", "deacon"}

TownLevelRoles are agent roles that don't have a rig

View Source
var ValidAgentRoles = []string{
	"mayor",
	"deacon",
	"witness",
	"refinery",
	"crew",
	"polecat",
}

ValidAgentRoles are the known agent role types for ID pattern validation

Functions

func LintIssue

func LintIssue(issue *types.Issue) error

LintIssue checks an existing issue for missing template sections. Unlike ValidateTemplate, this operates on a full Issue struct. Returns nil if the issue passes validation or has no requirements.

func ParseIssueType

func ParseIssueType(content string) (types.IssueType, error)

ParseIssueType extracts and validates an issue type from content. Returns the validated type or error if invalid.

func ParsePriority

func ParsePriority(content string) int

ParsePriority extracts and validates a priority value from content. Supports both numeric (0-4) and P-prefix format (P0-P4). Returns the parsed priority (0-4) or -1 if invalid.

func ValidateAgentID

func ValidateAgentID(id string) error

ValidateAgentID validates that an agent ID follows the expected pattern. Canonical format: prefix-rig-role-name Patterns:

  • Town-level: <prefix>-<role> (e.g., gt-mayor, bd-deacon)
  • Per-rig singleton: <prefix>-<rig>-<role> (e.g., gt-gastown-witness)
  • Per-rig named: <prefix>-<rig>-<role>-<name> (e.g., gt-gastown-polecat-nux)

The prefix can be any rig's configured prefix (gt-, bd-, etc.). Rig names may contain hyphens (e.g., my-project), so we parse by scanning for known role tokens from the right side of the ID. Returns nil if the ID is valid, or an error describing the issue.

func ValidateIDFormat

func ValidateIDFormat(id string) (string, error)

ValidateIDFormat validates that an ID has the correct format. Supports: prefix-number (bd-42), prefix-hash (bd-a3f8e9), or hierarchical (bd-a3f8e9.1) Returns the prefix part or an error if invalid.

func ValidatePrefix

func ValidatePrefix(requestedPrefix, dbPrefix string, force bool) error

ValidatePrefix checks that the requested prefix matches the database prefix. Returns an error if they don't match (unless force is true).

func ValidatePrefixWithAllowed

func ValidatePrefixWithAllowed(requestedPrefix, dbPrefix, allowedPrefixes string, force bool) error

ValidatePrefixWithAllowed checks that the requested prefix is allowed. It matches if: - force is true - dbPrefix is empty - requestedPrefix matches dbPrefix - requestedPrefix is in the comma-separated allowedPrefixes list Returns an error if none of these conditions are met.

func ValidatePriority

func ValidatePriority(priorityStr string) (int, error)

ValidatePriority parses and validates a priority string. Returns the parsed priority (0-4) or an error if invalid. Supports both numeric (0-4) and P-prefix format (P0-P4).

func ValidateTemplate

func ValidateTemplate(issueType types.IssueType, description string) error

ValidateTemplate checks if the description contains all required sections for the given issue type. Returns nil if validation passes or if the issue type has no required sections.

Section matching is case-insensitive and looks for the heading text anywhere in the description (doesn't require exact markdown format).

Types

type IssueValidator

type IssueValidator func(id string, issue *types.Issue) error

IssueValidator validates an issue and returns an error if validation fails. Validators can be composed using Chain() for complex validation logic.

func Chain

func Chain(validators ...IssueValidator) IssueValidator

Chain composes multiple validators into a single validator. Validators are executed in order and the first error stops the chain.

func Exists

func Exists() IssueValidator

Exists validates that an issue is not nil.

func ForClose

func ForClose(force bool) IssueValidator

ForClose returns a validator chain for close operations. Validates: issue exists, is not a template, and is not pinned (unless force).

func ForDelete

func ForDelete() IssueValidator

ForDelete returns a validator chain for delete operations. Validates: issue exists and is not a template.

func ForReopen

func ForReopen() IssueValidator

ForReopen returns a validator chain for reopen operations. Validates: issue exists, is not a template, and is closed.

func ForUpdate

func ForUpdate() IssueValidator

ForUpdate returns a validator chain for update operations. Validates: issue exists and is not a template.

func HasStatus

func HasStatus(allowed ...types.Status) IssueValidator

HasStatus validates that an issue has one of the allowed statuses.

func HasType

func HasType(allowed ...types.IssueType) IssueValidator

HasType validates that an issue has one of the allowed types.

func NotClosed

func NotClosed() IssueValidator

NotClosed validates that an issue is not already closed.

func NotHooked

func NotHooked(force bool) IssueValidator

NotHooked validates that an issue is not in hooked status.

func NotPinned

func NotPinned(force bool) IssueValidator

NotPinned validates that an issue is not pinned. Returns an error if the issue is pinned, unless force is true.

func NotTemplate

func NotTemplate() IssueValidator

NotTemplate validates that an issue is not a template. Templates are read-only and cannot be modified.

type MissingSection

type MissingSection struct {
	Heading string // The expected heading, e.g., "## Steps to Reproduce"
	Hint    string // Guidance for what to include
}

MissingSection describes a section that should be present but isn't.

type TemplateError

type TemplateError struct {
	IssueType types.IssueType
	Missing   []MissingSection
}

TemplateError is returned when template validation fails. It contains all missing sections for a single error report.

func (*TemplateError) Error

func (e *TemplateError) Error() string

Jump to

Keyboard shortcuts

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