fields

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

This section is empty.

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 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 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 DisplayValue

func DisplayValue(v any) any

DisplayValue flattens a raw Jira field value onto display text: option `{value}`, version/component `{name}`, user `{displayName}` become their string; arrays flatten element-wise; scalars pass through unchanged.

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 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 — callers that accept mixed-case input ToUpper+Trim first (looksLikeIssueKey, gadak_show issue). 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