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

Function ListSkillFiles

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

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