Skip to content

Commit 239aef7

Browse files
committed
Merge branch 'development' into feat/DX-2295
2 parents 8ccf22d + dd8ad24 commit 239aef7

File tree

11 files changed

+594
-689
lines changed

11 files changed

+594
-689
lines changed

.github/workflows/unit-test.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Run Unit Tests
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
run-tests:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Set up Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: '22.x'
18+
19+
- name: Install dependencies for all plugins
20+
run: |
21+
npm run setup-repo-old
22+
23+
- name: Fetch latest references
24+
run: |
25+
git fetch --prune
26+
27+
- name: Identify Changed Plugins
28+
id: changes
29+
run: |
30+
echo "Finding changed files..."
31+
# Ensure both commit references are valid
32+
if [[ -z "${{ github.event.before }}" || -z "${{ github.sha }}" ]]; then
33+
echo "Error: Missing commit references"
34+
exit 1
35+
fi
36+
37+
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
38+
echo "Changed files:"
39+
echo "$CHANGED_FILES"
40+
41+
# Identify affected plugins
42+
AFFECTED_PLUGINS=$(echo "$CHANGED_FILES" | grep -oP '(?<=^packages/)([^/]+)' | sort -u | tr '\n' ' ')
43+
echo "Affected plugins: $AFFECTED_PLUGINS"
44+
45+
# Set output for the next step
46+
echo "::set-output name=affected_plugins::$AFFECTED_PLUGINS"
47+
48+
- name: Run Unit Tests for Affected Plugins
49+
run: |
50+
for plugin in ${{ steps.changes.outputs.affected_plugins }}; do
51+
echo "Checking if tests should run for $plugin..."
52+
if [[ "$plugin" == "contentstack-audit" ]]; then
53+
echo "Running tests for contentstack-audit..."
54+
npm run test:unit --prefix ./packages/contentstack-audit
55+
else
56+
echo "contentstack-audit has not changed. Skipping tests."
57+
fi
58+
done

package-lock.json

Lines changed: 201 additions & 351 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-audit/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-audit",
3-
"version": "1.9.1",
3+
"version": "1.10.0",
44
"description": "Contentstack audit plugin",
55
"author": "Contentstack CLI",
66
"homepage": "https://github.com/contentstack/cli",
@@ -74,7 +74,8 @@
7474
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
7575
"version": "oclif readme && git add README.md",
7676
"clean": "rm -rf ./lib ./node_modules tsconfig.tsbuildinfo oclif.manifest.json",
77-
"test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\""
77+
"test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\"",
78+
"test:unit": "mocha --timeout 10000 --forbid-only \"test/unit/**/*.test.ts\""
7879
},
7980
"engines": {
8081
"node": ">=16"

packages/contentstack-audit/src/audit-base-command.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
6060
missingRefInCustomRoles,
6161
missingEnvLocalesInAssets,
6262
missingEnvLocalesInEntries,
63-
missingFieldRules
63+
missingFieldRules,
64+
missingMultipleFields
6465
} = await this.scanAndFix();
6566

