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

Function ListSkillFiles

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

872// ListSkillFiles returns all files in a skill directory as public SkillFile
873// structs with paths relative to the skill root.
874func ListSkillFiles(client *api.Client, host, owner, repo, treeSHA string) ([]SkillFile, error) {
875 apiPath, err := safeurl.JoinPath("repos", owner, repo, "git", "trees", treeSHA)
876 if err != nil {
877 return nil, err
878 }
879 apiPath.SetQuery("recursive", "true")
880 var tree treeResponse
881 if err := client.REST(host, "GET", apiPath.String(), nil, &tree); err != nil {
882 return nil, fmt.Errorf("could not fetch skill tree: %w", err)
883 }
884
885 if tree.Truncated {
886 // Fall back to non-recursive traversal when the tree is too large.
887 return walkTree(client, host, owner, repo, treeSHA, "", 0)
888 }
889
890 var files []SkillFile
891 for _, entry := range tree.Tree {
892 if entry.Type == "blob" {
893 files = append(files, SkillFile{
894 Path: entry.Path,
895 SHA: entry.SHA,
896 Size: entry.Size,
897 })
898 }
899 }
900 return files, nil
901}
902
903// maxTreeDepth bounds the recursion in walkTree to prevent unbounded
904// 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