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

Function DiscoverSkillFiles

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

811// DiscoverSkillFiles returns all file paths belonging to a skill directory
812// by fetching the skill's subtree directly using its tree SHA.
813func DiscoverSkillFiles(client *api.Client, host, owner, repo, treeSHA, skillPath string) ([]SkillFile, error) {
814 apiPath, err := safeurl.JoinPath("repos", owner, repo, "git", "trees", treeSHA)
815 if err != nil {
816 return nil, err
817 }
818 apiPath.SetQuery("recursive", "true")
819 var tree treeResponse
820 if err := client.REST(host, "GET", apiPath.String(), nil, &tree); err != nil {
821 return nil, fmt.Errorf("could not fetch skill tree: %w", err)
822 }
823
824 if tree.Truncated {
825 // Recursive fetch was truncated. Fall back to walking subtrees individually.
826 return walkTree(client, host, owner, repo, treeSHA, skillPath, 0)
827 }
828
829 var files []SkillFile
830 for _, entry := range tree.Tree {
831 if entry.Type == "blob" {
832 files = append(files, SkillFile{
833 Path: skillPath + "/" + entry.Path,
834 SHA: entry.SHA,
835 Size: entry.Size,
836 })
837 }
838 }
839
840 return files, nil
841}
842
843// ListSkillFiles returns all files in a skill directory as public SkillFile
844// 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