@@ -63,17 +63,19 @@ class Jira {
63
63
64
64
async updateField(issueId, data) {
65
65
try {
66
- const array = data.split(',');
67
- const parsedData = array.reduce((newData, item) => {
68
- const splitItem = item.split('::');
69
- if (splitItem.length === 2) {
70
- newData[splitItem[0].trim()] = splitItem[1];
71
- }
72
- return newData;
73
- }, {});
74
- const body = JSON.parse(JSON.stringify({
75
- fields: parsedData
76
- }));
66
+ const array = data.split(",");
67
+ const parsedData = array.reduce((newData, item) => {
68
+ const splitItem = item.split("::");
69
+ if (splitItem.length === 2) {
70
+ newData[splitItem[0].trim()] = splitItem[1];
71
+ }
72
+ return newData;
73
+ }, {});
74
+ const body = JSON.parse(
75
+ JSON.stringify({
76
+ fields: parsedData,
77
+ })
78
+ );
77
79
return this.fetch(
78
80
"updateField",
79
81
{
@@ -82,8 +84,7 @@ class Jira {
82
84
{
83
85
method: "PUT",
84
86
body,
85
- },
86
- true
87
+ }
87
88
);
88
89
} catch (err) {
89
90
throw err;
@@ -102,15 +103,15 @@ class Jira {
102
103
const { fields = [], expand = [] } = query;
103
104
104
105
try {
105
- return this.fetch(' getIssue' , {
106
+ return this.fetch(" getIssue" , {
106
107
pathname: `/rest/api/2/issue/${issueId}`,
107
108
query: {
108
- fields: fields.join(',' ),
109
- expand: expand.join(',' ),
109
+ fields: fields.join("," ),
110
+ expand: expand.join("," ),
110
111
},
111
112
});
112
113
} catch (error) {
113
- if (get(error, ' res.status' ) === 404) {
114
+ if (get(error, " res.status" ) === 404) {
114
115
return;
115
116
}
116
117
@@ -120,24 +121,24 @@ class Jira {
120
121
121
122
async getIssueTransitions(issueId) {
122
123
return this.fetch(
123
- ' getIssueTransitions' ,
124
+ " getIssueTransitions" ,
124
125
{
125
126
pathname: `/rest/api/2/issue/${issueId}/transitions`,
126
127
},
127
128
{
128
- method: ' GET' ,
129
+ method: " GET" ,
129
130
}
130
131
);
131
132
}
132
133
133
134
async transitionIssue(issueId, data) {
134
135
return this.fetch(
135
- ' transitionIssue' ,
136
+ " transitionIssue" ,
136
137
{
137
138
pathname: `/rest/api/3/issue/${issueId}/transitions`,
138
139
},
139
140
{
140
- method: ' POST' ,
141
+ method: " POST" ,
141
142
body: data,
142
143
}
143
144
);
@@ -147,7 +148,7 @@ class Jira {
147
148
apiMethodName,
148
149
{ host, pathname, query },
149
150
{ method, body, headers = {} } = {},
150
- skipStringify
151
+ skipStringify
151
152
) {
152
153
const url = format({
153
154
host: host || this.baseUrl,
@@ -156,22 +157,26 @@ class Jira {
156
157
});
157
158
158
159
if (!method) {
159
- method = ' GET' ;
160
+ method = " GET" ;
160
161
}
161
162
162
- if (headers[' Content-Type' ] === undefined) {
163
- headers[' Content-Type' ] = ' application/json' ;
163
+ if (headers[" Content-Type" ] === undefined) {
164
+ headers[" Content-Type" ] = " application/json" ;
164
165
}
165
166
166
167
if (headers.Authorization === undefined) {
167
168
headers.Authorization = `Basic ${Buffer.from(
168
169
`${this.email}:${this.token}`
169
- ).toString(' base64' )}`;
170
+ ).toString(" base64" )}`;
170
171
}
171
172
172
173
// strong check for undefined
173
174
// cause body variable can be 'false' boolean value
174
- if (body && headers['Content-Type'] === "application/json" && !skipStringify) {
175
+ if (
176
+ body &&
177
+ headers["Content-Type"] === "application/json" &&
178
+ !skipStringify
179
+ ) {
175
180
body = JSON.stringify(body);
176
181
}
177
182
@@ -185,7 +190,7 @@ class Jira {
185
190
};
186
191
187
192
try {
188
- console.log(' request:' , state.req.body)
193
+ console.log(" request:" , state.req.body);
189
194
await client(state, `${serviceName}:${apiMethodName}`);
190
195
} catch (error) {
191
196
const fields = {
@@ -194,9 +199,13 @@ class Jira {
194
199
};
195
200
196
201
delete state.req.headers;
197
- const formattedError = Object.assign(new Error("Jira API error"), state.res.body.errorMessages, fields);
202
+ const formattedError = Object.assign(
203
+ new Error("Jira API error"),
204
+ state,
205
+ fields
206
+ );
198
207
199
- console.log(' #### error' , JSON.stringify(formattedError))
208
+ console.log(" #### error" , JSON.stringify(formattedError));
200
209
201
210
throw formattedError;
202
211
}
0 commit comments