@@ -3,6 +3,7 @@ package jira
3
3
import (
4
4
"fmt"
5
5
"io"
6
+ "net/http"
6
7
"net/url"
7
8
"strings"
8
9
"sync"
@@ -68,9 +69,12 @@ type Options struct {
68
69
// AccountID is the accountID of the jira user.
69
70
AccountID string `yaml:"account-id" json:"account_id" validate:"required"`
70
71
// 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"`
72
76
// Token is the token for jira instance.
73
- Token string `yaml:"token" json:"token" validate:"required" `
77
+ Token string `yaml:"token" json:"token"`
74
78
// ProjectName is the name of the project.
75
79
ProjectName string `yaml:"project-name" json:"project_name"`
76
80
// ProjectID is the ID of the project (optional)
@@ -103,14 +107,28 @@ func New(options *Options) (*Integration, error) {
103
107
if ! options .Cloud {
104
108
username = options .AccountID
105
109
}
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 ()
112
129
}
113
- jiraClient , err := jira .NewClient (tp .Client (), options .URL )
130
+
131
+ jiraClient , err := jira .NewClient (httpclient , options .URL )
114
132
if err != nil {
115
133
return nil , err
116
134
}
0 commit comments