Documentation
¶
Index ¶
- Constants
- func GetHierarchyDepth(id string) int
- func GetPrefixList(prefixes map[string]int) []string
- func GroupByDepth(issues []*types.Issue) map[int][]*types.Issue
- func IssueDataChanged(existing *types.Issue, updates map[string]interface{}) bool
- func RenameImportedIssuePrefixes(issues []*types.Issue, targetPrefix string) (map[string]string, error)
- func SortByDepth(issues []*types.Issue)
- type Options
- type OrphanHandling
- type Result
Constants ¶
const ( // OrphanStrict fails import on missing parent (safest) OrphanStrict = sqlite.OrphanStrict // OrphanResurrect auto-resurrects missing parents from JSONL history OrphanResurrect = sqlite.OrphanResurrect // OrphanSkip skips orphaned issues with warning OrphanSkip = sqlite.OrphanSkip // OrphanAllow imports orphans without validation (default, works around bugs) OrphanAllow = sqlite.OrphanAllow )
Variables ¶
This section is empty.
Functions ¶
func GetHierarchyDepth ¶
GetHierarchyDepth returns the depth of a hierarchical issue ID. Depth is determined by the number of dots in the ID. Examples:
- "bd-abc123" → 0 (top-level)
- "bd-abc123.1" → 1 (one level deep)
- "bd-abc123.1.2" → 2 (two levels deep)
func GetPrefixList ¶
func GroupByDepth ¶
GroupByDepth groups issues into buckets by hierarchy depth. Returns a map where keys are depth levels and values are slices of issues at that depth. Maximum supported depth is 3 (as per beads spec).
func IssueDataChanged ¶
IssueDataChanged checks if an issue's data has changed from the database version
func RenameImportedIssuePrefixes ¶
func RenameImportedIssuePrefixes(issues []*types.Issue, targetPrefix string) (map[string]string, error)
RenameImportedIssuePrefixes renames all issues and their references to match the target prefix.
This function handles three ID formats:
- Sequential numeric IDs: "old-123" → "new-123"
- Hash-based IDs: "old-abc1" → "new-abc1"
- Hierarchical IDs: "old-abc1.2.3" → "new-abc1.2.3"
The suffix (everything after "prefix-") is preserved during rename, only the prefix changes. This preserves issue identity across prefix renames while maintaining parent-child relationships in hierarchical IDs (dots denote subtask nesting, e.g., bd-abc1.2 is child 2 of bd-abc1).
All text references to old IDs in issue fields (title, description, notes, etc.) and dependency relationships are updated to use the new IDs.
Returns the oldID → newID mapping so callers can persist the rename beyond the database (e.g., tombstone the old IDs so the shared JSONL heals too).
func SortByDepth ¶
SortByDepth sorts issues by hierarchy depth (shallow to deep) with stable sorting. Issues at the same depth are sorted by ID for deterministic ordering. This ensures parent issues are processed before their children.
Types ¶
type Options ¶
type Options struct {
DryRun bool // Preview changes without applying them
SkipUpdate bool // Skip updating existing issues (create-only mode)
Strict bool // Fail on any error (dependencies, labels, etc.)
RenameOnImport bool // Rename imported issues to match database prefix
AutoAdoptPrefix bool // Adopt a single upstream prefix from the repo's own sync JSONL: repoint DB config + migrate local issues (BeadsLog-b4p)
AdoptTargetPrefix string // The committed config.yaml issue-prefix (the authored migration "signature"); auto-adopt only fires toward this exact prefix (BeadsLog-b4p)
SkipPrefixValidation bool // Skip prefix validation (for auto-import)
OrphanHandling OrphanHandling // How to handle missing parent issues (default: allow)
ClearDuplicateExternalRefs bool // Clear duplicate external_ref values instead of erroring
ProtectLocalExportIDs map[string]time.Time // IDs from left snapshot with timestamps for timestamp-aware protection (GH#865)
}
Options contains import configuration
type OrphanHandling ¶
type OrphanHandling = sqlite.OrphanHandling
OrphanHandling is an alias to sqlite.OrphanHandling for convenience
type Result ¶
type Result struct {
Created int // New issues created
Updated int // Existing issues updated
Unchanged int // Existing issues that matched exactly (idempotent)
Skipped int // Issues skipped (duplicates, errors)
Collisions int // Collisions detected
IDMapping map[string]string // Mapping of remapped IDs (old -> new)
CollisionIDs []string // IDs that collided
PrefixMismatch bool // Prefix mismatch detected
ExpectedPrefix string // Database configured prefix
MismatchPrefixes map[string]int // Map of mismatched prefixes to count
SkippedDependencies []string // Dependencies skipped due to FK constraint violations
AdoptedPrefix string // Non-empty when auto-adopt repointed the DB prefix to this upstream prefix (BeadsLog-b4p)
AdoptedFrom string // The previous prefix replaced by auto-adopt
MigratedLocal int // Count of local issues migrated to the adopted prefix
}
Result contains statistics about the import operation
func ImportIssues ¶
func ImportIssues(ctx context.Context, dbPath string, store storage.Storage, issues []*types.Issue, opts Options) (*Result, error)
ImportIssues handles the core import logic used by both manual and auto-import. This function: - Works with existing storage or opens direct SQLite connection if needed - Detects and handles collisions - Imports issues, dependencies, labels, and comments - Returns detailed results
The caller is responsible for: - Reading and parsing JSONL into issues slice - Displaying results to the user - Setting metadata (e.g., last_import_hash)
Parameters: - ctx: Context for cancellation - dbPath: Path to SQLite database file - store: Existing storage instance (can be nil for direct mode) - issues: Parsed issues from JSONL - opts: Import options