fix: respect allowed_prefixes config during import (gt-2z6s)

The buildAllowedPrefixSet function now parses the allowed_prefixes config
and includes those prefixes when validating imports. This allows mol-*
prefixes to be imported without errors when configured.

Config example: bd config set allowed_prefixes "gt-,mol-"
This commit is contained in:
Steve Yegge
2025-12-24 14:28:23 -08:00
parent f28785d2dc
commit 25402184a6
2 changed files with 32 additions and 4 deletions
+31 -4
View File
@@ -216,8 +216,11 @@ func handlePrefixMismatch(ctx context.Context, sqliteStore *sqlite.SQLiteStorage
result.ExpectedPrefix = configuredPrefix
// gt-2z6s: Read allowed_prefixes config for additional valid prefixes (e.g., mol-*)
allowedPrefixesConfig, _ := sqliteStore.GetConfig(ctx, "allowed_prefixes")
// GH#686: In multi-repo mode, allow all prefixes (nil = allow all)
allowedPrefixes := buildAllowedPrefixSet(configuredPrefix)
allowedPrefixes := buildAllowedPrefixSet(configuredPrefix, allowedPrefixesConfig)
if allowedPrefixes == nil {
return issues, nil
}
@@ -235,7 +238,14 @@ func handlePrefixMismatch(ctx context.Context, sqliteStore *sqlite.SQLiteStorage
// GH#422: Check if issue ID starts with configured prefix directly
// rather than extracting/guessing. This handles multi-hyphen prefixes
// like "asianops-audit-" correctly.
prefixMatches := strings.HasPrefix(issue.ID, configuredPrefix+"-")
// gt-2z6s: Also check against allowed_prefixes config
prefixMatches := false
for prefix := range allowedPrefixes {
if strings.HasPrefix(issue.ID, prefix+"-") {
prefixMatches = true
break
}
}
if !prefixMatches {
// Extract prefix for error reporting (best effort)
prefix := utils.ExtractIssuePrefix(issue.ID)
@@ -970,9 +980,26 @@ func validateNoDuplicateExternalRefs(issues []*types.Issue, clearDuplicates bool
// buildAllowedPrefixSet returns allowed prefixes, or nil to allow all (GH#686).
// In multi-repo mode, additional repos have their own prefixes - allow all.
func buildAllowedPrefixSet(primaryPrefix string) map[string]bool {
// gt-2z6s: Also accepts allowedPrefixesConfig (comma-separated list like "gt-,mol-").
func buildAllowedPrefixSet(primaryPrefix string, allowedPrefixesConfig string) map[string]bool {
if config.GetMultiRepoConfig() != nil {
return nil // Multi-repo: allow all prefixes
}
return map[string]bool{primaryPrefix: true}
allowed := map[string]bool{primaryPrefix: true}
// gt-2z6s: Parse allowed_prefixes config (comma-separated, with or without trailing -)
if allowedPrefixesConfig != "" {
for _, prefix := range strings.Split(allowedPrefixesConfig, ",") {
prefix = strings.TrimSpace(prefix)
if prefix == "" {
continue
}
// Normalize: remove trailing - if present (we match without it)
prefix = strings.TrimSuffix(prefix, "-")
allowed[prefix] = true
}
}
return allowed
}