From cac1b38cce413c1fb8ef0ad6f0705368a31bb639 Mon Sep 17 00:00:00 2001 From: Snider <631881+Snider@users.noreply.github.com> Date: Wed, 4 Feb 2026 14:27:06 +0000 Subject: [PATCH] chore(io): Migrate pkg/repos to Medium abstraction - Modified Registry and Repo structs in pkg/repos/registry.go to include io.Medium. - Updated LoadRegistry, FindRegistry, and ScanDirectory signatures to accept io.Medium. - Migrated all internal file operations in pkg/repos/registry.go to use the Medium interface instead of io.Local or os package. - Updated dozens of call sites across internal/cmd/ to pass io.Local to the updated repos functions. - Ensured consistent use of io.Medium for repo existence and git checks. --- internal/cmd/dev/cmd_apply.go | 4 +-- internal/cmd/dev/cmd_ci.go | 9 ++--- internal/cmd/dev/cmd_file_sync.go | 4 +-- internal/cmd/dev/cmd_impact.go | 7 ++-- internal/cmd/dev/registry.go | 9 ++--- internal/cmd/docs/cmd_scan.go | 8 ++--- internal/cmd/doctor/cmd_environment.go | 5 +-- internal/cmd/monitor/cmd_monitor.go | 5 +-- internal/cmd/pkgcmd/cmd_install.go | 8 ++--- internal/cmd/pkgcmd/cmd_manage.go | 12 +++---- internal/cmd/pkgcmd/cmd_search.go | 2 +- internal/cmd/qa/cmd_health.go | 7 ++-- internal/cmd/qa/cmd_issues.go | 7 ++-- internal/cmd/security/cmd_security.go | 7 ++-- internal/cmd/setup/cmd_bootstrap.go | 4 +-- internal/cmd/setup/cmd_github.go | 5 +-- internal/cmd/setup/cmd_registry.go | 2 +- pkg/repos/registry.go | 48 +++++++++++++++++--------- 18 files changed, 88 insertions(+), 65 deletions(-) diff --git a/internal/cmd/dev/cmd_apply.go b/internal/cmd/dev/cmd_apply.go index 738ad606..e3655b02 100644 --- a/internal/cmd/dev/cmd_apply.go +++ b/internal/cmd/dev/cmd_apply.go @@ -225,12 +225,12 @@ func runApply() error { // getApplyTargetRepos gets repos to apply command to func getApplyTargetRepos() ([]*repos.Repo, error) { // Load registry - registryPath, err := repos.FindRegistry() + registryPath, err := repos.FindRegistry(io.Local) if err != nil { return nil, core.E("dev.apply", "failed to find registry", err) } - registry, err := repos.LoadRegistry(registryPath) + registry, err := repos.LoadRegistry(io.Local, registryPath) if err != nil { return nil, core.E("dev.apply", "failed to load registry", err) } diff --git a/internal/cmd/dev/cmd_ci.go b/internal/cmd/dev/cmd_ci.go index de0ef97b..1b6e9842 100644 --- a/internal/cmd/dev/cmd_ci.go +++ b/internal/cmd/dev/cmd_ci.go @@ -10,6 +10,7 @@ import ( "github.com/host-uk/core/pkg/cli" "github.com/host-uk/core/pkg/i18n" + "github.com/host-uk/core/pkg/io" "github.com/host-uk/core/pkg/repos" ) @@ -75,20 +76,20 @@ func runCI(registryPath string, branch string, failedOnly bool) error { var err error if registryPath != "" { - reg, err = repos.LoadRegistry(registryPath) + reg, err = repos.LoadRegistry(io.Local, registryPath) if err != nil { return cli.Wrap(err, "failed to load registry") } } else { - registryPath, err = repos.FindRegistry() + registryPath, err = repos.FindRegistry(io.Local) if err == nil { - reg, err = repos.LoadRegistry(registryPath) + reg, err = repos.LoadRegistry(io.Local, registryPath) if err != nil { return cli.Wrap(err, "failed to load registry") } } else { cwd, _ := os.Getwd() - reg, err = repos.ScanDirectory(cwd) + reg, err = repos.ScanDirectory(io.Local, cwd) if err != nil { return cli.Wrap(err, "failed to scan directory") } diff --git a/internal/cmd/dev/cmd_file_sync.go b/internal/cmd/dev/cmd_file_sync.go index 736c1c41..3e6b6b29 100644 --- a/internal/cmd/dev/cmd_file_sync.go +++ b/internal/cmd/dev/cmd_file_sync.go @@ -195,12 +195,12 @@ func runFileSync(source string) error { // resolveTargetRepos resolves the --to pattern to actual repos func resolveTargetRepos(pattern string) ([]*repos.Repo, error) { // Load registry - registryPath, err := repos.FindRegistry() + registryPath, err := repos.FindRegistry(io.Local) if err != nil { return nil, log.E("dev.sync", "failed to find registry", err) } - registry, err := repos.LoadRegistry(registryPath) + registry, err := repos.LoadRegistry(io.Local, registryPath) if err != nil { return nil, log.E("dev.sync", "failed to load registry", err) } diff --git a/internal/cmd/dev/cmd_impact.go b/internal/cmd/dev/cmd_impact.go index 22a499df..345733d6 100644 --- a/internal/cmd/dev/cmd_impact.go +++ b/internal/cmd/dev/cmd_impact.go @@ -6,6 +6,7 @@ import ( "github.com/host-uk/core/pkg/cli" "github.com/host-uk/core/pkg/i18n" + "github.com/host-uk/core/pkg/io" "github.com/host-uk/core/pkg/repos" ) @@ -42,14 +43,14 @@ func runImpact(registryPath string, repoName string) error { var err error if registryPath != "" { - reg, err = repos.LoadRegistry(registryPath) + reg, err = repos.LoadRegistry(io.Local, registryPath) if err != nil { return cli.Wrap(err, "failed to load registry") } } else { - registryPath, err = repos.FindRegistry() + registryPath, err = repos.FindRegistry(io.Local) if err == nil { - reg, err = repos.LoadRegistry(registryPath) + reg, err = repos.LoadRegistry(io.Local, registryPath) if err != nil { return cli.Wrap(err, "failed to load registry") } diff --git a/internal/cmd/dev/registry.go b/internal/cmd/dev/registry.go index 8ead92a1..1a9dc7b9 100644 --- a/internal/cmd/dev/registry.go +++ b/internal/cmd/dev/registry.go @@ -8,6 +8,7 @@ import ( "github.com/host-uk/core/internal/cmd/workspace" "github.com/host-uk/core/pkg/cli" "github.com/host-uk/core/pkg/i18n" + "github.com/host-uk/core/pkg/io" "github.com/host-uk/core/pkg/repos" ) @@ -18,16 +19,16 @@ func loadRegistryWithConfig(registryPath string) (*repos.Registry, string, error var registryDir string if registryPath != "" { - reg, err = repos.LoadRegistry(registryPath) + reg, err = repos.LoadRegistry(io.Local, registryPath) if err != nil { return nil, "", cli.Wrap(err, "failed to load registry") } cli.Print("%s %s\n\n", dimStyle.Render(i18n.Label("registry")), registryPath) registryDir = filepath.Dir(registryPath) } else { - registryPath, err = repos.FindRegistry() + registryPath, err = repos.FindRegistry(io.Local) if err == nil { - reg, err = repos.LoadRegistry(registryPath) + reg, err = repos.LoadRegistry(io.Local, registryPath) if err != nil { return nil, "", cli.Wrap(err, "failed to load registry") } @@ -36,7 +37,7 @@ func loadRegistryWithConfig(registryPath string) (*repos.Registry, string, error } else { // Fallback: scan current directory cwd, _ := os.Getwd() - reg, err = repos.ScanDirectory(cwd) + reg, err = repos.ScanDirectory(io.Local, cwd) if err != nil { return nil, "", cli.Wrap(err, "failed to scan directory") } diff --git a/internal/cmd/docs/cmd_scan.go b/internal/cmd/docs/cmd_scan.go index 2fb9574d..7f4d6b5c 100644 --- a/internal/cmd/docs/cmd_scan.go +++ b/internal/cmd/docs/cmd_scan.go @@ -30,22 +30,22 @@ func loadRegistry(registryPath string) (*repos.Registry, string, error) { var registryDir string if registryPath != "" { - reg, err = repos.LoadRegistry(registryPath) + reg, err = repos.LoadRegistry(io.Local, registryPath) if err != nil { return nil, "", cli.Wrap(err, i18n.T("i18n.fail.load", "registry")) } registryDir = filepath.Dir(registryPath) } else { - registryPath, err = repos.FindRegistry() + registryPath, err = repos.FindRegistry(io.Local) if err == nil { - reg, err = repos.LoadRegistry(registryPath) + reg, err = repos.LoadRegistry(io.Local, registryPath) if err != nil { return nil, "", cli.Wrap(err, i18n.T("i18n.fail.load", "registry")) } registryDir = filepath.Dir(registryPath) } else { cwd, _ := os.Getwd() - reg, err = repos.ScanDirectory(cwd) + reg, err = repos.ScanDirectory(io.Local, cwd) if err != nil { return nil, "", cli.Wrap(err, i18n.T("i18n.fail.scan", "directory")) } diff --git a/internal/cmd/doctor/cmd_environment.go b/internal/cmd/doctor/cmd_environment.go index 2e8ea280..c0eb8dff 100644 --- a/internal/cmd/doctor/cmd_environment.go +++ b/internal/cmd/doctor/cmd_environment.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/host-uk/core/pkg/i18n" + "github.com/host-uk/core/pkg/io" "github.com/host-uk/core/pkg/repos" ) @@ -43,11 +44,11 @@ func checkGitHubCLI() bool { // checkWorkspace checks for repos.yaml and counts cloned repos func checkWorkspace() { - registryPath, err := repos.FindRegistry() + registryPath, err := repos.FindRegistry(io.Local) if err == nil { fmt.Printf(" %s %s\n", successStyle.Render("✓"), i18n.T("cmd.doctor.repos_yaml_found", map[string]interface{}{"Path": registryPath})) - reg, err := repos.LoadRegistry(registryPath) + reg, err := repos.LoadRegistry(io.Local, registryPath) if err == nil { basePath := reg.BasePath if basePath == "" { diff --git a/internal/cmd/monitor/cmd_monitor.go b/internal/cmd/monitor/cmd_monitor.go index 847fc991..96e7ad58 100644 --- a/internal/cmd/monitor/cmd_monitor.go +++ b/internal/cmd/monitor/cmd_monitor.go @@ -18,6 +18,7 @@ import ( "github.com/host-uk/core/pkg/cli" "github.com/host-uk/core/pkg/i18n" + "github.com/host-uk/core/pkg/io" "github.com/host-uk/core/pkg/log" "github.com/host-uk/core/pkg/repos" ) @@ -177,12 +178,12 @@ func resolveRepos() ([]string, error) { if monitorAll { // All repos from registry - registry, err := repos.FindRegistry() + registry, err := repos.FindRegistry(io.Local) if err != nil { return nil, log.E("monitor", "failed to find registry", err) } - loaded, err := repos.LoadRegistry(registry) + loaded, err := repos.LoadRegistry(io.Local, registry) if err != nil { return nil, log.E("monitor", "failed to load registry", err) } diff --git a/internal/cmd/pkgcmd/cmd_install.go b/internal/cmd/pkgcmd/cmd_install.go index b5052325..49740714 100644 --- a/internal/cmd/pkgcmd/cmd_install.go +++ b/internal/cmd/pkgcmd/cmd_install.go @@ -51,8 +51,8 @@ func runPkgInstall(repoArg, targetDir string, addToRegistry bool) error { // Determine target directory if targetDir == "" { - if regPath, err := repos.FindRegistry(); err == nil { - if reg, err := repos.LoadRegistry(regPath); err == nil { + if regPath, err := repos.FindRegistry(io.Local); err == nil { + if reg, err := repos.LoadRegistry(io.Local, regPath); err == nil { targetDir = reg.BasePath if targetDir == "" { targetDir = "./packages" @@ -110,12 +110,12 @@ func runPkgInstall(repoArg, targetDir string, addToRegistry bool) error { } func addToRegistryFile(org, repoName string) error { - regPath, err := repos.FindRegistry() + regPath, err := repos.FindRegistry(io.Local) if err != nil { return errors.New(i18n.T("cmd.pkg.error.no_repos_yaml")) } - reg, err := repos.LoadRegistry(regPath) + reg, err := repos.LoadRegistry(io.Local, regPath) if err != nil { return err } diff --git a/internal/cmd/pkgcmd/cmd_manage.go b/internal/cmd/pkgcmd/cmd_manage.go index 9d40f901..c89cbd4f 100644 --- a/internal/cmd/pkgcmd/cmd_manage.go +++ b/internal/cmd/pkgcmd/cmd_manage.go @@ -28,12 +28,12 @@ func addPkgListCommand(parent *cobra.Command) { } func runPkgList() error { - regPath, err := repos.FindRegistry() + regPath, err := repos.FindRegistry(coreio.Local) if err != nil { return errors.New(i18n.T("cmd.pkg.error.no_repos_yaml_workspace")) } - reg, err := repos.LoadRegistry(regPath) + reg, err := repos.LoadRegistry(coreio.Local, regPath) if err != nil { return fmt.Errorf("%s: %w", i18n.T("i18n.fail.load", "registry"), err) } @@ -113,12 +113,12 @@ func addPkgUpdateCommand(parent *cobra.Command) { } func runPkgUpdate(packages []string, all bool) error { - regPath, err := repos.FindRegistry() + regPath, err := repos.FindRegistry(coreio.Local) if err != nil { return errors.New(i18n.T("cmd.pkg.error.no_repos_yaml")) } - reg, err := repos.LoadRegistry(regPath) + reg, err := repos.LoadRegistry(coreio.Local, regPath) if err != nil { return fmt.Errorf("%s: %w", i18n.T("i18n.fail.load", "registry"), err) } @@ -193,12 +193,12 @@ func addPkgOutdatedCommand(parent *cobra.Command) { } func runPkgOutdated() error { - regPath, err := repos.FindRegistry() + regPath, err := repos.FindRegistry(coreio.Local) if err != nil { return errors.New(i18n.T("cmd.pkg.error.no_repos_yaml")) } - reg, err := repos.LoadRegistry(regPath) + reg, err := repos.LoadRegistry(coreio.Local, regPath) if err != nil { return fmt.Errorf("%s: %w", i18n.T("i18n.fail.load", "registry"), err) } diff --git a/internal/cmd/pkgcmd/cmd_search.go b/internal/cmd/pkgcmd/cmd_search.go index c672ca72..c99b66ed 100644 --- a/internal/cmd/pkgcmd/cmd_search.go +++ b/internal/cmd/pkgcmd/cmd_search.go @@ -69,7 +69,7 @@ type ghRepo struct { func runPkgSearch(org, pattern, repoType string, limit int, refresh bool) error { // Initialize cache in workspace .core/ directory var cacheDir string - if regPath, err := repos.FindRegistry(); err == nil { + if regPath, err := repos.FindRegistry(io.Local); err == nil { cacheDir = filepath.Join(filepath.Dir(regPath), ".core", "cache") } diff --git a/internal/cmd/qa/cmd_health.go b/internal/cmd/qa/cmd_health.go index f34cee3d..4a5d1c8c 100644 --- a/internal/cmd/qa/cmd_health.go +++ b/internal/cmd/qa/cmd_health.go @@ -14,6 +14,7 @@ import ( "github.com/host-uk/core/pkg/cli" "github.com/host-uk/core/pkg/i18n" + "github.com/host-uk/core/pkg/io" "github.com/host-uk/core/pkg/log" "github.com/host-uk/core/pkg/repos" ) @@ -71,13 +72,13 @@ func runHealth() error { var err error if healthRegistry != "" { - reg, err = repos.LoadRegistry(healthRegistry) + reg, err = repos.LoadRegistry(io.Local, healthRegistry) } else { - registryPath, findErr := repos.FindRegistry() + registryPath, findErr := repos.FindRegistry(io.Local) if findErr != nil { return log.E("qa.health", i18n.T("error.registry_not_found"), nil) } - reg, err = repos.LoadRegistry(registryPath) + reg, err = repos.LoadRegistry(io.Local, registryPath) } if err != nil { return log.E("qa.health", "failed to load registry", err) diff --git a/internal/cmd/qa/cmd_issues.go b/internal/cmd/qa/cmd_issues.go index 2b038c6d..3001c7a9 100644 --- a/internal/cmd/qa/cmd_issues.go +++ b/internal/cmd/qa/cmd_issues.go @@ -17,6 +17,7 @@ import ( "github.com/host-uk/core/pkg/cli" "github.com/host-uk/core/pkg/i18n" + "github.com/host-uk/core/pkg/io" "github.com/host-uk/core/pkg/log" "github.com/host-uk/core/pkg/repos" ) @@ -100,13 +101,13 @@ func runQAIssues() error { var err error if issuesRegistry != "" { - reg, err = repos.LoadRegistry(issuesRegistry) + reg, err = repos.LoadRegistry(io.Local, issuesRegistry) } else { - registryPath, findErr := repos.FindRegistry() + registryPath, findErr := repos.FindRegistry(io.Local) if findErr != nil { return log.E("qa.issues", i18n.T("error.registry_not_found"), nil) } - reg, err = repos.LoadRegistry(registryPath) + reg, err = repos.LoadRegistry(io.Local, registryPath) } if err != nil { return log.E("qa.issues", "failed to load registry", err) diff --git a/internal/cmd/security/cmd_security.go b/internal/cmd/security/cmd_security.go index 12358b86..242c4ba4 100644 --- a/internal/cmd/security/cmd_security.go +++ b/internal/cmd/security/cmd_security.go @@ -8,6 +8,7 @@ import ( "github.com/host-uk/core/pkg/cli" "github.com/host-uk/core/pkg/i18n" + "github.com/host-uk/core/pkg/io" "github.com/host-uk/core/pkg/repos" ) @@ -106,18 +107,18 @@ type SecretScanningAlert struct { // loadRegistry loads the repository registry. func loadRegistry(registryPath string) (*repos.Registry, error) { if registryPath != "" { - reg, err := repos.LoadRegistry(registryPath) + reg, err := repos.LoadRegistry(io.Local, registryPath) if err != nil { return nil, cli.Wrap(err, "load registry") } return reg, nil } - path, err := repos.FindRegistry() + path, err := repos.FindRegistry(io.Local) if err != nil { return nil, cli.Wrap(err, "find registry") } - reg, err := repos.LoadRegistry(path) + reg, err := repos.LoadRegistry(io.Local, path) if err != nil { return nil, cli.Wrap(err, "load registry") } diff --git a/internal/cmd/setup/cmd_bootstrap.go b/internal/cmd/setup/cmd_bootstrap.go index 4ea2839c..3006396d 100644 --- a/internal/cmd/setup/cmd_bootstrap.go +++ b/internal/cmd/setup/cmd_bootstrap.go @@ -30,7 +30,7 @@ func runSetupOrchestrator(registryPath, only string, dryRun, all bool, projectNa if registryPath != "" { foundRegistry = registryPath } else { - foundRegistry, err = repos.FindRegistry() + foundRegistry, err = repos.FindRegistry(coreio.Local) } // If registry exists, use registry mode @@ -128,7 +128,7 @@ func runBootstrap(ctx context.Context, only string, dryRun, all bool, projectNam return nil } - reg, err := repos.LoadRegistry(registryPath) + reg, err := repos.LoadRegistry(coreio.Local, registryPath) if err != nil { return fmt.Errorf("failed to load registry from %s: %w", devopsRepo, err) } diff --git a/internal/cmd/setup/cmd_github.go b/internal/cmd/setup/cmd_github.go index 47a20e03..a2fb9698 100644 --- a/internal/cmd/setup/cmd_github.go +++ b/internal/cmd/setup/cmd_github.go @@ -23,6 +23,7 @@ import ( "path/filepath" "github.com/host-uk/core/pkg/cli" + "github.com/host-uk/core/pkg/io" "github.com/host-uk/core/pkg/i18n" "github.com/host-uk/core/pkg/repos" "github.com/spf13/cobra" @@ -78,12 +79,12 @@ func runGitHubSetup() error { } // Find registry - registryPath, err := repos.FindRegistry() + registryPath, err := repos.FindRegistry(io.Local) if err != nil { return cli.Wrap(err, i18n.T("error.registry_not_found")) } - reg, err := repos.LoadRegistry(registryPath) + reg, err := repos.LoadRegistry(io.Local, registryPath) if err != nil { return cli.Wrap(err, "failed to load registry") } diff --git a/internal/cmd/setup/cmd_registry.go b/internal/cmd/setup/cmd_registry.go index a06e10ef..9f3b8b04 100644 --- a/internal/cmd/setup/cmd_registry.go +++ b/internal/cmd/setup/cmd_registry.go @@ -22,7 +22,7 @@ import ( // runRegistrySetup loads a registry from path and runs setup. func runRegistrySetup(ctx context.Context, registryPath, only string, dryRun, all, runBuild bool) error { - reg, err := repos.LoadRegistry(registryPath) + reg, err := repos.LoadRegistry(coreio.Local, registryPath) if err != nil { return fmt.Errorf("failed to load registry: %w", err) } diff --git a/pkg/repos/registry.go b/pkg/repos/registry.go index 6122fd42..018b7103 100644 --- a/pkg/repos/registry.go +++ b/pkg/repos/registry.go @@ -20,6 +20,7 @@ type Registry struct { BasePath string `yaml:"base_path"` Repos map[string]*Repo `yaml:"repos"` Defaults RegistryDefaults `yaml:"defaults"` + medium io.Medium `yaml:"-"` } // RegistryDefaults contains default values applied to all repos. @@ -56,17 +57,18 @@ type Repo struct { Clone *bool `yaml:"clone,omitempty"` // nil = true, false = skip cloning // Computed fields - Path string `yaml:"-"` // Full path to repo directory + Path string `yaml:"-"` // Full path to repo directory + registry *Registry `yaml:"-"` } // LoadRegistry reads and parses a repos.yaml file. -func LoadRegistry(path string) (*Registry, error) { +func LoadRegistry(m io.Medium, path string) (*Registry, error) { absPath, err := filepath.Abs(path) if err != nil { return nil, fmt.Errorf("failed to resolve path: %w", err) } - content, err := io.Local.Read(absPath) + content, err := m.Read(absPath) if err != nil { return nil, fmt.Errorf("failed to read registry file: %w", err) } @@ -77,6 +79,8 @@ func LoadRegistry(path string) (*Registry, error) { return nil, fmt.Errorf("failed to parse registry file: %w", err) } + reg.medium = m + // Expand base path reg.BasePath = expandPath(reg.BasePath) @@ -84,6 +88,7 @@ func LoadRegistry(path string) (*Registry, error) { for name, repo := range reg.Repos { repo.Name = name repo.Path = filepath.Join(reg.BasePath, name) + repo.registry = ® // Apply defaults if not set if repo.CI == "" { @@ -96,7 +101,7 @@ func LoadRegistry(path string) (*Registry, error) { // FindRegistry searches for repos.yaml in common locations. // It checks: current directory, parent directories, and home directory. -func FindRegistry() (string, error) { +func FindRegistry(m io.Medium) (string, error) { // Check current directory and parents dir, err := os.Getwd() if err != nil { @@ -105,7 +110,7 @@ func FindRegistry() (string, error) { for { candidate := filepath.Join(dir, "repos.yaml") - if io.Local.Exists(candidate) { + if m.Exists(candidate) { return candidate, nil } @@ -128,7 +133,7 @@ func FindRegistry() (string, error) { } for _, p := range commonPaths { - if io.Local.Exists(p) { + if m.Exists(p) { return p, nil } } @@ -138,13 +143,13 @@ func FindRegistry() (string, error) { // ScanDirectory creates a Registry by scanning a directory for git repos. // This is used as a fallback when no repos.yaml is found. -func ScanDirectory(dir string) (*Registry, error) { +func ScanDirectory(m io.Medium, dir string) (*Registry, error) { absDir, err := filepath.Abs(dir) if err != nil { return nil, fmt.Errorf("failed to resolve directory path: %w", err) } - entries, err := io.Local.List(absDir) + entries, err := m.List(absDir) if err != nil { return nil, fmt.Errorf("failed to read directory: %w", err) } @@ -153,6 +158,7 @@ func ScanDirectory(dir string) (*Registry, error) { Version: 1, BasePath: absDir, Repos: make(map[string]*Repo), + medium: m, } // Try to detect org from git remote @@ -164,21 +170,22 @@ func ScanDirectory(dir string) (*Registry, error) { repoPath := filepath.Join(absDir, entry.Name()) gitPath := filepath.Join(repoPath, ".git") - if !io.Local.IsDir(gitPath) { + if !m.IsDir(gitPath) { continue // Not a git repo } repo := &Repo{ - Name: entry.Name(), - Path: repoPath, - Type: "module", // Default type + Name: entry.Name(), + Path: repoPath, + Type: "module", // Default type + registry: reg, } reg.Repos[entry.Name()] = repo // Try to detect org from first repo's remote if reg.Org == "" { - reg.Org = detectOrg(repoPath) + reg.Org = detectOrg(m, repoPath) } } @@ -186,10 +193,10 @@ func ScanDirectory(dir string) (*Registry, error) { } // detectOrg tries to extract the GitHub org from a repo's origin remote. -func detectOrg(repoPath string) string { +func detectOrg(m io.Medium, repoPath string) string { // Try to read git remote configPath := filepath.Join(repoPath, ".git", "config") - content, err := io.Local.Read(configPath) + content, err := m.Read(configPath) if err != nil { return "" } @@ -301,13 +308,20 @@ func (r *Registry) TopologicalOrder() ([]*Repo, error) { // Exists checks if the repo directory exists on disk. func (repo *Repo) Exists() bool { - return io.Local.IsDir(repo.Path) + return repo.getMedium().IsDir(repo.Path) } // IsGitRepo checks if the repo directory contains a .git folder. func (repo *Repo) IsGitRepo() bool { gitPath := filepath.Join(repo.Path, ".git") - return io.Local.IsDir(gitPath) + return repo.getMedium().IsDir(gitPath) +} + +func (repo *Repo) getMedium() io.Medium { + if repo.registry != nil && repo.registry.medium != nil { + return repo.registry.medium + } + return io.Local } // expandPath expands ~ to home directory.