fields

package
v0.24.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 8 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 fields holds source-neutral field helpers — coalesce, fill checks, slugs, and write-payload shaping — so internal/store can use them without importing Jira types. SpecIDs exists for that reason: store coalesces on alias+ids+role only. The Jira-shaped half (catalog classify/discover, editmeta resolve) lives in internal/jirafields.

Index

Constants

View Source
const IssueKeyBare = `[A-Z][A-Z0-9]+-[0-9]+`

IssueKeyBare is the regex body of a bare Jira issue key as it appears in free text: a project key of two or more characters (a letter, then letters and digits), a hyphen, one or more digits. Unanchored on purpose — consumers add their own anchors (\b, /browse/…) and capture groups around it. Single owner of the scan body (GDK-1103): cmd/gadak's dev scan and internal/store's item-ref extraction assemble from it, so the copies cannot drift. IssueKeyLiteral above stays the anchored whole-string check and is pinned one character looser on project length (A-1 passes there, not here).

Variables

This section is empty.

Functions

func ASCIISlug

func ASCIISlug(s string) string

ASCIISlug lowercases and snake-cases the ASCII letters and digits in s, dropping everything else. Returns "" when s carries no ASCII alphanumerics, which is the signal to fall back to the field id — see SuggestAlias.

func AllASCIIDigits added in v0.22.0

func AllASCIIDigits(s string) bool

AllASCIIDigits reports whether s is one or more ASCII digits — the "the user typed a bare id, not a name" discriminator in catalog resolution (transition resolutions, edit value tokens, wiki link targets). It lived in internal/transition until GDK-688: origin and edit both need it without the write vocabulary, so it belongs with the other field-token helpers.

func BodyFieldIDs

func BodyFieldIDs(bodyFields []string, specs []config.FieldSpec) []string

BodyFieldIDs returns the union of explicit body field ids and every id on a role=body spec, de-duplicated in first-seen order.

func CanonicalKey added in v0.22.0

func CanonicalKey(s string) string

CanonicalKey is the single owner of the key-normalization composition: trim, then case-fold. Before it, eleven production sites hand-rolled strings.ToUpper(strings.TrimSpace(…)) beside the shape check, and a caller that forgot the Trim still compiled. Keys from positionals, saved views, MCP tools and paste targets come through here. Project keys share the composition (they are the ABC- half of an issue key), which is why this is not named CanonicalIssueKey. The sourcelint gate (canonical_gate_test.go) keeps new hand-rolled copies out.

func Clip added in v0.22.0

func Clip(s string, cols int) string

Clip is the single owner of "collapse whitespace, then truncate to a display width with an ellipsis" (GDK-1811). Three byte-identical copies of this body had drifted apart in comment only — cmd/gadak's clip, internal/parenthint's clip, internal/freshness's clipWidth — and the freshness copy justified itself with "package main is not importable", which was true and beside the point.

Home: this package, not internal/term. The audit round that folded the three copies was pointed at internal/term, which turned out to own PTY session handling — its OSC parsing is escape-sequence work, not display width — and importing it would have pulled creack/pty and x/sys into internal/freshness, which every MCP read touches. Lead correction, 2026-09-12; internal/fields is where this binary's width authority already lived.

Columns, not runes: a Hangul or CJK rune occupies two cells, so a rune-counted cut renders twice as wide as the same cut in ASCII — which is how a 72-"character" column landed at 144 on a Korean issue. go-runewidth is this repo's width authority; the ellipsis is one cell, and Truncate keeps the whole result inside cols.

Whitespace first, because a value that is clipped for a one-line cell is a value whose newlines and runs of spaces would break that cell anyway.

func Coalesce

func Coalesce(specs []SpecIDs, extra map[string]json.RawMessage) map[string]any

Coalesce lands the first filled value for each spec under its alias. IDs are tried in order; null/""/[]/{} are skipped.

Values are stored display-ready: body-role values keep their raw document (the detail panel renders ADF), everything else flattens to a string or a []string — filters, chips, badges and FTS all consume plain text, and the write path resolves option ids through editmeta, never through the mirror.

func CoalesceSpecs

func CoalesceSpecs(specs []config.FieldSpec, extra map[string]json.RawMessage) map[string]any

CoalesceSpecs is Coalesce over config.FieldSpec values.

func DateOnlyLiteral added in v0.17.0

func DateOnlyLiteral(s string) bool