6667
this.showOutputOnScreen([
@@ -83,6 +84,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
8384
this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Entries Missing Locale and Environments', missingRefs: missingEnvLocalesInEntries }])
8485
this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Field Rules', missingRefs: missingFieldRules }])
8586

87+
this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Entries Changed Multiple Fields', missingRefs: missingMultipleFields }])
8688
if (
8789
!isEmpty(missingCtRefs) ||
8890
!isEmpty(missingGfRefs) ||
@@ -94,7 +96,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
9496
!isEmpty(missingRefInCustomRoles) ||
9597
!isEmpty(missingEnvLocalesInAssets) ||
9698
!isEmpty(missingEnvLocalesInEntries) ||
97-
!isEmpty(missingSelectFeild)
99+
!isEmpty(missingFieldRules) ||
100+
!isEmpty(missingMultipleFields)
98101
) {
99102
if (this.currentCommand === 'cm:stacks:audit') {
100103
this.log(this.$t(auditMsg.FINAL_REPORT_PATH, { path: this.sharedConfig.reportPath }), 'warn');
@@ -149,7 +152,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
149152
missingRefInCustomRoles,
150153
missingEnvLocalesInAssets,
151154
missingEnvLocalesInEntries,
152-
missingFieldRules;
155+
missingFieldRules,
156+
missingMultipleFields;
153157

154158
for (const module of this.sharedConfig.flags.modules || this.sharedConfig.modules) {
155159
print([
@@ -188,6 +192,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
188192
missingMandatoryFields = missingEntry.missingMandatoryFields ?? {};
189193
missingTitleFields = missingEntry.missingTitleFields ?? {};
190194
missingEnvLocalesInEntries = missingEntry.missingEnvLocale??{};
195+
missingMultipleFields = missingEntry.missingMultipleFields??{};
191196
await this.prepareReport(module, missingEntryRefs);
192197

193198
await this.prepareReport(`Entries_Select_feild`, missingSelectFeild);
@@ -198,6 +203,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
198203

199204
await this.prepareReport('Entry_Missing_Locale_and_Env_in_Publish_Details', missingEnvLocalesInEntries);
200205

206+
await this.prepareReport('Entry_Multiple_Fields', missingMultipleFields);
207+
201208
break;
202209
case 'workflows':
203210
missingCtRefsInWorkflow = await new Workflows({
@@ -249,7 +256,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
249256
missingRefInCustomRoles,
250257
missingEnvLocalesInAssets,
251258
missingEnvLocalesInEntries,
252-
missingFieldRules
259+
missingFieldRules,
260+
missingMultipleFields
253261
};
254262
}
255263

packages/contentstack-audit/src/config/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ const config = {
120120
'Entries_Select_feild',
121121
'Entry_Missing_Locale_and_Env_in_Publish_Details',
122122
'field-rules',
123+
'Entry_Multiple_Fields'
123124
],
124125
fixSelectField: false,
125126
};

packages/contentstack-audit/src/modules/entries.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default class Entries {
6060
protected missingMandatoryFields: Record<string, any> = {};
6161
protected missingTitleFields: Record<string, any> = {};
6262
protected missingEnvLocale: Record<string, any> = {};
63+
protected missingMultipleField: Record<string, any> = {};
6364
public environments: string[] = [];
6465
public entryMetaData: Record<string, any>[] = [];
6566
public moduleName: keyof typeof auditConfig.moduleConfig = 'entries';
@@ -241,6 +242,7 @@ export default class Entries {
241242
missingMandatoryFields: this.missingMandatoryFields,
242243
missingTitleFields: this.missingTitleFields,
243244
missingEnvLocale: this.missingEnvLocale,
245+
missingMultipleFields: this.missingMultipleField
244246
};
245247
}
246248

@@ -350,7 +352,26 @@ export default class Entries {
350352
}
351353

352354
for (const child of field?.schema ?? []) {
353-
const { uid } = child;
355+
const { uid, multiple, data_type } = child;
356+
357+
if(multiple && entry[uid] && !Array.isArray(entry[uid])) {
358+
if (!this.missingMultipleField[this.currentUid]) {
359+
this.missingMultipleField[this.currentUid] = [];
360+
}
361+
362+
this.missingMultipleField[this.currentUid].push({
363+
uid: this.currentUid,
364+
name: this.currentTitle,
365+
field_uid: uid,
366+
data_type,
367+
multiple,
368+
tree,
369+
treeStr: tree
370+
.map(({ name }) => name)
371+
.filter((val) => val)
372+
.join(' ➜ '),
373+
});
374+
}
354375
this.missingMandatoryFields[this.currentUid].push(
355376
...this.validateMandatoryFields(
356377
[...tree, { uid: field.uid, name: child.display_name, field: uid }],
@@ -717,12 +738,32 @@ export default class Entries {
717738
runFixOnSchema(tree: Record<string, unknown>[], schema: ContentTypeSchemaType[], entry: EntryFieldType) {
718739
// NOTE Global field Fix
719740
schema.forEach((field) => {
720-
const { uid, data_type } = field;
741+
const { uid, data_type, multiple } = field;
721742

722743
if (!Object(entry).hasOwnProperty(uid)) {
723744
return;
724745
}
725746

747+
if (multiple && entry[uid] && !Array.isArray(entry[uid])) {
748+
this.missingMultipleField[this.currentUid] ??= [];
749+
750+
this.missingMultipleField[this.currentUid].push({
751+
uid: this.currentUid,
752+
name: this.currentTitle,
753+
field_uid: uid,
754+
data_type,
755+
multiple,
756+
tree,
757+
treeStr: tree
758+
.map(({ name }) => name)
759+
.filter(Boolean)
760+
.join(' ➜ '),
761+
'fixStatus': 'Fixed',
762+
});
763+
764+
entry[uid] = [entry[uid]];
765+
}
766+
726767
switch (data_type) {
727768
case 'global_field':
728769
entry[uid] = this.fixGlobalFieldReferences(

packages/contentstack-audit/src/types/content-types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type ContentTypeStruct = {
1919
description: string;
2020
schema?: ContentTypeSchemaType[];
2121
mandatory: boolean;
22+
multiple: boolean;
2223
};
2324

2425
type ModuleConstructorParam = {
@@ -42,6 +43,7 @@ type CommonDataTypeStruct = {
4243
allow_json_rte: boolean;
4344
} & AnyProperty;
4445
mandatory: boolean;
46+
multiple: boolean;
4547
};
4648

4749
type RefErrorReturnType = {
@@ -164,7 +166,9 @@ enum OutputColumn {
164166
'selectedValue' = 'selectedValue',
165167
'fixStatus' = 'fixStatus',
166168
'Content_type_uid' = 'ct_uid',
167-
'action' = 'action'
169+
'action' = 'action',
170+
'field_uid' = 'field_uid',
171+
'multiple' = 'multiple'
168172
}
169173

170174
export {

packages/contentstack-audit/test/unit/commands/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Audit command', () => {
1010
filename!: string;
1111
} as FileTransportInstance;
1212

13-
describe('Audit run method', () => {
13+
describe('Audit run method:', () => {
1414
fancy
1515
.stdout({ print: process.env.PRINT === 'true' || false })
1616
.stub(winston.transports, 'File', () => fsTransport)

packages/contentstack-import/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {
8-
"@contentstack/cli-audit": "~1.9.1",
8+
"@contentstack/cli-audit": "~1.10.0",
99
"@contentstack/cli-command": "~1.3.3",
1010
"@contentstack/cli-utilities": "~1.9.0",
1111
"@contentstack/management": "~1.18.4",

packages/contentstack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"prepack": "pnpm compile && oclif manifest && oclif readme"
2323
},
2424
"dependencies": {
25-
"@contentstack/cli-audit": "~1.9.1",
25+
"@contentstack/cli-audit": "~1.10.0",
2626
"@contentstack/cli-auth": "~1.3.25",
2727
"@contentstack/cli-cm-bootstrap": "~1.13.3",
2828
"@contentstack/cli-cm-branches": "~1.3.1",

0 commit comments

Comments
 (0)