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

Function MigrateRepoConfigFiles

internal/repoconfig/repoconfig.go:344–369  ·  view source on GitHub ↗

MigrateRepoConfigFiles migrates legacy prompt_repos.json files to the canonical instruction_repos.json name. If instruction_repos.json already exists, it is preferred and prompt_repos.json is left untouched. If only prompt_repos.json exists, its repository entries are copied as-is because repo confi

(cfgDir string)

Source from the content-addressed store, hash-verified

342// prompt_repos.json exists, its repository entries are copied as-is because repo
343// config entries do not store an entity kind.
344func MigrateRepoConfigFiles(cfgDir string) (bool, error) {
345 oldPath := filepath.Join(cfgDir, "prompt_repos.json")
346 newPath := filepath.Join(cfgDir, "instruction_repos.json")
347
348 if fileExists(newPath) {
349 return false, nil
350 }
351
352 data, err := os.ReadFile(oldPath)
353 if err != nil {
354 if os.IsNotExist(err) {
355 return false, nil
356 }
357 return false, fmt.Errorf("repoconfig: read %s: %w", oldPath, err)
358 }
359 if _, err := parseRepoJSON(data); err != nil {
360 return false, err
361 }
362 if err := os.MkdirAll(cfgDir, 0o755); err != nil {
363 return false, fmt.Errorf("repoconfig: mkdir %s: %w", cfgDir, err)
364 }
365 if err := os.WriteFile(newPath, data, 0o644); err != nil {
366 return false, fmt.Errorf("repoconfig: write %s: %w", newPath, err)
367 }
368 return true, nil
369}
370
371func fileExists(path string) bool {
372 _, err := os.Stat(path)

Calls 3

fileExistsFunction · 0.85
parseRepoJSONFunction · 0.85
ReadFileMethod · 0.80