Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/prompt-clustering-analysis.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .github/workflows/safe-output-health.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .github/workflows/schema-consistency-checker.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .github/workflows/scout.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .github/workflows/security-fix-pr.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .github/workflows/semantic-function-refactor.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .github/workflows/smoke-claude.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .github/workflows/smoke-detector.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .github/workflows/static-analysis-report.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .github/workflows/test-claude-oauth-workflow.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .github/workflows/typist.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .github/workflows/unbloat-docs.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pkg/cli/frontmatter_utils.go → pkg/cli/frontmatter_editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ import (
"github.com/githubnext/gh-aw/pkg/workflow"
)

var frontmatterUtilsLog = logger.New("cli:frontmatter_utils")
var frontmatterEditorLog = logger.New("cli:frontmatter_editor")

// UpdateFieldInFrontmatter updates a field in the frontmatter while preserving the original formatting
// when possible. It tries to preserve whitespace, comments, and formatting by working with the raw
// frontmatter lines, similar to how addSourceToWorkflow works.
func UpdateFieldInFrontmatter(content, fieldName, fieldValue string) (string, error) {
frontmatterUtilsLog.Printf("Updating frontmatter field: %s = %s", fieldName, fieldValue)
frontmatterEditorLog.Printf("Updating frontmatter field: %s = %s", fieldName, fieldValue)

// Parse frontmatter using parser package
result, err := parser.ExtractFrontmatterFromContent(content)
if err != nil {
frontmatterUtilsLog.Printf("Failed to parse frontmatter: %v", err)
frontmatterEditorLog.Printf("Failed to parse frontmatter: %v", err)
return "", fmt.Errorf("failed to parse frontmatter: %w", err)
}

// Try to preserve original frontmatter formatting by manually updating the field
if len(result.FrontmatterLines) > 0 {
frontmatterUtilsLog.Printf("Using raw frontmatter lines for field update (%d lines)", len(result.FrontmatterLines))
frontmatterEditorLog.Printf("Using raw frontmatter lines for field update (%d lines)", len(result.FrontmatterLines))
// Look for existing field in the raw lines
fieldUpdated := false
frontmatterLines := make([]string, len(result.FrontmatterLines))
Expand Down Expand Up @@ -55,7 +55,7 @@ func UpdateFieldInFrontmatter(content, fieldName, fieldValue string) (string, er
frontmatterLines[i] = fmt.Sprintf("%s%s: %s", leadingSpace, fieldName, fieldValue)
}
fieldUpdated = true
frontmatterUtilsLog.Printf("Updated existing field %s in place (line %d)", fieldName, i+1)
frontmatterEditorLog.Printf("Updated existing field %s in place (line %d)", fieldName, i+1)
break
}
}
Expand All @@ -64,7 +64,7 @@ func UpdateFieldInFrontmatter(content, fieldName, fieldValue string) (string, er
if !fieldUpdated {
newField := fmt.Sprintf("%s: %s", fieldName, fieldValue)
frontmatterLines = append(frontmatterLines, newField)
frontmatterUtilsLog.Printf("Added new field %s at end of frontmatter", fieldName)
frontmatterEditorLog.Printf("Added new field %s at end of frontmatter", fieldName)
}

// Reconstruct the file with preserved formatting
Expand Down
Loading
Loading