Skip to content

Commit 63c9851

Browse files
committed
refactor(config): simplify GetAPIKey logic for copilot provider
1 parent 3f3f937 commit 63c9851

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

internal/config/config.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,18 @@ func GetActiveProviderConfig() (*ProviderConfig, error) {
8484

8585
// GetAPIKey returns the API key for the active provider.
8686
func GetAPIKey() (string, error) {
87-
providerConfig, err := GetActiveProviderConfig()
88-
if err != nil {
89-
// If config for the provider doesn't exist, that's an issue.
90-
// However, for copilot, we can try to load the token directly.
91-
if cfg.ActiveProvider == "copilot" {
92-
return LoadGitHubToken()
93-
}
94-
return "", err
87+
if cfg == nil {
88+
InitConfig()
9589
}
96-
97-
// Special handling for copilot to always prefer a freshly loaded token.
9890
if cfg.ActiveProvider == "copilot" {
9991
return LoadGitHubToken()
10092
}
10193

94+
providerConfig, err := GetActiveProviderConfig()
95+
if err != nil {
96+
return "", err
97+
}
98+
10299
if providerConfig.APIKey == "" {
103100
return "", fmt.Errorf("API key for provider '%s' is not set", cfg.ActiveProvider)
104101
}

0 commit comments

Comments
 (0)