diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-23 23:38:55 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-23 23:38:55 +0300 |
| commit | 42d3df9fe18663f5c6f7067b964f0b09071910e6 (patch) | |
| tree | fff4b4708115caa29c4daadc1444e02ab14c41b7 /cmd | |
| parent | 006724744a943aad877a92406a5e2b4d5d12acd3 (diff) | |
Add debugging features and improve error handling
- Add --test-github-token flag to validate GitHub authentication
- Improve error messages for 401 authentication failures
- Add merge conflict detection before sync attempts
- Stop sync on first error for easier debugging
- Add GitHub repo creation support for --sync and --sync-all commands
- Add detailed token loading debug output
- Create test script for GitHub token validation
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/gitsyncer/main.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/cmd/gitsyncer/main.go b/cmd/gitsyncer/main.go index b60fda0..6e5ecac 100644 --- a/cmd/gitsyncer/main.go +++ b/cmd/gitsyncer/main.go @@ -6,6 +6,7 @@ import ( "log" "os" "path/filepath" + "strings" "github.com/paul/gitsyncer/internal/codeberg" "github.com/paul/gitsyncer/internal/config" @@ -26,6 +27,7 @@ func main() { createGitHubRepos bool dryRun bool workDir string + testGitHubToken bool ) // Define command line flags @@ -41,6 +43,7 @@ func main() { flag.BoolVar(&createGitHubRepos, "create-github-repos", false, "automatically create missing GitHub repositories") flag.BoolVar(&dryRun, "dry-run", false, "show what would be synced without actually syncing") flag.StringVar(&workDir, "work-dir", ".gitsyncer-work", "working directory for cloning repositories") + flag.BoolVar(&testGitHubToken, "test-github-token", false, "test GitHub token authentication") flag.Parse() // Handle version flag @@ -48,6 +51,33 @@ func main() { fmt.Println(version.GetVersion()) os.Exit(0) } + + // Handle test GitHub token flag + if testGitHubToken { + fmt.Println("Testing GitHub token authentication...") + client := github.NewClient("", "snonux") // Empty token to trigger loading from env/file + if !client.HasToken() { + fmt.Println("ERROR: No GitHub token found!") + fmt.Println("Please set GITHUB_TOKEN environment variable or create ~/.gitsyncer_github_token file") + os.Exit(1) + } + + // Test the token by checking a known repo + exists, err := client.RepoExists("gitsyncer") + if err != nil { + fmt.Printf("ERROR: Token test failed: %v\n", err) + if strings.Contains(err.Error(), "401") { + fmt.Println("\nThe token is invalid or expired. Please check:") + fmt.Println("1. Token has not expired") + fmt.Println("2. Token has 'repo' scope") + fmt.Println("3. Token was not revoked") + } + os.Exit(1) + } + + fmt.Printf("SUCCESS: Token is valid! Repository check returned: %v\n", exists) + os.Exit(0) + } // Determine config file path if configPath == "" { @@ -337,6 +367,7 @@ func main() { fmt.Println(" gitsyncer --sync-codeberg-public Sync all public Codeberg repositories") fmt.Println(" gitsyncer --list-orgs List configured organizations") fmt.Println(" gitsyncer --list-repos List configured repositories") + fmt.Println(" gitsyncer --test-github-token Test GitHub token authentication") fmt.Println(" gitsyncer --version Show version information") fmt.Println("\nOptions:") fmt.Println(" --config <path> Path to configuration file") |
