Skip to content

Commit

Permalink
🚸 Make mapped fields more deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
pemontto committed Feb 6, 2022
1 parent 0751ba8 commit 115d082
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions packages/nodes-base/nodes/Jira/Jira.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,32 @@ export class Jira implements INodeType {
qs.updateHistory = additionalFields.updateHistory as string;
}
responseData = await jiraSoftwareCloudApiRequest.call(this, `/api/2/issue/${issueKey}`, 'GET', {}, qs);

if (additionalFields.resolveCustomFields) {
const mappedFields: IDataObject = {};
for (const field of Object.keys(responseData.fields)) {
// Sort custom fields last so we map them last
const customField = /^customfield_\d+$/;
const sortedFields: string[] = Object.keys(responseData.fields).sort((a, b) => {
if (customField.test(a) && customField.test(b)) {
return a > b ? 1 : -1;
}
if (customField.test(a)) {
return 1;
}
if (customField.test(b)) {
return -1;
}
return a > b ? 1 : -1;
});
for (const field of sortedFields) {
if (responseData.names[field] in mappedFields) {
// Duplicate fields, use original key
mappedFields[field] = responseData.fields[field];
let newField: string = responseData.names[field];
let counter = 0;
while (newField in mappedFields) {
counter++;
newField = `${responseData.names[field]}_${counter}`;
}
mappedFields[newField] = responseData.fields[field];
} else {
mappedFields[responseData.names[field] || field] = responseData.fields[field];
}
Expand Down

0 comments on commit 115d082

Please sign in to comment.