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

Function applySourceAndIncludeModifications

pkg/cli/add_command.go:560–602  ·  view source on GitHub ↗
(content string, workflowSpec *WorkflowSpec, sourceInfo *FetchedWorkflow, githubWorkflowsDir string, opts AddOptions)

Source from the content-addressed store, hash-verified

558}
559
560func applySourceAndIncludeModifications(content string, workflowSpec *WorkflowSpec, sourceInfo *FetchedWorkflow, githubWorkflowsDir string, opts AddOptions) (string, error) {
561 // Add source field to frontmatter
562 commitSHA := ""
563 if sourceInfo != nil {
564 commitSHA = sourceInfo.CommitSHA
565 }
566 sourceString := buildSourceStringWithCommitSHA(workflowSpec, commitSHA)
567 if sourceString != "" {
568 updatedContent, err := addSourceToWorkflow(content, sourceString)
569 if err != nil {
570 if opts.Verbose {
571 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to add source field: %v", err)))
572 }
573 } else {
574 content = updatedContent
575 }
576 }
577
578 // Note: frontmatter 'imports:' are intentionally kept as relative paths here.
579 // fetchAndSaveRemoteFrontmatterImports already downloaded those files locally, so
580 // the compiler can resolve them from disk without any GitHub API calls.
581
582 // Process @include directives and replace with workflowspec.
583 // For local workflows, use the workflow's directory as the package source path.
584 // Pass githubWorkflowsDir as localWorkflowDir so that any body-level import
585 // whose target already exists locally is preserved as a local reference rather
586 // than being rewritten to a cross-repo workflowspec.
587 if workflowSpec.RepoSlug == "" || workflowSpec.WorkflowPath == "" {
588 return content, nil
589 }
590 includeSourceDir := ""
591 if sourceInfo != nil && sourceInfo.IsLocal {
592 includeSourceDir = filepath.Dir(workflowSpec.WorkflowPath)
593 }
594 processedContent, err := processIncludesWithWorkflowSpec(content, workflowSpec, commitSHA, includeSourceDir, githubWorkflowsDir, opts.Verbose)
595 if err != nil {
596 if opts.Verbose {
597 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to process includes: %v", err)))
598 }
599 return content, nil
600 }
601 return processedContent, nil
602}
603
604func applyStopAfterModifications(content string, opts AddOptions) (string, error) {
605 // Handle stop-after field modifications

Callers 1

Calls 4

FormatWarningMessageFunction · 0.92
addSourceToWorkflowFunction · 0.85

Tested by

no test coverage detected