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

Function extractFieldFromDirectiveForField

pkg/parser/include_expander.go:301–326  ·  view source on GitHub ↗
(
	directive *ImportDirectiveMatch,
	baseDir string,
	extractFunc func(string) (string, error),
)

Source from the content-addressed store, hash-verified

299}
300
301func extractFieldFromDirectiveForField(
302 directive *ImportDirectiveMatch,
303 baseDir string,
304 extractFunc func(string) (string, error),
305) (string, bool, error) {
306 filePath := includeDirectiveFilePath(directive.Path)
307 fullPath, err := ResolveIncludePath(filePath, baseDir, nil)
308 if err != nil {
309 if directive.IsOptional {
310 return "", true, nil
311 }
312 return "", false, fmt.Errorf("failed to resolve required include '%s': %w", filePath, err)
313 }
314
315 fileContent, err := readFileFunc(fullPath)
316 if err != nil {
317 return "", false, fmt.Errorf("failed to read included file '%s': %w", fullPath, err)
318 }
319
320 fieldJSON, err := extractFunc(string(fileContent))
321 if err != nil {
322 return "", false, fmt.Errorf("failed to extract field from '%s': %w", fullPath, err)
323 }
324
325 return fieldJSON, false, nil
326}
327
328func includeDirectiveFilePath(includePath string) string {
329 // Note: section references are ignored for frontmatter field extraction.

Callers 1

processIncludesForFieldFunction · 0.85

Calls 3

includeDirectiveFilePathFunction · 0.85
ResolveIncludePathFunction · 0.70
ErrorfMethod · 0.45

Tested by

no test coverage detected