fix(multi-repo): filter issues by prefix when flushing from non-primary repos (GH #437)
In multi-repo mode, non-primary repos incorrectly wrote ALL issues to their local issues.jsonl, including foreign issues from other repos. This caused prefix mismatch errors on subsequent imports. The fix adds prefix filtering in flushToJSONLWithState() when: 1. Multi-repo mode is configured (repos.primary set) 2. Current repo is not the primary repo 3. The repo has a configured issue_prefix Issues not matching the local prefix are filtered out before writing to JSONL. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -11,10 +11,12 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/steveyegge/beads/internal/beads"
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/debug"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
@@ -685,6 +687,46 @@ func flushToJSONLWithState(state flushState) {
|
||||
issues = append(issues, issue)
|
||||
}
|
||||
|
||||
// Filter issues by prefix in multi-repo mode for non-primary repos (fixes GH #437)
|
||||
// In multi-repo mode, non-primary repos should only export issues that match
|
||||
// their own prefix. Issues from other repos (hydrated for unified view) should
|
||||
// NOT be written to the local JSONL.
|
||||
multiRepo := config.GetMultiRepoConfig()
|
||||
if multiRepo != nil {
|
||||
// Get our configured prefix
|
||||
prefix, prefixErr := store.GetConfig(ctx, "issue_prefix")
|
||||
if prefixErr == nil && prefix != "" {
|
||||
// Determine if we're the primary repo
|
||||
cwd, _ := os.Getwd()
|
||||
primaryPath := multiRepo.Primary
|
||||
if primaryPath == "" || primaryPath == "." {
|
||||
primaryPath = cwd
|
||||
}
|
||||
|
||||
// Normalize paths for comparison
|
||||
absCwd, _ := filepath.Abs(cwd)
|
||||
absPrimary, _ := filepath.Abs(primaryPath)
|
||||
|
||||
isPrimary := absCwd == absPrimary
|
||||
|
||||
if !isPrimary {
|
||||
// Filter to only issues matching our prefix
|
||||
filtered := make([]*types.Issue, 0, len(issues))
|
||||
prefixWithDash := prefix
|
||||
if !strings.HasSuffix(prefixWithDash, "-") {
|
||||
prefixWithDash = prefix + "-"
|
||||
}
|
||||
for _, issue := range issues {
|
||||
if strings.HasPrefix(issue.ID, prefixWithDash) {
|
||||
filtered = append(filtered, issue)
|
||||
}
|
||||
}
|
||||
debug.Logf("multi-repo filter: %d issues -> %d (prefix %s)", len(issues), len(filtered), prefix)
|
||||
issues = filtered
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write atomically using common helper
|
||||
exportedIDs, err := writeJSONLAtomic(jsonlPath, issues)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user