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

Function extractWorkflowNameFromFile

pkg/cli/workflows.go:409–442  ·  view source on GitHub ↗

extractWorkflowNameFromFile extracts the workflow name from a file's H1 header

(filePath string)

Source from the content-addressed store, hash-verified

407
408// extractWorkflowNameFromFile extracts the workflow name from a file's H1 header
409func extractWorkflowNameFromFile(filePath string) (title string, err error) {
410 fd, err := os.Open(filePath)
411 if err != nil {
412 return "", err
413 }
414 defer func() {
415 if closeErr := fd.Close(); closeErr != nil && err == nil {
416 err = fmt.Errorf("failed to close workflow file %s: %w", filePath, closeErr)
417 }
418 }()
419
420 title, err = fastParseTitleFromReader(fd)
421 if err != nil {
422 return "", err
423 }
424
425 if title == "" {
426 // No H1 header found, generate default name from filename
427 baseName := filepath.Base(filePath)
428 baseName = strings.TrimSuffix(baseName, filepath.Ext(baseName))
429 baseName = strings.ReplaceAll(baseName, "-", " ")
430
431 // Capitalize first letter of each word
432 words := strings.Fields(baseName)
433 for i, word := range words {
434 if len(word) > 0 {
435 words[i] = strings.ToUpper(word[:1]) + word[1:]
436 }
437 }
438 title = strings.Join(words, " ")
439 }
440
441 return title, nil
442}
443
444// extractEngineIDFromFrontmatter extracts the engine ID from a parsed frontmatter map.
445// Returns "copilot" as the default if no engine is specified.

Calls 3

fastParseTitleFromReaderFunction · 0.85
CloseMethod · 0.65
ErrorfMethod · 0.45