From 789ff9b5e285d885ef78a45ba18ba2104b5c2e78 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Thu, 29 Aug 2024 15:55:24 +0530 Subject: [PATCH 1/2] Created a file for entries with empty titles --- .../src/audit-base-command.ts | 17 +++- .../contentstack-audit/src/config/index.ts | 2 + .../contentstack-audit/src/modules/entries.ts | 79 ++++++++++--------- .../src/types/content-types.ts | 5 +- 4 files changed, 63 insertions(+), 40 deletions(-) diff --git a/packages/contentstack-audit/src/audit-base-command.ts b/packages/contentstack-audit/src/audit-base-command.ts index f7f87fd7d6..727e4b6242 100644 --- a/packages/contentstack-audit/src/audit-base-command.ts +++ b/packages/contentstack-audit/src/audit-base-command.ts @@ -56,6 +56,7 @@ export abstract class AuditBaseCommand extends BaseCommand, ): Promise { - if (Object.keys(config.moduleConfig).includes(moduleName)) { + if (Object.keys(config.moduleConfig).includes(moduleName) || config.feild_level_modules.includes(moduleName)) { const csvPath = join(sanitizePath(this.sharedConfig.reportPath), `${sanitizePath(moduleName)}.csv`); return new Promise((resolve, reject) => { // file deepcode ignore MissingClose: Will auto close once csv stream end diff --git a/packages/contentstack-audit/src/config/index.ts b/packages/contentstack-audit/src/config/index.ts index 2e31b7a954..f3675f933c 100644 --- a/packages/contentstack-audit/src/config/index.ts +++ b/packages/contentstack-audit/src/config/index.ts @@ -75,7 +75,9 @@ const config = { ReportTitleForEntries: { Entries_Select_feild: 'Entries_Select_feild', Entries_Mandatory_feild: 'Entries_Mandatory_feild', + Entries_Title_feild: 'Entries_Title_feild' }, + 'feild_level_modules' : ['Entries_Title_feild'] }; export default config; diff --git a/packages/contentstack-audit/src/modules/entries.ts b/packages/contentstack-audit/src/modules/entries.ts index e534f7569e..0e284da2e7 100644 --- a/packages/contentstack-audit/src/modules/entries.ts +++ b/packages/contentstack-audit/src/modules/entries.ts @@ -57,6 +57,7 @@ export default class Entries { protected missingRefs: Record = {}; protected missingSelectFeild: Record = {}; protected missingMandatoryFields: Record = {}; + protected missingTitleFields: Record = {}; public entryMetaData: Record[] = []; public moduleName: keyof typeof auditConfig.moduleConfig = 'entries'; @@ -71,11 +72,14 @@ export default class Entries { this.folderPath = resolve(sanitizePath(config.basePath), sanitizePath(config.moduleConfig.entries.dirName)); } - validateModules(moduleName: keyof typeof auditConfig.moduleConfig, moduleConfig: Record): keyof typeof auditConfig.moduleConfig { + validateModules( + moduleName: keyof typeof auditConfig.moduleConfig, + moduleConfig: Record, + ): keyof typeof auditConfig.moduleConfig { if (Object.keys(moduleConfig).includes(moduleName)) { return moduleName; } - return 'entries' + return 'entries'; } /** @@ -168,6 +172,7 @@ export default class Entries { missingEntryRefs: this.missingRefs, missingSelectFeild: this.missingSelectFeild, missingMandatoryFields: this.missingMandatoryFields, + missingTitleFields: this.missingTitleFields, }; } @@ -199,7 +204,7 @@ export default class Entries { async fixPrerequisiteData() { this.ctSchema = (await new ContentType({ fix: true, - log: () => { }, + log: () => {}, config: this.config, moduleName: 'content-types', ctSchema: this.ctSchema, @@ -207,7 +212,7 @@ export default class Entries { }).run(true)) as ContentTypeStruct[]; this.gfSchema = (await new GlobalField({ fix: true, - log: () => { }, + log: () => {}, config: this.config, moduleName: 'global-fields', ctSchema: this.ctSchema, @@ -220,7 +225,7 @@ export default class Entries { if (existsSync(extensionPath)) { try { this.extensions = Object.keys(JSON.parse(readFileSync(extensionPath, 'utf8'))); - } catch (error) { } + } catch (error) {} } if (existsSync(marketplacePath)) { @@ -233,7 +238,7 @@ export default class Entries { ) as string[]; this.extensions.push(...metaData); } - } catch (error) { } + } catch (error) {} } } @@ -415,19 +420,19 @@ export default class Entries { return missingRefs.length ? [ - { - tree, - data_type, - missingRefs, - display_name, - ct_uid: this.currentUid, - name: this.currentTitle, - treeStr: tree - .map(({ name }) => name) - .filter((val) => val) - .join(' ➜ '), - }, - ] + { + tree, + data_type, + missingRefs, + display_name, + ct_uid: this.currentUid, + name: this.currentTitle, + treeStr: tree + .map(({ name }) => name) + .filter((val) => val) + .join(' ➜ '), + }, + ] : []; } @@ -587,19 +592,19 @@ export default class Entries { return missingRefs.length ? [ - { - tree, - data_type, - missingRefs, - display_name, - uid: this.currentUid, - name: this.currentTitle, - treeStr: tree - .map(({ name }) => name) - .filter((val) => val) - .join(' ➜ '), - }, - ] + { + tree, + data_type, + missingRefs, + display_name, + uid: this.currentUid, + name: this.currentTitle, + treeStr: tree + .map(({ name }) => name) + .filter((val) => val) + .join(' ➜ '), + }, + ] : []; } @@ -858,10 +863,7 @@ export default class Entries { }; if (mandatory) { - if ( - (data_type === 'json' && field_metadata.allow_json_rte && isJsonRteEmpty()) || - (!(data_type === 'json') && isEntryEmpty()) - ) { + if ((data_type === 'json' && field_metadata.allow_json_rte && isJsonRteEmpty()) || isEntryEmpty()) { return [ { uid: this.currentUid, @@ -1261,6 +1263,11 @@ export default class Entries { let { title } = entries[entryUid]; if (entries[entryUid].hasOwnProperty('title') && !title) { + this.missingTitleFields[entryUid] = { + 'Entry UID': entryUid, + 'Content Type UID': uid, + "Locale": code, + }; this.log( `The 'title' field in Entry with UID '${entryUid}' of Content Type '${uid}' in Locale '${code}' is empty.`, `error`, diff --git a/packages/contentstack-audit/src/types/content-types.ts b/packages/contentstack-audit/src/types/content-types.ts index 96099e4efa..dce8a32448 100644 --- a/packages/contentstack-audit/src/types/content-types.ts +++ b/packages/contentstack-audit/src/types/content-types.ts @@ -142,7 +142,10 @@ enum OutputColumn { 'MissingValues' = 'missingCTSelectFieldValues', 'Minimum Required Instaces' = 'min_instance', 'missingFieldUid' = 'missingFieldUid', - 'isPublished' = 'isPublished' + 'isPublished' = 'isPublished', + 'Entry UID' ="Entry UID", + 'Content Type UID'= 'Content Type UID', + "Locale"="Locale", } export { From c5a609e0a487aa3021df2fcd547589f40c0d81f2 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Thu, 29 Aug 2024 16:00:07 +0530 Subject: [PATCH 2/2] fixed merged changed --- packages/contentstack-audit/src/audit-base-command.ts | 4 ++-- packages/contentstack-audit/src/modules/entries.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/contentstack-audit/src/audit-base-command.ts b/packages/contentstack-audit/src/audit-base-command.ts index 2f585dfd92..9246e162a5 100644 --- a/packages/contentstack-audit/src/audit-base-command.ts +++ b/packages/contentstack-audit/src/audit-base-command.ts @@ -132,7 +132,7 @@ export abstract class AuditBaseCommand extends BaseCommand