fix: Prefer config file api_token over JIRA_API_TOKEN env var#962
Open
RameezShuhaib wants to merge 1 commit intoankitpokhrel:mainfrom
Open
fix: Prefer config file api_token over JIRA_API_TOKEN env var#962RameezShuhaib wants to merge 1 commit intoankitpokhrel:mainfrom
RameezShuhaib wants to merge 1 commit intoankitpokhrel:mainfrom
Conversation
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.
ccoVeille
suggested changes
Mar 4, 2026
ccoVeille
left a comment
There was a problem hiding this comment.
This sounds like an unexpected changes to me.
The classic variable resolution order is
argument > env > config file
So here you would break the expectations of many users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
--configorJIRA_CONFIG_FILEto specify a different Jira account, theJIRA_API_TOKENenvironment variable overrides theapi_tokenfrom the config file. This causes issue list to return empty results when the env var token does not have access to the project.Root Cause
viper.AutomaticEnv()was called afterReadInConfig(), but since viper treats env vars with higher priority by default, the config file value was being overwritten.Solution
After reading the config file, explicitly preserve the
api_tokenvalue usingviper.Set()before callingAutomaticEnv(). This ensures the config file token takes precedence when explicitly set.Testing
Tested with multiple Jira accounts where:
JIRA_API_TOKENis set to account A--configspecifies account B with a differentapi_tokenBefore: Returns empty results (uses account A token)
After: Returns correct results (uses account B token from config file)