@@ -3,6 +3,7 @@ package jira
3
3
import (
4
4
"context"
5
5
"encoding/json"
6
+ "fmt"
6
7
"net/http"
7
8
"strconv"
8
9
"strings"
@@ -63,7 +64,10 @@ func (c *Client) CreateV2(req *CreateRequest) (*CreateResponse, error) {
63
64
}
64
65
65
66
func (c * Client ) create (req * CreateRequest , ver string ) (* CreateResponse , error ) {
66
- data := c .getRequestData (req )
67
+ data , err := c .getRequestData (req )
68
+ if err != nil {
69
+ return nil , err
70
+ }
67
71
68
72
body , err := json .Marshal (& data )
69
73
if err != nil {
@@ -103,7 +107,7 @@ func (c *Client) create(req *CreateRequest, ver string) (*CreateResponse, error)
103
107
return & out , err
104
108
}
105
109
106
- func (* Client ) getRequestData (req * CreateRequest ) * createRequest {
110
+ func (* Client ) getRequestData (req * CreateRequest ) ( * createRequest , error ) {
107
111
if req .Labels == nil {
108
112
req .Labels = []string {}
109
113
}
@@ -176,31 +180,36 @@ func (*Client) getRequestData(req *CreateRequest) *createRequest {
176
180
}
177
181
data .Fields .M .FixVersions = versions
178
182
}
179
- constructCustomFields (req .CustomFields , & data )
183
+ if err := constructCustomFields (req .CustomFields , & data ); err != nil {
184
+ return nil , err
185
+ }
180
186
181
- return & data
187
+ return & data , nil
182
188
}
183
189
184
- func constructCustomFields (fields map [string ]string , data * createRequest ) {
190
+ func constructCustomFields (fields map [string ]string , data * createRequest ) error {
185
191
if len (fields ) == 0 {
186
- return
192
+ return nil
187
193
}
188
194
189
195
var configuredFields []IssueTypeField
190
196
191
197
err := viper .UnmarshalKey ("issue.fields.custom" , & configuredFields )
192
198
if err != nil || len (configuredFields ) == 0 {
193
- return
199
+ return nil
194
200
}
195
201
196
202
data .Fields .M .customFields = make (customField )
197
203
198
204
for key , val := range fields {
205
+ found := false
206
+
199
207
for _ , configured := range configuredFields {
200
208
identifier := strings .ReplaceAll (strings .ToLower (strings .TrimSpace (configured .Name )), " " , "-" )
201
209
if identifier != strings .ToLower (key ) {
202
210
continue
203
211
}
212
+ found = true
204
213
205
214
switch configured .Schema .DataType {
206
215
case customFieldFormatOption :
@@ -230,7 +239,12 @@ func constructCustomFields(fields map[string]string, data *createRequest) {
230
239
data .Fields .M .customFields [configured .Key ] = val
231
240
}
232
241
}
242
+
243
+ if ! found {
244
+ return fmt .Errorf ("invalid custom field specified: %s" , key )
245
+ }
233
246
}
247
+ return nil
234
248
}
235
249
236
250
type createRequest struct {
0 commit comments