refactor: deduplicate FindJSONLInDir function (bd-8a5)
Extract shared JSONL file discovery logic to internal/utils/path.go. Both autoimport and beads packages now use this shared implementation. Changes: - Add utils.FindJSONLInDir with common logic - Update autoimport.go to use utils.FindJSONLInDir - Update beads.go to delegate to utils.FindJSONLInDir - Update server_export_import_auto.go to use utils.FindJSONLInDir - Move FindJSONLInDir test to utils/path_test.go - Fix pre-existing duplicate countIssuesInJSONLFile in init.go 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -278,41 +278,8 @@ func FindJSONLPath(dbPath string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Get the directory containing the database
|
||||
dbDir := filepath.Dir(dbPath)
|
||||
|
||||
// Look for existing .jsonl files in the .beads directory
|
||||
pattern := filepath.Join(dbDir, "*.jsonl")
|
||||
matches, err := filepath.Glob(pattern)
|
||||
if err == nil && len(matches) > 0 {
|
||||
// bd-6xd: Prefer issues.jsonl over beads.jsonl (canonical name)
|
||||
for _, match := range matches {
|
||||
if filepath.Base(match) == "issues.jsonl" {
|
||||
return match
|
||||
}
|
||||
}
|
||||
// bd-tqo: Fall back to beads.jsonl for legacy support
|
||||
for _, match := range matches {
|
||||
if filepath.Base(match) == "beads.jsonl" {
|
||||
return match
|
||||
}
|
||||
}
|
||||
// bd-tqo: Skip deletions.jsonl and merge artifacts to prevent corruption
|
||||
for _, match := range matches {
|
||||
base := filepath.Base(match)
|
||||
if base == "deletions.jsonl" ||
|
||||
base == "beads.base.jsonl" ||
|
||||
base == "beads.left.jsonl" ||
|
||||
base == "beads.right.jsonl" {
|
||||
continue
|
||||
}
|
||||
return match
|
||||
}
|
||||
// If only deletions/merge files exist, fall through to default
|
||||
}
|
||||
|
||||
// bd-6xd: Default to issues.jsonl (canonical name)
|
||||
return filepath.Join(dbDir, "issues.jsonl")
|
||||
// Get the directory containing the database and delegate to shared utility
|
||||
return utils.FindJSONLInDir(filepath.Dir(dbPath))
|
||||
}
|
||||
|
||||
// DatabaseInfo contains information about a discovered beads database
|
||||
|
||||
Reference in New Issue
Block a user