Skip to content

Commit b47ce6c

Browse files
committed
feat: added bearer support to jira reporting for self hosted + misc
1 parent 7c87285 commit b47ce6c

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

pkg/reporting/trackers/jira/jira.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package jira
33
import (
44
"fmt"
55
"io"
6+
"net/http"
67
"net/url"
78
"strings"
89
"sync"
@@ -68,9 +69,12 @@ type Options struct {
6869
// AccountID is the accountID of the jira user.
6970
AccountID string `yaml:"account-id" json:"account_id" validate:"required"`
7071
// Email is the email of the user for jira instance
71-
Email string `yaml:"email" json:"email" validate:"required,email"`
72+
Email string `yaml:"email" json:"email"`
73+
// PersonalAccessToken is the personal access token for jira instance.
74+
// If this is set, Bearer Auth is used instead of Basic Auth.
75+
PersonalAccessToken string `yaml:"personal-access-token" json:"personal_access_token"`
7276
// Token is the token for jira instance.
73-
Token string `yaml:"token" json:"token" validate:"required"`
77+
Token string `yaml:"token" json:"token"`
7478
// ProjectName is the name of the project.
7579
ProjectName string `yaml:"project-name" json:"project_name"`
7680
// ProjectID is the ID of the project (optional)
@@ -103,14 +107,28 @@ func New(options *Options) (*Integration, error) {
103107
if !options.Cloud {
104108
username = options.AccountID
105109
}
106-
tp := jira.BasicAuthTransport{
107-
Username: username,
108-
Password: options.Token,
109-
}
110-
if options.HttpClient != nil {
111-
tp.Transport = options.HttpClient.HTTPClient.Transport
110+
111+
var httpclient *http.Client
112+
if options.PersonalAccessToken != "" {
113+
bearerTp := jira.BearerAuthTransport{
114+
Token: options.PersonalAccessToken,
115+
}
116+
if options.HttpClient != nil {
117+
bearerTp.Transport = options.HttpClient.HTTPClient.Transport
118+
}
119+
httpclient = bearerTp.Client()
120+
} else {
121+
basicTp := jira.BasicAuthTransport{
122+
Username: username,
123+
Password: options.Token,
124+
}
125+
if options.HttpClient != nil {
126+
basicTp.Transport = options.HttpClient.HTTPClient.Transport
127+
}
128+
httpclient = basicTp.Client()
112129
}
113-
jiraClient, err := jira.NewClient(tp.Client(), options.URL)
130+
131+
jiraClient, err := jira.NewClient(httpclient, options.URL)
114132
if err != nil {
115133
return nil, err
116134
}

0 commit comments

Comments
 (0)