5
5
"encoding/base64"
6
6
"encoding/json"
7
7
"fmt"
8
+ "strconv"
8
9
"strings"
9
10
"time"
10
11
)
@@ -57,6 +58,7 @@ type JQLResponse struct {
57
58
58
59
type Issue struct {
59
60
Key string `json:"key"`
61
+ Id string `json:"id"`
60
62
Fields struct {
61
63
Summary string `json:"summary"`
62
64
Status struct {
@@ -65,6 +67,14 @@ type Issue struct {
65
67
} `json:"fields"`
66
68
}
67
69
70
+ func (issue Issue ) GetIdAsInt () int {
71
+ value , err := strconv .ParseInt (issue .Id , 10 , 64 )
72
+ if err != nil {
73
+ return 0
74
+ }
75
+ return int (value )
76
+ }
77
+
68
78
type WorklogResponse struct {
69
79
Self string `json:"self"`
70
80
Author struct {
@@ -111,13 +121,19 @@ func (jc *JiraClient) GetLatestIssues() (JQLResponse, error) {
111
121
return jc .GetIssuesByJQL ("assignee in (currentUser()) ORDER BY updated DESC, created DESC" , 10 )
112
122
}
113
123
114
- func (jc * JiraClient ) GetIssuesByKeys (issueKeys []string ) (JQLResponse , error ) {
115
- issueKeysJQL := fmt .Sprintf ("key in (%s) ORDER BY updated DESC, created DESC" , strings .Join (issueKeys , "," ))
124
+ func (jc * JiraClient ) GetIssuesByKeys (issueKeys []int ) (JQLResponse , error ) {
125
+ // Convert []int to []string
126
+ issueKeysStr := make ([]string , len (issueKeys ))
127
+ for i , key := range issueKeys {
128
+ issueKeysStr [i ] = fmt .Sprintf ("%d" , key )
129
+ }
130
+ issueKeysJQL := fmt .Sprintf ("key in (%s) ORDER BY updated DESC, created DESC" , strings .Join (issueKeysStr , "," ))
116
131
return jc .GetIssuesByJQL (issueKeysJQL , len (issueKeys ))
117
132
}
118
133
119
134
func (jc * JiraClient ) GetIssue (issueKey string ) (Issue , error ) {
120
- requestUrl := fmt .Sprintf ("%s/rest/api/2/issue/%s?fields=summary,status" , Config .JiraUrl , issueKey )
135
+ // issueKey could be JIRA-123 (key) or just 234235 (id)
136
+ requestUrl := fmt .Sprintf ("%s/rest/api/2/issue/%s?fields=summary,status,id" , Config .JiraUrl , issueKey )
121
137
response , err := SendHttpRequest ("GET" , requestUrl , nil , jc .getHttpHeaders (), 200 )
122
138
if err != nil {
123
139
return Issue {}, err
@@ -130,15 +146,15 @@ func (jc *JiraClient) GetIssue(issueKey string) (Issue, error) {
130
146
return jiraIssue , nil
131
147
}
132
148
133
- func (jc * JiraClient ) CreateWorklog (issueKey string , logTime * time.Time , timeSpent string ) (WorklogResponse , error ) {
149
+ func (jc * JiraClient ) CreateWorklog (issueId int , logTime * time.Time , timeSpent string ) (WorklogResponse , error ) {
134
150
payload := map [string ]string {
135
151
"timeSpent" : FormatTimeSpent (TimeSpentToSeconds (timeSpent )),
136
152
"adjustEstimate" : "leave" ,
137
153
"started" : logTime .Format ("2006-01-02T15:04:05.000-0700" ),
138
154
}
139
155
payloadJson , _ := json .Marshal (payload )
140
156
requestBody := bytes .NewBuffer (payloadJson )
141
- requestUrl := fmt .Sprintf ("%s/rest/api/2/issue/%s /worklog?notifyUsers=false" , Config .JiraUrl , issueKey )
157
+ requestUrl := fmt .Sprintf ("%s/rest/api/2/issue/%d /worklog?notifyUsers=false" , Config .JiraUrl , issueId )
142
158
response , err := SendHttpRequest ("POST" , requestUrl , requestBody , jc .getHttpHeaders (), 201 )
143
159
if err != nil {
144
160
return WorklogResponse {}, err
@@ -152,21 +168,21 @@ func (jc *JiraClient) CreateWorklog(issueKey string, logTime *time.Time, timeSpe
152
168
return workLogRequest , nil
153
169
}
154
170
155
- func (jc * JiraClient ) UpdateWorklog (issueKey string , jiraWorklogId int , timeSpentInSeconds int ) error {
171
+ func (jc * JiraClient ) UpdateWorklog (issueId int , jiraWorklogId int , timeSpentInSeconds int ) error {
156
172
payload := JiraWorklogUpdate {
157
173
TimeSpentSeconds : timeSpentInSeconds ,
158
174
}
159
175
payloadJson , _ := json .Marshal (payload )
160
176
requestBody := bytes .NewBuffer (payloadJson )
161
- requestUrl := fmt .Sprintf ("%s/rest/api/2/issue/%s /worklog/%d?notifyUsers=false" ,
162
- Config .JiraUrl , issueKey , jiraWorklogId )
177
+ requestUrl := fmt .Sprintf ("%s/rest/api/2/issue/%d /worklog/%d?notifyUsers=false" ,
178
+ Config .JiraUrl , issueId , jiraWorklogId )
163
179
_ , err := SendHttpRequest ("PUT" , requestUrl , requestBody , jc .getHttpHeaders (), 200 )
164
180
return err
165
181
}
166
182
167
- func (jc * JiraClient ) DeleteWorklog (issueKey string , jiraWorklogId int ) error {
168
- requestUrl := fmt .Sprintf ("%s/rest/api/2/issue/%s /worklog/%d?notifyUsers=false" ,
169
- Config .JiraUrl , issueKey , jiraWorklogId )
183
+ func (jc * JiraClient ) DeleteWorklog (issueId int , jiraWorklogId int ) error {
184
+ requestUrl := fmt .Sprintf ("%s/rest/api/2/issue/%d /worklog/%d?notifyUsers=false" ,
185
+ Config .JiraUrl , issueId , jiraWorklogId )
170
186
_ , err := SendHttpRequest ("DELETE" , requestUrl , nil , jc .getHttpHeaders (), 204 )
171
187
return err
172
188
}
0 commit comments