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
|
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"codeberg.org/snonux/gitsyncer/internal/cli"
"codeberg.org/snonux/gitsyncer/internal/config"
)
var testCmd = &cobra.Command{
Use: "test",
Short: "Test authentication and configuration",
Long: `Test various aspects of the gitsyncer configuration including authentication tokens.`,
}
var testGitHubCmd = &cobra.Command{
Use: "github-token",
Short: "Test GitHub authentication",
Example: ` # Test GitHub token authentication
gitsyncer test github-token`,
Run: func(cmd *cobra.Command, args []string) {
os.Exit(cli.HandleTestGitHubToken())
},
}
var testCodebergCmd = &cobra.Command{
Use: "codeberg-token",
Short: "Test Codeberg authentication",
Example: ` # Test Codeberg token authentication
gitsyncer test codeberg-token`,
Run: func(cmd *cobra.Command, args []string) {
// TODO: Implement Codeberg token test
fmt.Println("Codeberg token test not yet implemented")
os.Exit(1)
},
}
var testConfigCmd = &cobra.Command{
Use: "config",
Short: "Validate configuration file",
Example: ` # Validate configuration
gitsyncer test config
# Test specific config file
gitsyncer test config -c ~/my-config.json`,
Run: func(cmd *cobra.Command, args []string) {
// Try to load and validate config
cfg, err := config.Load(cfgFile)
if err != nil {
fmt.Fprintf(os.Stderr, "Configuration validation failed: %v\n", err)
os.Exit(1)
}
fmt.Println("Configuration validation successful!")
fmt.Printf(" Organizations: %d\n", len(cfg.Organizations))
fmt.Printf(" Repositories: %d\n", len(cfg.Repositories))
// Check for common issues
hasGitHub := false
hasCodeberg := false
for _, org := range cfg.Organizations {
if org.Host == "git@github.com" {
hasGitHub = true
if org.GitHubToken == "" {
fmt.Println(" ⚠️ Warning: GitHub organization without token")
}
}
if org.Host == "git@codeberg.org" {
hasCodeberg = true
if org.CodebergToken == "" {
fmt.Println(" ⚠️ Warning: Codeberg organization without token")
}
}
}
if !hasGitHub && !hasCodeberg {
fmt.Println(" ⚠️ Warning: No GitHub or Codeberg organizations configured")
}
os.Exit(0)
},
}
func init() {
rootCmd.AddCommand(testCmd)
testCmd.AddCommand(testGitHubCmd)
testCmd.AddCommand(testCodebergCmd)
testCmd.AddCommand(testConfigCmd)
}
|