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

Function updateSkillRefsInContentWithResolver

pkg/cli/update_actions.go:692–756  ·  view source on GitHub ↗
(
	ctx context.Context,
	content string,
	allowMajor, verbose bool,
	coolDown time.Duration,
	resolver skillRefUpdateResolver,
)

Source from the content-addressed store, hash-verified

690}
691
692func updateSkillRefsInContentWithResolver(
693 ctx context.Context,
694 content string,
695 allowMajor, verbose bool,
696 coolDown time.Duration,
697 resolver skillRefUpdateResolver,
698) (bool, string, error) {
699 result, err := parser.ExtractFrontmatterFromContent(content)
700 if err != nil {
701 if verbose {
702 updateLog.Printf("Skipping skill update for content without parseable frontmatter: %v", err)
703 }
704 return false, content, nil
705 }
706 if result == nil || result.Frontmatter == nil {
707 return false, content, nil
708 }
709
710 rawSkills, ok := result.Frontmatter["skills"].([]any)
711 if !ok || len(rawSkills) == 0 {
712 return false, content, nil
713 }
714
715 changed := false
716 for i, rawSkill := range rawSkills {
717 switch typed := rawSkill.(type) {
718 case string:
719 updated, updatedRef, err := updateSkillRefValue(ctx, typed, allowMajor, verbose, coolDown, resolver)
720 if err != nil {
721 return false, content, err
722 }
723 if updated {
724 rawSkills[i] = updatedRef
725 changed = true
726 }
727 case map[string]any:
728 skillRef, ok := typed["skill"].(string)
729 if !ok {
730 continue
731 }
732 updated, updatedRef, err := updateSkillRefValue(ctx, skillRef, allowMajor, verbose, coolDown, resolver)
733 if err != nil {
734 return false, content, err
735 }
736 if updated {
737 typed["skill"] = updatedRef
738 changed = true
739 }
740 }
741 }
742 if !changed {
743 return false, content, nil
744 }
745 result.Frontmatter["skills"] = rawSkills
746
747 updatedFrontmatter, err := yaml.Marshal(result.Frontmatter)
748 if err != nil {
749 return false, content, fmt.Errorf("failed to marshal updated frontmatter: %w", err)

Calls 6

ReconstructWorkflowFileFunction · 0.92
QuoteCronExpressionsFunction · 0.92
updateSkillRefValueFunction · 0.85
PrintfMethod · 0.45
ErrorfMethod · 0.45