Round 2 follow-up to 907c5fa. Closes residual CodeRabbit findings.
Test infra:
- Replaced must* test helpers across cmd_apply_test, cmd_file_sync_test,
cmd_vm_test, cmd_ci_test, cmd_repo_test, cmd_wizard_test,
cmd_api_testgen_test, cmd_workflow_test, secret_test, coverage_test,
scan_secrets_test, snapshot_test with stdlib checks.
- Deleted stale package-level test_helpers_test.go files that only
supported the old must* pattern.
- AX-6 maintained: no testify Go imports / go.mod requires. Remaining
go.sum testify entries are transitive checksums after go mod tidy.
Module graph:
- CLI imports switched back to Cobra-compatible
dappco.re/go/core/cli/pkg/cli module + replacements for private
vanity modules. GOWORK=off resolves cleanly under isolated cache.
- locales/embed.go / go.sum: i18n checksum + go mod tidy clean.
Verified-but-already-correct (no code change needed):
- cmd/dev/service.go: no-op core.Result{OK:true} + prompt type assertion
- cmd/workspace/config.go: filepath.Abs normalisation + fmt.Errorf
wrapping
- tests/cli/devops/main.go: raw walk/read errors wrapped
- tests/cli/devops/Taskfile.yaml: strict shell flags
- cmd/dev/cmd_issues.go + cmd_reviews.go: import grouping (after CLI
module correction)
Verification: gofmt clean, GOWORK=off go vet + go test -count=1 ./...
pass with explicit cache paths.
Closes residual findings on https://github.com/dAppCore/go-devops/pull/2
Co-authored-by: Codex <noreply@openai.com>
159 lines
3.9 KiB
Go
159 lines
3.9 KiB
Go
package docs
|
|
|
|
import (
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"dappco.re/go/core/cli/pkg/cli"
|
|
"dappco.re/go/devops/cmd/workspace"
|
|
"dappco.re/go/i18n"
|
|
"dappco.re/go/io"
|
|
"dappco.re/go/scm/repos"
|
|
)
|
|
|
|
// RepoDocInfo holds documentation info for a repo
|
|
type RepoDocInfo struct {
|
|
Name string
|
|
Path string
|
|
HasDocs bool
|
|
Readme string
|
|
ClaudeMd string
|
|
Changelog string
|
|
DocsFiles []string // All files in docs/ directory (recursive)
|
|
KBFiles []string // All files in KB/ directory (recursive)
|
|
}
|
|
|
|
func loadRegistry(registryPath string) (*repos.Registry, string, error) {
|
|
var reg *repos.Registry
|
|
var err error
|
|
var registryDir string
|
|
|
|
if 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(io.Local)
|
|
if err == nil {
|
|
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(io.Local, cwd)
|
|
if err != nil {
|
|
return nil, "", cli.Wrap(err, i18n.T("i18n.fail.scan", "directory"))
|
|
}
|
|
registryDir = cwd
|
|
}
|
|
}
|
|
|
|
// Load workspace config to respect packages_dir
|
|
wsConfig, err := workspace.LoadConfig(registryDir)
|
|
if err != nil {
|
|
return nil, "", cli.Wrap(err, i18n.T("i18n.fail.load", "workspace config"))
|
|
}
|
|
|
|
basePath := registryDir
|
|
|
|
if wsConfig != nil && wsConfig.PackagesDir != "" && wsConfig.PackagesDir != "./packages" {
|
|
pkgDir := wsConfig.PackagesDir
|
|
|
|
// Expand ~
|
|
if strings.HasPrefix(pkgDir, "~/") {
|
|
home, _ := os.UserHomeDir()
|
|
pkgDir = filepath.Join(home, pkgDir[2:])
|
|
}
|
|
|
|
if !filepath.IsAbs(pkgDir) {
|
|
pkgDir = filepath.Join(registryDir, pkgDir)
|
|
}
|
|
basePath = pkgDir
|
|
|
|
// Update repo paths if they were relative to registry
|
|
// This ensures consistency when packages_dir overrides the default
|
|
reg.BasePath = basePath
|
|
for _, repo := range reg.Repos {
|
|
repo.Path = filepath.Join(basePath, repo.Name)
|
|
}
|
|
}
|
|
|
|
return reg, basePath, nil
|
|
}
|
|
|
|
func scanRepoDocs(repo *repos.Repo) RepoDocInfo {
|
|
info := RepoDocInfo{
|
|
Name: repo.Name,
|
|
Path: repo.Path,
|
|
}
|
|
|
|
// Check for README.md
|
|
readme := filepath.Join(repo.Path, "README.md")
|
|
if io.Local.IsFile(readme) {
|
|
info.Readme = readme
|
|
info.HasDocs = true
|
|
}
|
|
|
|
// Check for CLAUDE.md
|
|
claudeMd := filepath.Join(repo.Path, "CLAUDE.md")
|
|
if io.Local.IsFile(claudeMd) {
|
|
info.ClaudeMd = claudeMd
|
|
info.HasDocs = true
|
|
}
|
|
|
|
// Check for CHANGELOG.md
|
|
changelog := filepath.Join(repo.Path, "CHANGELOG.md")
|
|
if io.Local.IsFile(changelog) {
|
|
info.Changelog = changelog
|
|
info.HasDocs = true
|
|
}
|
|
|
|
// Recursively scan docs/ directory for .md files
|
|
docsDir := filepath.Join(repo.Path, "docs")
|
|
// Check if directory exists by listing it
|
|
if _, err := io.Local.List(docsDir); err == nil {
|
|
_ = filepath.WalkDir(docsDir, func(path string, d fs.DirEntry, err error) error {
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
// Skip plans/ directory
|
|
if d.IsDir() && d.Name() == "plans" {
|
|
return filepath.SkipDir
|
|
}
|
|
// Skip non-markdown files
|
|
if d.IsDir() || !strings.HasSuffix(d.Name(), ".md") {
|
|
return nil
|
|
}
|
|
// Get relative path from docs/
|
|
relPath, _ := filepath.Rel(docsDir, path)
|
|
info.DocsFiles = append(info.DocsFiles, relPath)
|
|
info.HasDocs = true
|
|
return nil
|
|
})
|
|
}
|
|
|
|
// Recursively scan KB/ directory for .md files
|
|
kbDir := filepath.Join(repo.Path, "KB")
|
|
if _, err := io.Local.List(kbDir); err == nil {
|
|
_ = filepath.WalkDir(kbDir, func(path string, d fs.DirEntry, err error) error {
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
if d.IsDir() || !strings.HasSuffix(d.Name(), ".md") {
|
|
return nil
|
|
}
|
|
relPath, _ := filepath.Rel(kbDir, path)
|
|
info.KBFiles = append(info.KBFiles, relPath)
|
|
info.HasDocs = true
|
|
return nil
|
|
})
|
|
}
|
|
|
|
return info
|
|
}
|