Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
resolved PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
poornima-metron committed Jul 11, 2024
1 parent 3bcb488 commit baf366c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 39 deletions.
44 changes: 16 additions & 28 deletions src/converters/IssueEntityConverter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import camelCase from 'lodash/camelCase';

import get from 'lodash/get';
import {
IntegrationLogger,
parseTimePropertyValue,
Expand Down Expand Up @@ -101,7 +101,7 @@ export function createIssueEntity({
const issueType = issue.fields.issuetype && issue.fields.issuetype.name;
const customFields: { [key: string]: any } = {};

// Extract simple custom fields
// Extract custom fields (simple and complex)
for (const [key, value] of Object.entries(issue.fields)) {
if (
key.startsWith('customfield_') &&
Expand All @@ -121,35 +121,23 @@ export function createIssueEntity({
customFields[fieldName] = extractedValue;
}
}
}
}

// Handle complex custom fields
complexCustomFieldsToInclude.forEach((path) => {
const [baseFieldId, ...nestedPathParts] = path.split('.');
if (issue.fields[baseFieldId] !== undefined) {
const nestedPath = nestedPathParts.join('.');
const fieldValue = getNestedValue(issue.fields[baseFieldId], nestedPath);
if (fieldValue !== undefined) {
if (fieldsById && fieldsById[baseFieldId]) {
const baseFieldName = camelCase(fieldsById[baseFieldId].name);
const formattedPathParts = nestedPathParts.map((part) => {
const match = part.match(/^(\w+)(?:\[(\d+)\])?$/);
if (match) {
const [, key, index] = match;
if (index !== undefined) {
return `${camelCase(key)}${index}`;
}
return camelCase(key);
}
return camelCase(part);
});
const formattedPath = [baseFieldName, ...formattedPathParts].join('');
setFlatNestedValue(customFields, formattedPath, fieldValue);
// Check for complex custom fields
for (const path of complexCustomFieldsToInclude) {
const [baseFieldId, ...rest] = path.split('.');
const nestedPath = rest.join('.');
if (!issue.fields[baseFieldId]) {
continue;
}
const extractedValue = get(issue.fields[baseFieldId], nestedPath);
if (!extractedValue) {
continue;
}
const baseFieldName = camelCase(fieldsById[baseFieldId].name);
const fieldName = nestedPath.split(/[\.\[\]]+/).map(camelCase).join('');
customFields[`${baseFieldName}${fieldName}`] = extractedValue;
}
}
});
}

if (!['string', 'undefined'].includes(typeof requestedClass)) {
logger.warn(
Expand Down
13 changes: 2 additions & 11 deletions src/steps/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,12 @@ export async function fetchIssues({
logger.info(
{
customFields: config.customFields,
allFieldIdsAndNames: Object.values(fieldsById).map(
(field) => `${field.id}: ${field.name ?? 'undefined field name'}`,
),
},
'Custom fields to ingest.',
);

logger.info(
{
complexCustomFields: config.complexCustomFields,
allFieldIdsAndNames: Object.values(fieldsById).map(
(field) => `${field.id}: ${field.name ?? 'undefined field name'}`,
(field) => `${field.id}: ${field.name ?? 'undefined field name'}`
),
},
'Complex custom fields to ingest.',
'Custom and complex custom fields to ingest.'
);

const issueProcessor = async (projectKey: JiraProjectKey, issue: Issue) =>
Expand Down

0 comments on commit baf366c

Please sign in to comment.