fields

package
v0.13.0 Latest Latest
Warning

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

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

Documentation

Overview

Package fields classifies and discovers Jira custom fields for the mirror. Pure functions only — no network, no database.

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 Classify

func Classify(f jira.FieldInfo) (role, kind string, ok bool)

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

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

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 EditKind

func EditKind(m jira.FieldMeta) string

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 FieldSpecs (Kind set) plus legacy EditableFields (legacy wins on alias collision).

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[] | 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

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

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. Legacy EditableFields win over FieldSpecs for the same alias; specs with an empty Kind are display-only and do not enter the write path.

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.

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