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

Function ExtractMetadataFromLockFile

pkg/workflow/lock_schema.go:75–99  ·  view source on GitHub ↗

ExtractMetadataFromLockFile extracts structured metadata from a lock file's comment header Returns metadata and whether legacy format (no metadata) was detected

(content string)

Source from the content-addressed store, hash-verified

73// ExtractMetadataFromLockFile extracts structured metadata from a lock file's comment header
74// Returns metadata and whether legacy format (no metadata) was detected
75func ExtractMetadataFromLockFile(content string) (*LockMetadata, bool, error) {
76 // Look for JSON metadata in comments (format: # gh-aw-metadata: {...})
77 // Use .+ to capture to end of line since metadata is single-line JSON
78 matches := lockMetadataPattern.FindStringSubmatch(content)
79
80 if len(matches) >= 2 {
81 jsonStr := matches[1]
82 var metadata LockMetadata
83 if err := json.Unmarshal([]byte(jsonStr), &metadata); err != nil {
84 return nil, false, fmt.Errorf("failed to parse lock metadata JSON: %w", err)
85 }
86 lockSchemaLog.Printf("Extracted metadata from lock file: schema=%s", metadata.SchemaVersion)
87 return &metadata, false, nil
88 }
89
90 // Legacy format: look for frontmatter-hash without JSON metadata
91 if matches := lockHashPattern.FindStringSubmatch(content); len(matches) >= 2 {
92 lockSchemaLog.Print("Legacy lock file detected (no schema version)")
93 // Return a minimal metadata struct with just the hash for legacy files
94 return &LockMetadata{FrontmatterHash: matches[1]}, true, nil
95 }
96
97 // No metadata found at all
98 return nil, false, nil
99}
100
101// formatSupportedVersions formats the list of supported versions for error messages
102func formatSupportedVersions() string {

Calls 3

PrintMethod · 0.80
ErrorfMethod · 0.45
PrintfMethod · 0.45