-
Notifications
You must be signed in to change notification settings - Fork 5
fix all problem and test the windows version #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |
| "fmt" | ||
| "net/url" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "runtime" | ||
| "strings" | ||
|
|
@@ -13,8 +14,8 @@ import ( | |
| ) | ||
|
|
||
| type ProviderConfig struct { | ||
| APIKey string `mapstructure:"api_key"` | ||
| Model string `mapstructure:"model"` | ||
| APIKey string `mapstructure:"api_key"` | ||
| Model string `mapstructure:"model"` | ||
| EndpointURL string `mapstructure:"endpoint_url"` | ||
| } | ||
|
|
||
|
|
@@ -37,7 +38,7 @@ func InitConfig() { | |
| viper.SetDefault("providers.copilot.model", "openai/gpt-5-mini") | ||
| } else { | ||
| viper.SetDefault("active_provider", "openai") | ||
| viper.SetDefault("providers.openai.model", "gpt-5-mini") | ||
| viper.SetDefault("providers.openai.model", "openai/gpt-5-mini") | ||
| } | ||
|
|
||
| viper.AutomaticEnv() | ||
|
|
@@ -90,9 +91,6 @@ func GetAPIKey() (string, error) { | |
| if cfg == nil { | ||
| InitConfig() | ||
| } | ||
| if cfg.ActiveProvider == "copilot" { | ||
| return LoadGitHubToken() | ||
| } | ||
|
|
||
| providerConfig, err := GetActiveProviderConfig() | ||
| if err != nil { | ||
|
|
@@ -213,12 +211,9 @@ func SetEndpoint(provider, endpoint string) error { | |
| } | ||
|
|
||
| func LoadGitHubToken() (string, error) { | ||
| if token := os.Getenv("GITHUB_TOKEN"); token != "" { | ||
| return token, nil | ||
| } | ||
|
|
||
| if token := os.Getenv("GITHUB_MODELS_TOKEN"); token != "" { | ||
| return token, nil | ||
| tok, err := tryGetTokenFromGHCLI() | ||
| if err == nil && tok != "" { | ||
| return tok, nil | ||
| } | ||
|
|
||
| configDir := getConfigDir() | ||
|
|
@@ -248,20 +243,30 @@ func LoadGitHubToken() (string, error) { | |
| } | ||
| } | ||
|
|
||
| return "", fmt.Errorf("GitHub token not found. Please set GITHUB_TOKEN or GITHUB_MODELS_TOKEN environment variable with a Personal Access Token that has 'models' scope") | ||
| return "", fmt.Errorf("GitHub token not found via 'gh auth token'; run 'gh auth login' to authenticate the GitHub CLI") | ||
| } | ||
| func tryGetTokenFromGHCLI() (string, error) { | ||
| out, err := exec.Command("gh", "auth", "token").Output() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| tok := strings.TrimSpace(string(out)) | ||
| if tok == "" { | ||
| return "", fmt.Errorf("gh returned empty token") | ||
| } | ||
| return tok, nil | ||
| } | ||
|
|
||
| func getConfigDir() string { | ||
| if xdgConfig := os.Getenv("XDG_CONFIG_HOME"); xdgConfig != "" { | ||
| return xdgConfig | ||
|
|
||
| // WARNING: The code is not woking | ||
| } else if runtime.GOOS == "windows" { | ||
| if localAppData := os.Getenv("LOCALAPPDATA"); localAppData != "" { | ||
| return localAppData | ||
| } else { | ||
| return filepath.Join(os.Getenv("HOME"), "AppData", "Local") | ||
| homeDir, err := os.UserHomeDir() | ||
| if err != nil { | ||
| fmt.Println("Error getting user home directory:", err) | ||
| os.Exit(1) | ||
| } | ||
|
Comment on lines
+265
to
268
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling if err != nil {
fmt.Fprintf(os.Stderr, "Warning: could not determine user home directory: %v. Using current directory for config.\n", err)
return "."
} |
||
| return filepath.Join(homeDir, "AppData", "Local") | ||
| } else { | ||
| return filepath.Join(os.Getenv("HOME"), ".config") | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change removes the logic for loading the GitHub token from
GITHUB_TOKENorGITHUB_MODELS_TOKENenvironment variables. This is a regression in functionality, as users who previously relied on these environment variables will find that they no longer work. It's a common and good practice to check for environment variables before falling back to other methods like executing an external command, as it's faster and provides a conventional configuration method.