MCPcopy Create free account
hub / github.com/github/gh-aw / updateFieldInFrontmatterFallback

Function updateFieldInFrontmatterFallback

pkg/cli/frontmatter_editor.go:109–140  ·  view source on GitHub ↗

updateFieldInFrontmatterFallback implements the original behavior as a fallback

(result *parser.FrontmatterResult, fieldName, fieldValue string)

Source from the content-addressed store, hash-verified

107
108// updateFieldInFrontmatterFallback implements the original behavior as a fallback
109func updateFieldInFrontmatterFallback(result *parser.FrontmatterResult, fieldName, fieldValue string) (string, error) {
110 // Initialize frontmatter if it doesn't exist
111 if result.Frontmatter == nil {
112 result.Frontmatter = make(map[string]any)
113 }
114
115 // Update the field
116 result.Frontmatter[fieldName] = fieldValue
117
118 // Convert back to YAML with proper field ordering
119 updatedFrontmatter, err := workflow.MarshalWithFieldOrder(result.Frontmatter, constants.PriorityWorkflowFields)
120 if err != nil {
121 return "", fmt.Errorf("failed to marshal updated frontmatter: %w", err)
122 }
123
124 // Clean up quoted keys - replace "on": with on: at the start of a line
125 frontmatterStr := strings.TrimSuffix(string(updatedFrontmatter), "\n")
126 frontmatterStr = workflow.UnquoteYAMLKey(frontmatterStr, "on")
127
128 // Reconstruct the file
129 var lines []string
130 lines = append(lines, "---")
131 if frontmatterStr != "" {
132 lines = append(lines, strings.Split(frontmatterStr, "\n")...)
133 }
134 lines = append(lines, "---")
135 if result.Markdown != "" {
136 lines = append(lines, result.Markdown)
137 }
138
139 return strings.Join(lines, "\n"), nil
140}
141
142// addFieldToFrontmatter adds a new field to the frontmatter while preserving formatting.
143// This is used when we know the field doesn't exist yet.

Callers 2

UpdateFieldInFrontmatterFunction · 0.85
addFieldToFrontmatterFunction · 0.85

Calls 3

MarshalWithFieldOrderFunction · 0.92
UnquoteYAMLKeyFunction · 0.92
ErrorfMethod · 0.45

Tested by

no test coverage detected