MCPcopy Create free account
hub / github.com/cli/cli / DiscoverSkillFiles

Function DiscoverSkillFiles

internal/skills/discovery/discovery.go:842–870  ·  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

840// DiscoverSkillFiles returns all file paths belonging to a skill directory
841// by fetching the skill's subtree directly using its tree SHA.
842func DiscoverSkillFiles(client *api.Client, host, owner, repo, treeSHA, skillPath string) ([]SkillFile, error) {
843 apiPath, err := safeurl.JoinPath("repos", owner, repo, "git", "trees", treeSHA)
844 if err != nil {
845 return nil, err
846 }
847 apiPath.SetQuery("recursive", "true")
848 var tree treeResponse
849 if err := client.REST(host, "GET", apiPath.String(), nil, &tree); err != nil {
850 return nil, fmt.Errorf("could not fetch skill tree: %w", err)
851 }
852
853 if tree.Truncated {
854 // Recursive fetch was truncated. Fall back to walking subtrees individually.
855 return walkTree(client, host, owner, repo, treeSHA, skillPath, 0)
856 }
857
858 var files []SkillFile
859 for _, entry := range tree.Tree {
860 if entry.Type == "blob" {
861 files = append(files, SkillFile{
862 Path: skillPath + "/" + entry.Path,
863 SHA: entry.SHA,
864 Size: entry.Size,
865 })
866 }
867 }
868
869 return files, nil
870}
871
872// ListSkillFiles returns all files in a skill directory as public SkillFile
873// structs with paths relative to the skill root.

Callers 2

installSkillFunction · 0.92
TestDiscoverSkillFilesFunction · 0.85

Calls 6

JoinPathFunction · 0.92
walkTreeFunction · 0.85
SetQueryMethod · 0.80
RESTMethod · 0.65
StringMethod · 0.65
ErrorfMethod · 0.65

Tested by 1

TestDiscoverSkillFilesFunction · 0.68