ComputeFrontmatterHashFromFileWithReader computes the frontmatter hash for a workflow file using a custom file reader function (e.g., for GitHub API, in-memory file system, etc.) It parses the frontmatter once from the file content, then delegates to the core logic.
(filePath string, cache *ImportCache, fileReader FileReader)
| 160 | // using a custom file reader function (e.g., for GitHub API, in-memory file system, etc.) |
| 161 | // It parses the frontmatter once from the file content, then delegates to the core logic. |
| 162 | func ComputeFrontmatterHashFromFileWithReader(filePath string, cache *ImportCache, fileReader FileReader) (string, error) { |
| 163 | frontmatterHashLog.Printf("Computing hash for file: %s", filePath) |
| 164 | |
| 165 | // Read file content using the provided file reader |
| 166 | content, err := fileReader(filePath) |
| 167 | if err != nil { |
| 168 | return "", fmt.Errorf("failed to read file: %w", err) |
| 169 | } |
| 170 | |
| 171 | // Parse frontmatter once from content; treat inlined-imports as false if parsing fails |
| 172 | var parsedFrontmatter map[string]any |
| 173 | if parsed, parseErr := ExtractFrontmatterFromContent(string(content)); parseErr == nil { |
| 174 | parsedFrontmatter = parsed.Frontmatter |
| 175 | } |
| 176 | |
| 177 | return computeFrontmatterHashFromContent(string(content), parsedFrontmatter, filePath, cache, fileReader) |
| 178 | } |
| 179 | |
| 180 | // computeFrontmatterHashFromContent is the shared core that computes the hash given the |
| 181 | // already-read file content and pre-parsed frontmatter map (may be nil). |