sonarinternal

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package sonarinternal holds helpers shared by `krci sonar` verbs (validation, enum sets, render/format dispatch, error-envelope plumbing). Placed under an `internal/` directory so Go enforces package visibility: only packages below `pkg/cmd/sonar/` may import it.

Index

Constants

View Source
const MaxPageSize = 500

MaxPageSize is the upper bound on `--page-size` for every paginated sonar verb, mirroring the shared Zod schema cap on portal-side.

View Source
const SchemaVersion = "1"

SchemaVersion is the shared JSON envelope version for every `krci sonar *` verb. Bump only when the envelope shape changes in a way scripting consumers must detect (e.g. removal of a previously-required key).

Variables

View Source
var (
	IssueTypes      = newEnumSet("BUG", "VULNERABILITY", "CODE_SMELL")
	IssueSeverities = newEnumSet("BLOCKER", "CRITICAL", "MAJOR", "MINOR", "INFO")
	IssueStatuses   = newEnumSet("OPEN", "CONFIRMED", "REOPENED", "RESOLVED", "CLOSED")
)

Canonical SonarQube enum sets. Keep in sync with the Portal's shared SonarQube schema.

Functions

func HandleError

func HandleError(ios *iostreams.IOStreams, outputFormat string, err error) error

HandleError promotes portal.ErrUnauthorized to the shared "run krci auth login" message, and — when `-o json` is selected — also writes the `{schemaVersion, error: { message }}` envelope to stdout so scripting consumers get a structured error alongside the exit-1 signal. Callers still return the returned error so root-level main.go emits the plain-text form on stderr and exits 1.

func PageCount

func PageCount(total, pageSize int) int

PageCount returns the number of pages of pageSize required to hold total items. Always returns at least 1 so footers never read "page 1 of 0".

func PrintTable

func PrintTable(w io.Writer, isTTY bool, headers []string, rows [][]string) error

PrintTable is the shared TTY/non-TTY dispatcher for sonar verbs that show a plain 2D table. Styled output for interactive terminals, plain tabwriter output when stdout is piped.

func Render

func Render[T any](ios *iostreams.IOStreams, outputFormat string, data T, renderTable TableRenderer) error

Render dispatches on the `-o` flag: emit the shared `{schemaVersion, data}` JSON envelope for `-o json`, invoke the supplied TableRenderer for `-o table` (the default), or return a validation error for anything else.

func ValidateEnumCSV

func ValidateEnumCSV(flagName string, values []string, allowed EnumSet) ([]string, error)

ValidateEnumCSV checks every comma-separated/repeated value in values against allowed. flagName is used in error messages. Returns the flattened list of validated items in input order with duplicates collapsed (empty when values is empty).

func ValidateOutputFormat

func ValidateOutputFormat(format string) error

ValidateOutputFormat rejects `-o` values other than "", "table", or "json". An empty string means "use default" (table) and is always valid.

func ValidateProjectCommand

func ValidateProjectCommand(cmd *cobra.Command, outputFormat, project, pullRequest string) error

ValidateProjectCommand runs the standard validator triple used by the three project-scoped verbs (get, gate, issues): output format → DNS-1123 project key → non-empty --pull-request (when supplied).

func ValidateProjectKey

func ValidateProjectKey(project string) error

ValidateProjectKey returns an error when project does not match DNS-1123. Codebase names (by Portal convention, also the SonarQube projectKey) follow the same shape as Kubernetes namespaces — see internal/cmdutil/validate.go.

func ValidatePullRequest

func ValidatePullRequest(changed bool, value string) error

ValidatePullRequest rejects an explicitly supplied empty --pull-request value. changed is true when the flag was set on the command line (regardless of value).

Types

type EnumSet

type EnumSet struct {
	Values []string
	// contains filtered or unexported fields
}

EnumSet pairs the canonical list and lookup map for a SonarQube enum. Callers treat both fields as read-only.

type TableRenderer

type TableRenderer func(w io.Writer, isTTY bool) error

TableRenderer emits the table/text view of a sonar verb's payload. The callback receives the output writer and the TTY state so it can apply styling or truncation conditionally.

Jump to

Keyboard shortcuts

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