MCPcopy Index your code
hub / github.com/github/gh-aw / WriteJavaScriptToYAML

Function WriteJavaScriptToYAML

pkg/workflow/js.go:419–437  ·  view source on GitHub ↗

WriteJavaScriptToYAML writes a JavaScript script with proper indentation to a strings.Builder

(yaml *strings.Builder, script string)

Source from the content-addressed store, hash-verified

417
418// WriteJavaScriptToYAML writes a JavaScript script with proper indentation to a strings.Builder
419func WriteJavaScriptToYAML(yaml *strings.Builder, script string) {
420 // Validate that script is not empty - this helps catch errors where getter functions
421 // return empty strings after embedded scripts were removed
422 if strings.TrimSpace(script) == "" {
423 jsLog.Print("WARNING: Attempted to write empty JavaScript script to YAML")
424 return
425 }
426
427 // Remove JavaScript comments first
428 cleanScript := removeJavaScriptComments(script)
429
430 scriptLines := strings.SplitSeq(cleanScript, "\n")
431 for line := range scriptLines {
432 // Skip empty lines when inlining to YAML
433 if strings.TrimSpace(line) != "" {
434 fmt.Fprintf(yaml, " %s\n", line)
435 }
436 }
437}
438
439// GetLogParserScript returns the JavaScript content for a log parser by name

Calls 2

removeJavaScriptCommentsFunction · 0.85
PrintMethod · 0.80