MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / fetchSingleRepoCount

Function fetchSingleRepoCount

internal/cli/management.go:1278–1326  ·  view source on GitHub ↗
(kind entities.Kind, owner, repo, branch, path string)

Source from the content-addressed store, hash-verified

1276}
1277
1278func fetchSingleRepoCount(kind entities.Kind, owner, repo, branch, path string) (int, error) {
1279 client := fetching.New()
1280 dest := filepath.Join(os.TempDir(), fmt.Sprintf("cam-fetch-%s-%s", owner, repo))
1281 _ = os.RemoveAll(dest)
1282 root, err := client.DownloadGitHubZip(owner, repo, branch, dest)
1283 if err != nil {
1284 return 0, err
1285 }
1286 scanRoot := root
1287 if path != "" {
1288 paths := strings.Split(path, "|")
1289 if len(paths) == 1 {
1290 scanRoot = filepath.Join(root, path)
1291 } else {
1292 scanRoot = root
1293 }
1294 }
1295 store := entities.NewStore(kind)
1296 added := 0
1297 fileTarget := defaultManifestName(kind)
1298 err = filepath.WalkDir(scanRoot, func(p string, d os.DirEntry, err error) error {
1299 if err != nil || d.IsDir() {
1300 return err
1301 }
1302 if filepath.Base(p) != fileTarget {
1303 return nil
1304 }
1305 data, err := os.ReadFile(p)
1306 if err != nil {
1307 return err
1308 }
1309 name := filepath.Base(filepath.Dir(p))
1310 entity := entities.Entity{
1311 Name: name,
1312 Content: string(data),
1313 Path: p,
1314 Repo: &entities.RepoRef{Owner: owner, Name: repo, Branch: branch, Path: path},
1315 }
1316 if err := store.Put(entity); err != nil {
1317 return err
1318 }
1319 added++
1320 return nil
1321 })
1322 if err != nil {
1323 return added, err
1324 }
1325 return added, nil
1326}
1327
1328func defaultManifestName(kind entities.Kind) string {
1329 switch kind {

Callers 2

fetchAllReposFunction · 0.85
fetchSingleRepoFunction · 0.85

Calls 6

PutMethod · 0.95
NewFunction · 0.92
NewStoreFunction · 0.92
defaultManifestNameFunction · 0.85
DownloadGitHubZipMethod · 0.80
ReadFileMethod · 0.80

Tested by

no test coverage detected