From e70284f3cd850771024c426335e4154e73823eb3 Mon Sep 17 00:00:00 2001 From: Rameez Shuhaib Date: Wed, 4 Mar 2026 21:29:35 +0400 Subject: [PATCH] fix: Prefer config file api_token over JIRA_API_TOKEN env var When a config file explicitly sets api_token, preserve it before AutomaticEnv binds JIRA_API_TOKEN so the env var does not override it. Fixes issue list returning empty results when using --config or JIRA_CONFIG_FILE with a different account than JIRA_API_TOKEN. --- internal/cmd/root/root.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/cmd/root/root.go b/internal/cmd/root/root.go index 7bd95e1b..cc2c9e1b 100644 --- a/internal/cmd/root/root.go +++ b/internal/cmd/root/root.go @@ -60,12 +60,19 @@ func init() { viper.SetConfigType(jiraConfig.FileType) } - viper.AutomaticEnv() - viper.SetEnvPrefix("jira") + if err := viper.ReadInConfig(); err == nil { + if debug { + fmt.Printf("Using config file: %s\n", viper.ConfigFileUsed()) + } - if err := viper.ReadInConfig(); err == nil && debug { - fmt.Printf("Using config file: %s\n", viper.ConfigFileUsed()) + // Preserve config file token before AutomaticEnv binds JIRA_API_TOKEN. + if token := viper.GetString("api_token"); token != "" { + viper.Set("api_token", token) + } } + + viper.AutomaticEnv() + viper.SetEnvPrefix("jira") }) }