DateOnlyLiteral is YYYY-MM-DD with month 01–12 and day 01–31. It does not parse into a timestamp — date-only values stay date-only. Single owner of the duedate / date-field literal check (GDK-619): `gadak create --due` and the server's create / update-fields endpoints import it.

func EditableAliases

func EditableAliases(cfg *config.Config) map[string]EditableAlias

EditableAliases builds the write allowlist from built-in system aliases, then Fields (Kind set), then leftover EditableFields (legacy wins on alias collision). A nil config is "no config at all" and returns empty.

func FieldIDSlug

func FieldIDSlug(fieldID string) string

FieldIDSlug turns customfield_10019 into cf_10019.

func FieldValue

func FieldValue(kind string, raw json.RawMessage) (any, error)

FieldValue shapes the client's `string | string[] | number | null` into what Jira wants for that kind. A null clears the field, which is what the editor's clear does. textarea (ADF) is not a kind here — Cloud v3 needs a separate document write.

func IsFilled

func IsFilled(raw json.RawMessage) bool

IsFilled reports whether a Jira field value counts as "set" on an issue. null, "", [], and {} are empty; 0 and false are filled (user-supplied values).

func IsFilledAny

func IsFilledAny(v any) bool

IsFilledAny reports whether a decoded JSON value counts as set (same rules as IsFilled, for values already unmarshaled into issues.custom).

func IsIssueKey added in v0.22.0

func IsIssueKey(s string) bool

IsIssueKey canonicalizes (CanonicalKey) and then checks the shape (IssueKeyLiteral) — the exact composition the "does this look like an issue key" sites used to spell by hand; cmd/gadak's looksLikeIssueKey was the first to fold.

func IsMultiKind added in v0.22.0

func IsMultiKind(kind string) bool

IsMultiKind reports whether the kind holds a list of selections. Exported so the CLI can reconcile --field arity (one value, or a repeated flag) with the field before ValueFromIDs shapes it, instead of asking again with its own list of kind names (GDK-18).

func IssueKeyLiteral added in v0.17.0

func IssueKeyLiteral(s string) bool

IssueKeyLiteral is a Jira issue key ABC-123: a project key (A–Z then A–Z0–9), a hyphen, and one or more digits. It does not trim or case-fold — canonicalization is CanonicalKey's job, and mixed-case or padded input goes through IsIssueKey rather than a hand-rolled ToUpper+Trim. Single owner of the key-shape check (GDK-328): CLI positional keys, MCP gadak_show, and the server's create / parent endpoints import it.

func NormalizeName

func NormalizeName(name string) string

NormalizeName collapses whitespace runs, trims, and lowercases for grouping fields that share a display name across board templates.

func SuggestAlias

func SuggestAlias(name, fieldID string, used map[string]bool) string

SuggestAlias proposes a stable config key for a field the config does not name yet.

The slug is ASCII-only, and a name with no ASCII letters falls back to the field id (cf_10019). Two reasons, both from the same fact: Jira returns field names in the account's own language. A Korean account calls customfield_10019 "순위" where an English one says "Rank", so a name-derived alias is not the same on two machines — and a fieldMap is exactly the thing teams share with `gadak team export`. An id-derived alias is ugly but identical everywhere.

func ValueFromIDs

func ValueFromIDs(kind string, ids []string) any

ValueFromIDs shapes selected id(s) into the Jira field payload for kind. An empty selection clears: multi kinds become []any{}, others become nil.

Types

type EditableAlias

type EditableAlias struct {
	IDs  []string
	Kind string // preferred kind from the spec when set; empty → use editmeta
}

EditableAlias maps an alias onto candidate field ids and a preferred kind. Specs with an empty Kind are display-only and do not enter the write path. Leftover EditableFields (in-memory / settings PUT that skipped LoadFor) still overlay and win on alias collision so those callers keep working.

type SpecIDs

type SpecIDs struct {
	Alias string
	IDs   []string
	Role  string
}

SpecIDs is the flat shape store and sync use to coalesce without depending on the full FieldSpec when only alias+ids+role are needed. The package boundary exists so store can import this type without pulling Jira REST types onto its graph (docs/ARCHITECTURE.md:79).

func SpecIDsFrom

func SpecIDsFrom(specs []config.FieldSpec) []SpecIDs

SpecIDsFrom projects config field specs onto the coalesce shape.

Jump to

Keyboard shortcuts

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