markdown

package
v0.12.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const FieldValuesFileName = ".jira-field-values.json"

FieldValuesFileName is the conventional name for the sidecar file.

Variables

This section is empty.

Functions

func ExtractObjectDisplay

func ExtractObjectDisplay(raw json.RawMessage) (string, bool)

ExtractObjectDisplay extracts a display value from a JSON object field value. Returns the display string and true if the value is an object with a .value or .name key. Returns "", false for non-objects, nil, or objects without displayable keys.

func IsBuiltinKey

func IsBuiltinKey(key string) bool

IsBuiltinKey returns true if key is a reserved frontmatter key.

func IsTempKey

func IsTempKey(key string) bool

IsTempKey returns true if the given key matches the temp key pattern.

func IssuePath

func IssuePath(issue api.Issue, flat bool) string

IssuePath returns the relative file path for an issue markdown file. Format: {ProjectKey}/{IssueKey} - {SanitizedSummary}.md If Project is nil, the project key is extracted from the issue key prefix. When flat is true, the project key directory prefix is omitted.

func IssueTreePath

func IssueTreePath(issue api.Issue, flat bool) string

IssueTreePath returns the relative file path for an issue in tree mode. Epics become directories containing _epic.md; children of any parent are placed inside the parent's directory. Orphans stay flat. When flat is true, the project key directory prefix is omitted.

func NormalizeFieldName

func NormalizeFieldName(displayName string) string

NormalizeFieldName converts a Jira field display name to a YAML-safe key. It lowercases, replaces spaces with underscores, and strips all characters not in [a-z0-9_]. Returns empty string if nothing remains.

func SanitizeFilename

func SanitizeFilename(name string) string

SanitizeFilename replaces characters that are invalid in file names, collapses multiple spaces, trims whitespace, and enforces a max length of 100 chars.

func SaveFieldValues

func SaveFieldValues(path string, fvm FieldValueMap) error

SaveFieldValues writes a FieldValueMap to the given path atomically.

func SplitFrontmatter

func SplitFrontmatter(content, path string) (yamlContent, body string, err error)

SplitFrontmatter splits a markdown file's content into its YAML frontmatter and body. It returns the raw YAML (between the --- delimiters) and the trimmed body that follows. Returns a VALIDATION_ERROR CLIError if the delimiters are missing. Exported so callers that map non-standard frontmatter (see the mapping package) can reuse the exact same splitting rules as ParseFile.

Types

type FieldValueMap

type FieldValueMap map[string]map[string]json.RawMessage

FieldValueMap stores raw API objects for custom field values that need object wrapping during import. Structure:

normalizedFieldName → displayValue → rawJSON

Only populated for fields where the API returns an object (e.g. team, option, user). Scalar values (string, number, bool) don't need this.

func FindFieldValues

func FindFieldValues(dir string) (FieldValueMap, string, error)

FindFieldValues searches for a .jira-field-values.json file starting from dir, then checking the parent directory (one level up). Returns the loaded map and the path found, or an empty map if not found.

func IssueToMarkdown

func IssueToMarkdown(issue api.Issue, fields map[string]api.Field, warnWriter io.Writer) ([]byte, FieldValueMap, error)

IssueToMarkdown converts an api.Issue to markdown bytes with YAML frontmatter. The fields map (keyed by field ID, e.g. "customfield_10001") provides display names for custom field resolution. Pass nil to omit custom fields. Warnings (collisions, skipped values) are written to warnWriter; nil is safe.

Returns the markdown bytes and a FieldValueMap containing raw API objects for any custom fields whose values were extracted from objects (for sidecar).

The output has the form:

---
key: PROJ-123
summary: Issue title
...
---
Markdown description body

func LoadFieldValues

func LoadFieldValues(path string) (FieldValueMap, error)

LoadFieldValues reads a FieldValueMap from the given path. Returns an empty map (not nil) if the file does not exist.

func (FieldValueMap) Merge

func (fvm FieldValueMap) Merge(other FieldValueMap) bool

Merge adds entries from other into fvm. Existing entries are preserved (first-write wins), so earlier exports don't lose values. Returns true if any new entries were added.

type Frontmatter

type Frontmatter struct {
	Key        string   `yaml:"key"`
	ID         string   `yaml:"id,omitempty"`
	Type       string   `yaml:"type,omitempty"`
	Summary    string   `yaml:"summary"`
	Status     string   `yaml:"status,omitempty"`
	Priority   string   `yaml:"priority,omitempty"`
	Labels     []string `yaml:"labels,omitempty"`
	Components []string `yaml:"components,omitempty"`
	Parent     string   `yaml:"parent,omitempty"`
	Assignee   string   `yaml:"assignee,omitempty"`
	AssigneeID string   `yaml:"assignee_id,omitempty"`
	Reporter   string   `yaml:"reporter,omitempty"`
	ReporterID string   `yaml:"reporter_id,omitempty"`
	Project    string   `yaml:"project,omitempty"`
	Created    string   `yaml:"created,omitempty"`
	Updated    string   `yaml:"updated,omitempty"`

	// CustomFields holds custom field values keyed by normalized name.
	// Excluded from default YAML marshal; appended by MarshalYAML.
	CustomFields map[string]interface{} `yaml:"-"`
}

Frontmatter holds the YAML metadata for an issue markdown file.

func (Frontmatter) MarshalYAML

func (fm Frontmatter) MarshalYAML() (interface{}, error)

MarshalYAML marshals built-in fields first, then appends custom fields in alphabetical order.

type IssueFile

type IssueFile struct {
	Path        string
	Frontmatter Frontmatter
	Description string // raw markdown body after frontmatter
}

IssueFile represents a parsed markdown file with YAML frontmatter.

func ParseDir

func ParseDir(dir string) ([]*IssueFile, error)

ParseDir recursively finds all .md files in dir and parses them, sorted by path.

func ParseFile

func ParseFile(path string) (*IssueFile, error)

ParseFile reads a markdown file, splits YAML frontmatter from body, and validates. Returns CLIError with VALIDATION_ERROR if frontmatter is missing or invalid.

func (*IssueFile) IsCreate

func (f *IssueFile) IsCreate() bool

IsCreate returns true if the issue key matches the temp key pattern (e.g. PROJ-NEW-1).

Jump to

Keyboard shortcuts

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