MCPcopy
hub / github.com/cli/cli / DiscoverSkillFiles

Function DiscoverSkillFiles

internal/skills/discovery/discovery.go:780–804  ·  view source on GitHub ↗

DiscoverSkillFiles returns all file paths belonging to a skill directory by fetching the skill's subtree directly using its tree SHA.

(client *api.Client, host, owner, repo, treeSHA, skillPath string)

Source from the content-addressed store, hash-verified

778// DiscoverSkillFiles returns all file paths belonging to a skill directory
779// by fetching the skill's subtree directly using its tree SHA.
780func DiscoverSkillFiles(client *api.Client, host, owner, repo, treeSHA, skillPath string) ([]SkillFile, error) {
781 apiPath := fmt.Sprintf("repos/%s/%s/git/trees/%s?recursive=true", url.PathEscape(owner), url.PathEscape(repo), url.PathEscape(treeSHA))
782 var tree treeResponse
783 if err := client.REST(host, "GET", apiPath, nil, &tree); err != nil {
784 return nil, fmt.Errorf("could not fetch skill tree: %w", err)
785 }
786
787 if tree.Truncated {
788 // Recursive fetch was truncated. Fall back to walking subtrees individually.
789 return walkTree(client, host, owner, repo, treeSHA, skillPath, 0)
790 }
791
792 var files []SkillFile
793 for _, entry := range tree.Tree {
794 if entry.Type == "blob" {
795 files = append(files, SkillFile{
796 Path: skillPath + "/" + entry.Path,
797 SHA: entry.SHA,
798 Size: entry.Size,
799 })
800 }
801 }
802
803 return files, nil
804}
805
806// ListSkillFiles returns all files in a skill directory as public SkillFile
807// structs with paths relative to the skill root.

Callers 2

installSkillFunction · 0.92
TestDiscoverSkillFilesFunction · 0.85

Calls 3

walkTreeFunction · 0.85
RESTMethod · 0.65
ErrorfMethod · 0.65

Tested by 1

TestDiscoverSkillFilesFunction · 0.68