Skip to content

Commit 9bfe2c4

Browse files
committed
chore(jira): update version
1 parent d8e2632 commit 9bfe2c4

File tree

3 files changed

+41
-32
lines changed

3 files changed

+41
-32
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ To update the fields of an issue you need to specify an issue key and field data
1212

1313
```yaml
1414
- name: Comment on issue
15-
uses: kherP/[email protected].12
15+
uses: kherP/[email protected].13
1616
with:
1717
issue: INC-2
1818
fields: customfield_10006::https://www.google.com,customfield_10007::44

dist/index.js

+39-30
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,19 @@ class Jira {
6363

6464
async updateField(issueId, data) {
6565
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+
);
7779
return this.fetch(
7880
"updateField",
7981
{
@@ -82,8 +84,7 @@ class Jira {
8284
{
8385
method: "PUT",
8486
body,
85-
},
86-
true
87+
}
8788
);
8889
} catch (err) {
8990
throw err;
@@ -102,15 +103,15 @@ class Jira {
102103
const { fields = [], expand = [] } = query;
103104

104105
try {
105-
return this.fetch('getIssue', {
106+
return this.fetch("getIssue", {
106107
pathname: `/rest/api/2/issue/${issueId}`,
107108
query: {
108-
fields: fields.join(','),
109-
expand: expand.join(','),
109+
fields: fields.join(","),
110+
expand: expand.join(","),
110111
},
111112
});
112113
} catch (error) {
113-
if (get(error, 'res.status') === 404) {
114+
if (get(error, "res.status") === 404) {
114115
return;
115116
}
116117

@@ -120,24 +121,24 @@ class Jira {
120121

121122
async getIssueTransitions(issueId) {
122123
return this.fetch(
123-
'getIssueTransitions',
124+
"getIssueTransitions",
124125
{
125126
pathname: `/rest/api/2/issue/${issueId}/transitions`,
126127
},
127128
{
128-
method: 'GET',
129+
method: "GET",
129130
}
130131
);
131132
}
132133

133134
async transitionIssue(issueId, data) {
134135
return this.fetch(
135-
'transitionIssue',
136+
"transitionIssue",
136137
{
137138
pathname: `/rest/api/3/issue/${issueId}/transitions`,
138139
},
139140
{
140-
method: 'POST',
141+
method: "POST",
141142
body: data,
142143
}
143144
);
@@ -147,7 +148,7 @@ class Jira {
147148
apiMethodName,
148149
{ host, pathname, query },
149150
{ method, body, headers = {} } = {},
150-
skipStringify
151+
skipStringify
151152
) {
152153
const url = format({
153154
host: host || this.baseUrl,
@@ -156,22 +157,26 @@ class Jira {
156157
});
157158

158159
if (!method) {
159-
method = 'GET';
160+
method = "GET";
160161
}
161162

162-
if (headers['Content-Type'] === undefined) {
163-
headers['Content-Type'] = 'application/json';
163+
if (headers["Content-Type"] === undefined) {
164+
headers["Content-Type"] = "application/json";
164165
}
165166

166167
if (headers.Authorization === undefined) {
167168
headers.Authorization = `Basic ${Buffer.from(
168169
`${this.email}:${this.token}`
169-
).toString('base64')}`;
170+
).toString("base64")}`;
170171
}
171172

172173
// strong check for undefined
173174
// 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+
) {
175180
body = JSON.stringify(body);
176181
}
177182

@@ -185,7 +190,7 @@ class Jira {
185190
};
186191

187192
try {
188-
console.log('request:', state.req.body)
193+
console.log("request:", state.req.body);
189194
await client(state, `${serviceName}:${apiMethodName}`);
190195
} catch (error) {
191196
const fields = {
@@ -194,9 +199,13 @@ class Jira {
194199
};
195200

196201
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+
);
198207

199-
console.log('#### error', JSON.stringify(formattedError))
208+
console.log("#### error", JSON.stringify(formattedError));
200209

201210
throw formattedError;
202211
}

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)