Documentation
¶
Overview ¶
Package fields classifies and discovers Jira custom fields for the mirror. Pure functions only — no network, no database.
Index ¶
- func ASCIISlug(s string) string
- func BodyFieldIDs(bodyFields []string, specs []config.FieldSpec) []string
- func Classify(f jira.FieldInfo) (role, kind string, ok bool)
- func Coalesce(specs []SpecIDs, extra map[string]json.RawMessage) map[string]any
- func CoalesceSpecs(specs []config.FieldSpec, extra map[string]json.RawMessage) map[string]any
- func Discover(catalog []jira.FieldInfo, fill map[string]int, prior []config.FieldSpec) []config.FieldSpec
- func DisplayValue(v any) any
- func EditKind(m jira.FieldMeta) string
- func EditableAliases(cfg *config.Config) map[string]EditableAlias
- func FieldIDSlug(fieldID string) string
- func FieldValue(kind string, raw json.RawMessage) (any, error)
- func IsFilled(raw json.RawMessage) bool
- func IsFilledAny(v any) bool
- func NormalizeName(name string) string
- func ResolveEditableID(candidates []string, meta map[string]jira.FieldMeta) (id, kind string, ok bool)
- func SuggestAlias(name, fieldID string, used map[string]bool) string
- func ValueFromIDs(kind string, ids []string) any
- type EditableAlias
- type SpecIDs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ASCIISlug ¶
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 ¶
BodyFieldIDs returns the union of explicit body field ids and every id on a role=body spec, de-duplicated in first-seen order.
func Classify ¶
Classify maps a Jira field schema onto a display role and editor kind. ok=false marks fields gadak should never surface (plugin plumbing, ranks).
func Coalesce ¶
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 ¶
CoalesceSpecs is Coalesce over config.FieldSpec values.
func Discover ¶
func Discover(catalog []jira.FieldInfo, fill map[string]int, prior []config.FieldSpec) []config.FieldSpec
Discover groups the custom-field catalog by normalized display name, keeps the groups the mirror has actually seen filled, and returns specs ordered by total fill count descending. Prior Auto:false specs are preserved; Auto:true prior entries donate aliases for stability.
func DisplayValue ¶
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 EditKind ¶
EditKind maps a Jira field schema onto the editors the UI has. A field whose schema is none of them has no editor and is left out of editmeta.
func EditableAliases ¶
func EditableAliases(cfg *config.Config) map[string]EditableAlias
EditableAliases builds the write allowlist from Fields (Kind set) plus leftover EditableFields (legacy wins on alias collision).
func FieldIDSlug ¶
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[] | null` into what Jira wants for that kind. A null clears the field, which is what the editor's clear does.
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 ¶
IsFilledAny reports whether a decoded JSON value counts as set (same rules as IsFilled, for values already unmarshaled into issues.custom).
func NormalizeName ¶
NormalizeName collapses whitespace runs, trims, and lowercases for grouping fields that share a display name across board templates.
func ResolveEditableID ¶
func ResolveEditableID(candidates []string, meta map[string]jira.FieldMeta) (id, kind string, ok bool)
ResolveEditableID picks the first candidate id present in editmeta.
func SuggestAlias ¶
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 ¶
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 ¶
SpecIDs is the flat shape store and sync use to coalesce without depending on the full FieldSpec when only alias+ids+role are needed.
func SpecIDsFrom ¶
SpecIDsFrom projects config field specs onto the coalesce shape.