qualification

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package qualification provides domain types for PR qualification validation. This package contains pure domain types (value objects and enums) that represent the core concepts of PR qualification without any external dependencies.

Domain types in this package:

  • Result: Represents the outcome of a validation check
  • Severity: Indicates the severity level of validation results

These types are used throughout the qualification subsystem to communicate validation outcomes in a structured, type-safe manner.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LayoutType

type LayoutType string

LayoutType represents different repository layout patterns. It's a domain type that categorizes the organizational structure of deployment manifests in a Git repository.

cd-operator supports multiple layout conventions to accommodate different organizational standards and tooling requirements.

const (
	// LayoutStandard represents the standard layout: deployments/<app>/base/, deployments/<app>/overlays/
	// This is the conventional Kustomize-based layout used by most Kubernetes projects.
	//
	// Typical structure:
	//   deployments/
	//     myapp/
	//       base/
	//         kustomization.yaml
	//         deployment.yaml
	//       overlays/
	//         dev/
	//           kustomization.yaml
	//         prod/
	//           kustomization.yaml
	LayoutStandard LayoutType = "standard"

	// LayoutTMC represents the TMC layout: tmc/<cluster>/<app>/
	// This layout is used with Tanzu Mission Control for cluster-specific configurations.
	//
	// Typical structure:
	//   tmc/
	//     cluster-01/
	//       myapp/
	//         deployment.yaml
	//     cluster-02/
	//       myapp/
	//         deployment.yaml
	LayoutTMC LayoutType = "tmc"

	// LayoutUnknown represents an unrecognized layout pattern.
	// PRs with unknown layouts typically fail validation unless
	// configured otherwise.
	LayoutUnknown LayoutType = "unknown"
)

func (LayoutType) IsValid

func (l LayoutType) IsValid() bool

IsValid checks if the layout type is a recognized type. Only LayoutStandard and LayoutTMC are considered valid. LayoutUnknown and any other values return false.

This method is useful for validation logic that needs to ensure a layout was successfully detected.

func (LayoutType) String

func (l LayoutType) String() string

String returns the string representation of the layout type. This implements the fmt.Stringer interface for better logging and debugging.

type Result

type Result struct {
	// Valid indicates whether the validation passed
	Valid bool

	// ValidatorName is the name of the validator that produced this result
	ValidatorName string

	// Reason provides a human-readable explanation of the result
	Reason string

	// Details contains additional structured information about the validation
	Details map[string]interface{}

	// Severity indicates how critical a failure is
	Severity Severity

	// Suggestions contains actionable advice for fixing validation failures
	Suggestions []string
}

Result represents the outcome of a validation check. It contains all information needed to understand whether a validation passed or failed, why it happened, and what actions can be taken.

Results can be chained with fluent methods (WithDetails, WithSuggestion) to build rich validation feedback.

func NewFailureResult

func NewFailureResult(validatorName, reason string, severity Severity) Result

NewFailureResult creates a failed validation result. Use this constructor when a validation check fails.

Parameters:

  • validatorName: The name of the validator producing this result
  • reason: Human-readable explanation of why the validation failed
  • severity: The severity level of this failure (Error, Warning, or Info)

Returns a Result with Valid=false and the specified severity.

func NewSuccessResult

func NewSuccessResult(validatorName, reason string) Result

NewSuccessResult creates a successful validation result. Use this constructor when a validation check passes.

Parameters:

  • validatorName: The name of the validator producing this result
  • reason: Human-readable explanation of why the validation passed

Returns a Result with Valid=true and Severity=SeverityInfo.

func (Result) Error

func (r Result) Error() string

Error implements the error interface for Result when Valid is false. This allows Results to be used directly as errors in error handling flows.

func (Result) WithDetails

func (r Result) WithDetails(key string, value interface{}) Result

WithDetails adds structured details to a validation result. This method supports a fluent API for building results with rich context.

Details are stored as key-value pairs and can be used to provide machine-readable information about the validation outcome.

Example:

result := NewFailureResult("layout", "unknown layout detected", SeverityError).
    WithDetails("files_changed", 5).
    WithDetails("detected_pattern", "custom/*")

Returns a copy of the result with the new detail added.

func (Result) WithSuggestion

func (r Result) WithSuggestion(suggestion string) Result

WithSuggestion adds an actionable suggestion to a validation result. This method supports a fluent API for building results with guidance.

Suggestions provide human-readable advice on how to fix validation failures. Multiple suggestions can be added by calling this method multiple times.

Example:

result := NewFailureResult("mergeable", "PR has conflicts", SeverityError).
    WithSuggestion("Rebase your branch on the latest main").
    WithSuggestion("Resolve merge conflicts manually")

Returns a copy of the result with the new suggestion appended.

type Severity

type Severity string

Severity indicates the severity level of a validation result. It provides a way to categorize validation outcomes by their impact on the qualification decision.

const (
	// SeverityError indicates a critical failure that blocks progression.
	// PRs with error-level validation failures cannot be auto-merged.
	SeverityError Severity = "error"

	// SeverityWarning indicates a non-critical issue that allows progression.
	// PRs with warnings may still be auto-merged depending on configuration.
	SeverityWarning Severity = "warning"

	// SeverityInfo indicates informational feedback.
	// Info-level results are used for successful validations or
	// non-blocking informational messages.
	SeverityInfo Severity = "info"
)

Jump to

Keyboard shortcuts

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