diff options
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | internal/cli/sync_handlers.go | 43 | ||||
| -rw-r--r-- | internal/cmd/sync.go | 2 | ||||
| -rw-r--r-- | internal/version/version.go | 2 |
4 files changed, 47 insertions, 2 deletions
@@ -2,7 +2,7 @@ GitSyncer is a tool for synchronizing git repositories between multiple organizations (e.g., GitHub and Codeberg). It automatically keeps all branches in sync across different git hosting platforms. -It has been vibe coded mainly using Claude Code CLI. +It has been vibe coded mainly vibe coded using Claude Code CLI. ## Documentation diff --git a/internal/cli/sync_handlers.go b/internal/cli/sync_handlers.go index d87d771..1878808 100644 --- a/internal/cli/sync_handlers.go +++ b/internal/cli/sync_handlers.go @@ -21,6 +21,14 @@ func HandleSync(cfg *config.Config, flags *Flags) int { } } + // If create-codeberg-repos is enabled, create the repo if needed + if flags.CreateCodebergRepos { + if err := createCodebergRepoIfNeeded(cfg, flags.SyncRepo); err != nil { + fmt.Printf("ERROR: %v\n", err) + return 1 + } + } + syncer := sync.New(cfg, flags.WorkDir) syncer.SetBackupEnabled(flags.Backup) if err := syncer.SyncRepository(flags.SyncRepo); err != nil { @@ -47,6 +55,16 @@ func HandleSyncAll(cfg *config.Config, flags *Flags) int { } } + // Initialize Codeberg client if needed + var codebergClient codeberg.Client + var hasCodebergClient bool + if flags.CreateCodebergRepos { + if client := initCodebergClient(cfg); client != nil { + codebergClient = *client + hasCodebergClient = true + } + } + syncer := sync.New(cfg, flags.WorkDir) syncer.SetBackupEnabled(flags.Backup) successCount := 0 @@ -63,6 +81,14 @@ func HandleSyncAll(cfg *config.Config, flags *Flags) int { } } + // Create Codeberg repo if needed + if hasCodebergClient { + fmt.Printf("Checking/creating Codeberg repository %s...\n", repo) + if err := codebergClient.CreateRepo(repo, fmt.Sprintf("Mirror of %s", repo), false); err != nil { + fmt.Printf("Warning: Failed to create Codeberg repo %s: %v\n", repo, err) + } + } + 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") @@ -225,6 +251,23 @@ func createGitHubRepoIfNeeded(cfg *config.Config, repoName string) error { return githubClient.CreateRepo(repoName, fmt.Sprintf("Mirror of %s", repoName), false) } +func createCodebergRepoIfNeeded(cfg *config.Config, repoName string) error { + codebergOrg := cfg.FindCodebergOrg() + if codebergOrg == nil { + return nil + } + + fmt.Printf("Initializing Codeberg client for organization: %s\n", codebergOrg.Name) + codebergClient := codeberg.NewClient(codebergOrg.Name, codebergOrg.CodebergToken) + if !codebergClient.HasToken() { + fmt.Println("Warning: No Codeberg token found. Cannot create repository.") + return nil + } + + fmt.Println("Checking/creating Codeberg repository...") + return codebergClient.CreateRepo(repoName, fmt.Sprintf("Mirror of %s", repoName), false) +} + func initGitHubClient(cfg *config.Config) *github.Client { githubOrg := cfg.FindGitHubOrg() if githubOrg == nil { diff --git a/internal/cmd/sync.go b/internal/cmd/sync.go index 9efa432..abedb7e 100644 --- a/internal/cmd/sync.go +++ b/internal/cmd/sync.go @@ -196,5 +196,7 @@ func buildFlags() *cli.Flags { NoCheckReleases: noReleases, AutoCreateReleases: autoCreate, AIReleaseNotes: !noAIReleaseNotes, + CreateGitHubRepos: createRepos, + CreateCodebergRepos: createRepos, } }
\ No newline at end of file diff --git a/internal/version/version.go b/internal/version/version.go index 622c509..b45fdc1 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -7,7 +7,7 @@ import ( var ( // Version is the current version of gitsyncer - Version = "0.7.2" + Version = "0.8.0" // GitCommit is the git commit hash at build time GitCommit = "unknown" |
