summaryrefslogtreecommitdiff
path: root/internal/cli/description_cache.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-19 10:10:20 +0300
committerPaul Buetow <paul@buetow.org>2025-08-19 10:10:20 +0300
commite5cf30e8df255fe4d4d34db7fc076f26a2b84fee (patch)
tree64b625140b2db4a53f6de5cabe692f2d65272d58 /internal/cli/description_cache.go
parenta8db7af2a094a16393f0060e628310d4161b154f (diff)
feat(sync): sync repository descriptions across Codeberg and GitHub\n\nfeat(version): bump to v0.9.0v0.9.0
Diffstat (limited to 'internal/cli/description_cache.go')
-rw-r--r--internal/cli/description_cache.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/cli/description_cache.go b/internal/cli/description_cache.go
new file mode 100644
index 0000000..1cfc951
--- /dev/null
+++ b/internal/cli/description_cache.go
@@ -0,0 +1,38 @@
+package cli
+
+import (
+ "encoding/json"
+ "fmt"
+ "os"
+ "path/filepath"
+)
+
+// loadDescriptionCache loads the per-repo canonical description cache
+func loadDescriptionCache(workDir string) map[string]string {
+ cache := make(map[string]string)
+ cacheFile := filepath.Join(workDir, ".gitsyncer-descriptions-cache.json")
+ data, err := os.ReadFile(cacheFile)
+ if err != nil {
+ return cache
+ }
+ if err := json.Unmarshal(data, &cache); err != nil {
+ fmt.Printf("Warning: Failed to parse descriptions cache: %v\n", err)
+ return make(map[string]string)
+ }
+ fmt.Printf("Loaded descriptions cache with %d entries\n", len(cache))
+ return cache
+}
+
+// saveDescriptionCache saves the per-repo canonical description cache
+func saveDescriptionCache(workDir string, cache map[string]string) error {
+ cacheFile := filepath.Join(workDir, ".gitsyncer-descriptions-cache.json")
+ data, err := json.MarshalIndent(cache, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal descriptions cache: %w", err)
+ }
+ if err := os.WriteFile(cacheFile, data, 0644); err != nil {
+ return fmt.Errorf("failed to write descriptions cache: %w", err)
+ }
+ return nil
+}
+