diff options
| author | Paul Buetow <paul@buetow.org> | 2025-08-19 10:10:20 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-08-19 10:10:20 +0300 |
| commit | e5cf30e8df255fe4d4d34db7fc076f26a2b84fee (patch) | |
| tree | 64b625140b2db4a53f6de5cabe692f2d65272d58 /internal/cli/sync_handlers.go | |
| parent | a8db7af2a094a16393f0060e628310d4161b154f (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/sync_handlers.go')
| -rw-r--r-- | internal/cli/sync_handlers.go | 142 |
1 files changed, 93 insertions, 49 deletions
diff --git a/internal/cli/sync_handlers.go b/internal/cli/sync_handlers.go index 1878808..09b993a 100644 --- a/internal/cli/sync_handlers.go +++ b/internal/cli/sync_handlers.go @@ -31,11 +31,17 @@ func HandleSync(cfg *config.Config, flags *Flags) int { syncer := sync.New(cfg, flags.WorkDir) syncer.SetBackupEnabled(flags.Backup) - if err := syncer.SyncRepository(flags.SyncRepo); err != nil { - log.Fatal("Sync failed:", err) - return 1 - } - return 0 + if err := syncer.SyncRepository(flags.SyncRepo); err != nil { + log.Fatal("Sync failed:", err) + return 1 + } + // Also sync descriptions for this single repository + descCache := loadDescriptionCache(flags.WorkDir) + syncRepoDescriptions(cfg, flags.DryRun, flags.SyncRepo, "", "", descCache) + if err := saveDescriptionCache(flags.WorkDir, descCache); err != nil { + fmt.Printf("Warning: Failed to save descriptions cache: %v\n", err) + } + return 0 } // HandleSyncAll handles syncing all configured repositories @@ -65,9 +71,11 @@ func HandleSyncAll(cfg *config.Config, flags *Flags) int { } } - syncer := sync.New(cfg, flags.WorkDir) - syncer.SetBackupEnabled(flags.Backup) - successCount := 0 + syncer := sync.New(cfg, flags.WorkDir) + syncer.SetBackupEnabled(flags.Backup) + successCount := 0 + // Load descriptions cache + descCache := loadDescriptionCache(flags.WorkDir) for i, repo := range cfg.Repositories { fmt.Printf("\n[%d/%d] Syncing %s...\n", i+1, len(cfg.Repositories), repo) @@ -89,14 +97,20 @@ func HandleSyncAll(cfg *config.Config, flags *Flags) int { } } - if err := syncer.SyncRepository(repo); err != nil { - fmt.Printf("ERROR: Failed to sync %s: %v\n", repo, err) - fmt.Printf("Stopping sync due to error.\n") - return 1 - } - successCount++ - } - + if err := syncer.SyncRepository(repo); err != nil { + fmt.Printf("ERROR: Failed to sync %s: %v\n", repo, err) + fmt.Printf("Stopping sync due to error.\n") + return 1 + } + successCount++ + // Sync descriptions after repo sync + syncRepoDescriptions(cfg, flags.DryRun, repo, "", "", descCache) + } + // Save descriptions cache + if err := saveDescriptionCache(flags.WorkDir, descCache); err != nil { + fmt.Printf("Warning: Failed to save descriptions cache: %v\n", err) + } + fmt.Printf("\nSuccessfully synced all %d repositories!\n", successCount) // Print abandoned branches summary @@ -164,8 +178,8 @@ func HandleSyncCodebergPublic(cfg *config.Config, flags *Flags) int { return 0 } - // Show the repositories that will be synced - showReposToSync(repoNames) + // Show the repositories that will be synced + showReposToSync(repoNames) if flags.DryRun { fmt.Printf("\n[DRY RUN] Would sync %d repositories from Codeberg to GitHub\n", len(repoNames)) @@ -177,9 +191,9 @@ func HandleSyncCodebergPublic(cfg *config.Config, flags *Flags) int { } } - if !flags.DryRun { - return syncCodebergRepos(cfg, flags, repos, repoNames) - } + if !flags.DryRun { + return syncCodebergRepos(cfg, flags, repos, repoNames) + } return 0 } @@ -214,8 +228,8 @@ func HandleSyncGitHubPublic(cfg *config.Config, flags *Flags) int { return 0 } - // Show the repositories that will be synced - showReposToSync(repoNames) + // Show the repositories that will be synced + showReposToSync(repoNames) if flags.DryRun { fmt.Printf("\n[DRY RUN] Would sync %d repositories from GitHub to Codeberg\n", len(repoNames)) @@ -225,9 +239,9 @@ func HandleSyncGitHubPublic(cfg *config.Config, flags *Flags) int { return 0 } - if !flags.DryRun { - return syncGitHubRepos(cfg, flags, repos, repoNames) - } + if !flags.DryRun { + return syncGitHubRepos(cfg, flags, repos, repoNames) + } return 0 } @@ -333,7 +347,10 @@ func syncCodebergRepos(cfg *config.Config, flags *Flags, repos []codeberg.Reposi } } - fmt.Printf("\nStarting sync of %d repositories...\n", len(repoNames)) + fmt.Printf("\nStarting sync of %d repositories...\n", len(repoNames)) + + // Load descriptions cache + descCache := loadDescriptionCache(flags.WorkDir) syncer := sync.New(cfg, flags.WorkDir) syncer.SetBackupEnabled(flags.Backup) @@ -345,8 +362,8 @@ func syncCodebergRepos(cfg *config.Config, flags *Flags, repos []codeberg.Reposi repoMap[repo.Name] = repo } - for i, repoName := range repoNames { - fmt.Printf("\n[%d/%d] Syncing %s...\n", i+1, len(repoNames), repoName) + for i, repoName := range repoNames { + fmt.Printf("\n[%d/%d] Syncing %s...\n", i+1, len(repoNames), repoName) // Create GitHub repo if needed if hasGithubClient && flags.CreateGitHubRepos { @@ -363,15 +380,27 @@ func syncCodebergRepos(cfg *config.Config, flags *Flags, repos []codeberg.Reposi } } - if err := syncer.SyncRepository(repoName); err != nil { - fmt.Printf("ERROR: Failed to sync %s: %v\n", repoName, err) - fmt.Printf("Stopping sync due to error.\n") - return 1 - } - successCount++ - } - - fmt.Printf("\n=== Summary ===\n") + if err := syncer.SyncRepository(repoName); err != nil { + fmt.Printf("ERROR: Failed to sync %s: %v\n", repoName, err) + fmt.Printf("Stopping sync due to error.\n") + return 1 + } + successCount++ + + // After syncing, sync descriptions according to precedence + if cbRepo, ok := repoMap[repoName]; ok { + syncRepoDescriptions(cfg, flags.DryRun, repoName, cbRepo.Description, "", descCache) + } else { + syncRepoDescriptions(cfg, flags.DryRun, repoName, "", "", descCache) + } + } + + // Save descriptions cache + if err := saveDescriptionCache(flags.WorkDir, descCache); err != nil { + fmt.Printf("Warning: Failed to save descriptions cache: %v\n", err) + } + + fmt.Printf("\n=== Summary ===\n") fmt.Printf("Successfully synced: %d repositories\n", successCount) // Print abandoned branches summary @@ -426,7 +455,10 @@ func syncGitHubRepos(cfg *config.Config, flags *Flags, repos []github.Repository } } - fmt.Printf("\nStarting sync of %d repositories...\n", len(repoNames)) + fmt.Printf("\nStarting sync of %d repositories...\n", len(repoNames)) + + // Load descriptions cache + descCache := loadDescriptionCache(flags.WorkDir) syncer := sync.New(cfg, flags.WorkDir) syncer.SetBackupEnabled(flags.Backup) @@ -438,8 +470,8 @@ func syncGitHubRepos(cfg *config.Config, flags *Flags, repos []github.Repository repoMap[repo.Name] = repo } - for i, repoName := range repoNames { - fmt.Printf("\n[%d/%d] Syncing %s...\n", i+1, len(repoNames), repoName) + for i, repoName := range repoNames { + fmt.Printf("\n[%d/%d] Syncing %s...\n", i+1, len(repoNames), repoName) // Create Codeberg repo if needed if hasCodebergClient && flags.CreateCodebergRepos { @@ -456,13 +488,25 @@ func syncGitHubRepos(cfg *config.Config, flags *Flags, repos []github.Repository } } - if err := syncer.SyncRepository(repoName); err != nil { - fmt.Printf("ERROR: Failed to sync %s: %v\n", repoName, err) - fmt.Printf("Stopping sync due to error.\n") - return 1 - } - successCount++ - } + if err := syncer.SyncRepository(repoName); err != nil { + fmt.Printf("ERROR: Failed to sync %s: %v\n", repoName, err) + fmt.Printf("Stopping sync due to error.\n") + return 1 + } + successCount++ + + // After syncing, sync descriptions according to precedence + if ghRepo, ok := repoMap[repoName]; ok { + syncRepoDescriptions(cfg, flags.DryRun, repoName, "", ghRepo.Description, descCache) + } else { + syncRepoDescriptions(cfg, flags.DryRun, repoName, "", "", descCache) + } + } + + // Save descriptions cache + if err := saveDescriptionCache(flags.WorkDir, descCache); err != nil { + fmt.Printf("Warning: Failed to save descriptions cache: %v\n", err) + } fmt.Printf("\n=== Summary ===\n") fmt.Printf("Successfully synced: %d repositories\n", successCount) @@ -510,4 +554,4 @@ func ShowFullSyncMessage() { fmt.Println(" - Create missing GitHub repositories") fmt.Println(" - Create missing Codeberg repositories (when implemented)") fmt.Println() -}
\ No newline at end of file +} |
