Skip to content

Commit fa50fd2

Browse files
committed
(fix) The constructed server urls were pointing to authorization server, rather than their own JIRA server
1 parent 6ca4d10 commit fa50fd2

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

api/client.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/spf13/viper"
77
"github.com/zalando/go-keyring"
88

9+
"github.com/ankitpokhrel/jira-cli/internal/cmdutil"
910
"github.com/ankitpokhrel/jira-cli/pkg/jira"
1011
"github.com/ankitpokhrel/jira-cli/pkg/jira/filter"
1112
"github.com/ankitpokhrel/jira-cli/pkg/netrc"
@@ -60,7 +61,14 @@ func Client(config jira.Config) *jira.Client {
6061
}
6162

6263
if config.Server == "" {
63-
config.Server = viper.GetString("server")
64+
apiServer := viper.GetString("api_server")
65+
if apiServer != "" {
66+
config.Server = apiServer
67+
} else {
68+
// Fallback to server URL if api_server is not set
69+
cmdutil.Warn("api_server key is not set, falling back to server URL")
70+
config.Server = viper.GetString("server")
71+
}
6472
}
6573
if config.Login == "" {
6674
config.Login = viper.GetString("login")

internal/config/generator.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const (
3030
optionBack = "Go-back"
3131
optionNone = "None"
3232
lineBreak = "----------"
33+
apiServer = "https://api.atlassian.com/ex/jira"
3334
)
3435

3536
var (
@@ -81,7 +82,9 @@ type JiraCLIConfigGenerator struct {
8182
value struct {
8283
installation string
8384
server string
84-
version struct {
85+
// API server is the server URL for the Jira API. Should be the same as the server URL if not oAuth.
86+
apiServer string
87+
version struct {
8588
major, minor, patch int
8689
}
8790
login string
@@ -368,10 +371,6 @@ func (c *JiraCLIConfigGenerator) configureOAuth() error {
368371
func (c *JiraCLIConfigGenerator) configureServerAndLoginDetails() error {
369372
var qs []*survey.Question
370373

371-
if c.value.authType == jira.AuthTypeOAuth {
372-
// Set server URL using the cloud ID from OAuth configuration
373-
c.usrCfg.Server = fmt.Sprintf("https://api.atlassian.com/ex/jira/%s", c.value.oauth.cloudId)
374-
}
375374
c.value.server = c.usrCfg.Server
376375
c.value.login = c.usrCfg.Login
377376

@@ -469,18 +468,26 @@ func (c *JiraCLIConfigGenerator) configureServerAndLoginDetails() error {
469468

470469
if ans.Server != "" {
471470
c.value.server = ans.Server
471+
472472
}
473473
if ans.Login != "" {
474474
c.value.login = ans.Login
475475
}
476+
477+
if c.value.authType == jira.AuthTypeOAuth {
478+
// Set server URL using the cloud ID from OAuth configuration
479+
c.value.apiServer = fmt.Sprintf("%s/%s", apiServer, c.value.oauth.cloudId)
480+
} else {
481+
c.value.apiServer = c.value.server
482+
}
476483
}
477484
// Trim trailing slash from server URL
478485
c.value.server = strings.TrimRight(c.value.server, "/")
479486
return c.verifyLoginDetails()
480487
}
481488
func (c *JiraCLIConfigGenerator) generateJiraConfig() jira.Config {
482489
config := jira.Config{
483-
Server: c.value.server,
490+
Server: c.value.apiServer,
484491
Login: c.value.login,
485492
Insecure: &c.usrCfg.Insecure,
486493
AuthType: &c.value.authType,
@@ -819,6 +826,7 @@ func (c *JiraCLIConfigGenerator) write(path string) (string, error) {
819826

820827
config.Set("installation", c.value.installation)
821828
config.Set("server", c.value.server)
829+
config.Set("api_server", c.value.apiServer)
822830
config.Set("login", c.value.login)
823831
config.Set("project", c.value.project)
824832
config.Set("epic", c.value.epic)

0 commit comments

Comments
 (0)