Implement external_ref as primary matching key for import updates (bd-1022)
- Add GetIssueByExternalRef() query function to storage interface and implementations - Update DetectCollisions() to prioritize external_ref matching over ID matching - Modify upsertIssues() to handle external_ref matches in import logic - Add index on external_ref column for performance - Add comprehensive tests for external_ref matching in both collision detection and import - Enables re-syncing from external systems (Jira, GitHub, Linear) without duplicates - Preserves local issues (no external_ref) from being overwritten
This commit is contained in:
@@ -278,6 +278,35 @@ func (m *MemoryStorage) GetIssue(ctx context.Context, id string) (*types.Issue,
|
||||
return &issueCopy, nil
|
||||
}
|
||||
|
||||
// GetIssueByExternalRef retrieves an issue by external reference
|
||||
func (m *MemoryStorage) GetIssueByExternalRef(ctx context.Context, externalRef string) (*types.Issue, error) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
|
||||
// Linear search through all issues to find match by external_ref
|
||||
for _, issue := range m.issues {
|
||||
if issue.ExternalRef != nil && *issue.ExternalRef == externalRef {
|
||||
// Return a copy to avoid mutations
|
||||
issueCopy := *issue
|
||||
|
||||
// Attach dependencies
|
||||
if deps, ok := m.dependencies[issue.ID]; ok {
|
||||
issueCopy.Dependencies = deps
|
||||
}
|
||||
|
||||
// Attach labels
|
||||
if labels, ok := m.labels[issue.ID]; ok {
|
||||
issueCopy.Labels = labels
|
||||
}
|
||||
|
||||
return &issueCopy, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Not found
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// UpdateIssue updates fields on an issue
|
||||
func (m *MemoryStorage) UpdateIssue(ctx context.Context, id string, updates map[string]interface{}, actor string) error {
|
||||
m.mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user