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

Function ListSkillFiles

internal/skills/discovery/discovery.go:846–873  ·  view source on GitHub ↗

ListSkillFiles returns all files in a skill directory as public SkillFile structs with paths relative to the skill root.

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

Source from the content-addressed store, hash-verified

844// ListSkillFiles returns all files in a skill directory as public SkillFile
845// structs with paths relative to the skill root.
846func ListSkillFiles(client *api.Client, host, owner, repo, treeSHA string) ([]SkillFile, error) {
847 apiPath, err := safeurl.JoinPath("repos", owner, repo, "git", "trees", treeSHA)
848 if err != nil {
849 return nil, err
850 }
851 apiPath.SetQuery("recursive", "true")
852 var tree treeResponse
853 if err := client.REST(host, "GET", apiPath.String(), nil, &tree); err != nil {
854 return nil, fmt.Errorf("could not fetch skill tree: %w", err)
855 }
856
857 if tree.Truncated {
858 // Fall back to non-recursive traversal when the tree is too large.
859 return walkTree(client, host, owner, repo, treeSHA, "", 0)
860 }
861
862 var files []SkillFile
863 for _, entry := range tree.Tree {
864 if entry.Type == "blob" {
865 files = append(files, SkillFile{
866 Path: entry.Path,
867 SHA: entry.SHA,
868 Size: entry.Size,
869 })
870 }
871 }
872 return files, nil
873}
874
875// maxTreeDepth bounds the recursion in walkTree to prevent unbounded
876// API calls on deeply nested repositories.

Callers 2

previewRunFunction · 0.92
TestListSkillFilesFunction · 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

TestListSkillFilesFunction · 0.68