-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstore_config.go
More file actions
99 lines (85 loc) · 2.22 KB
/
store_config.go
File metadata and controls
99 lines (85 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"os"
"path/filepath"
"strings"
)
// SetPrefix changes the store prefix and updates all issue IDs
func (s *Store) SetPrefix(newPrefix string) error {
oldPrefix := s.Prefix
newPrefix = strings.TrimSuffix(newPrefix, "-")
// Build mapping of old ID to new ID
idMap := make(map[string]string)
for oldID := range s.Issues {
// Extract nanoid suffix
var suffix string
if oldPrefix == "" {
// Old ID has no prefix, entire ID is the nanoid
suffix = oldID
} else {
// Old ID has format "prefix-nanoid", extract after prefix and hyphen
suffix = strings.TrimPrefix(oldID[len(oldPrefix):], "-")
}
// Build new ID
var newID string
if newPrefix == "" {
// New prefix is empty, ID is just the nanoid
newID = suffix
} else {
// New prefix exists, format as "prefix-nanoid"
newID = newPrefix + "-" + suffix
}
idMap[oldID] = newID
}
// Create new issues map with updated IDs
newIssues := make(map[string]*Issue)
for oldID, issue := range s.Issues {
newID := idMap[oldID]
issue.ID = newID
// Update DependsOn references
for i, depID := range issue.DependsOn {
if newDepID, ok := idMap[depID]; ok {
issue.DependsOn[i] = newDepID
}
}
// Update Blocks references
for i, blockID := range issue.Blocks {
if newBlockID, ok := idMap[blockID]; ok {
issue.Blocks[i] = newBlockID
}
}
newIssues[newID] = issue
}
s.Prefix = newPrefix
s.Issues = newIssues
return nil
}
// GetStoreFilePath returns the path to the mint-issues.yaml file
// Checks MINT_STORE_FILE env var first (for tests)
// Then looks for .git walking up from current directory
// Falls back to current directory if no .git found
func GetStoreFilePath() (string, error) {
// Check env var first (for tests)
if envPath := os.Getenv("MINT_STORE_FILE"); envPath != "" {
return envPath, nil
}
cwd, err := os.Getwd()
if err != nil {
return "", err
}
// Walk up looking for .git
dir := cwd
for {
gitPath := filepath.Join(dir, ".git")
if _, err := os.Stat(gitPath); err == nil {
return filepath.Join(dir, "mint-issues.yaml"), nil
}
parent := filepath.Dir(dir)
if parent == dir {
// Reached root
break
}
dir = parent
}
return filepath.Join(cwd, "mint-issues.yaml"), nil
}