Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 54: Development-to-Staging #1351

Merged
merged 34 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
deec7f3
fix: handled request.body undefined issue in launch plugin
aman19K Mar 11, 2024
805337d
Merge pull request #1338 from contentstack/fix/CS-44169
aman19K Mar 11, 2024
075e40b
Handling the embedded entries cretion in RTE, version bump
cs-raj Mar 11, 2024
b5459fa
Merge branch 'development' into feat/CS-43630
cs-raj Mar 11, 2024
7bab3a9
optimisation
cs-raj Mar 11, 2024
6ed1178
formatting fixed and used filter
cs-raj Mar 13, 2024
1c24e85
added the check to remove all the other branches than the one mention…
cs-raj Mar 14, 2024
0ab653b
Merge pull request #1339 from contentstack/feat/CS-43630
cs-raj Mar 14, 2024
0c503d9
Merge branch 'development' into feat/CS-44350
cs-raj Mar 15, 2024
1af72ec
pr fixes to remove the branches and keep it as seperate type
cs-raj Mar 15, 2024
fa740a0
removed stray console log
cs-raj Mar 15, 2024
756c07a
Merge pull request #1341 from contentstack/feat/CS-44350
cs-raj Mar 16, 2024
96d5b5b
Merge branch 'staging' into stage-to-development
aman19K Mar 18, 2024
fdf7f93
Merge pull request #1343 from contentstack/stage-to-development
aman19K Mar 18, 2024
0e1abcd
added logger for errors for multiple files errors, version bump
cs-raj Mar 18, 2024
8bf0fc8
removed loggerService from script
cs-raj Mar 18, 2024
a8b5992
Added error logs only and for the api errors showing only the selecte…
cs-raj Mar 20, 2024
47e288d
branches version bump
cs-raj Mar 21, 2024
4b95fd5
removal of redundant catch blocks
cs-raj Mar 21, 2024
fb6cd94
Merge branch 'development' into hotfix/development-merge
cs-raj Mar 21, 2024
0d28790
package-lock update
cs-raj Mar 21, 2024
ce161e1
Merge pull request #1346 from contentstack/hotfix/development-merge
cs-raj Mar 21, 2024
e0e99b7
Merge branch 'development' into feat/CS-44174
cs-raj Mar 21, 2024
832bdb6
PR comment fixes
cs-raj Mar 21, 2024
80d9c53
Merge pull request #1344 from contentstack/feat/CS-44174
cs-raj Mar 21, 2024
f006281
Merge branch 'staging' into stage-to-development
cs-raj Mar 22, 2024
96c21e1
Merge pull request #1349 from contentstack/stage-to-development
cs-raj Mar 22, 2024
622710b
upgraded tar to 6.2.1
cs-raj Mar 26, 2024
6e3065d
@oclif/plugin-plugins to 5.0.0
cs-raj Mar 26, 2024
1e4bc9b
Merge pull request #1352 from contentstack/fix/CS-44536
cs-raj Mar 26, 2024
91ecc6d
remove the return statement due to which it was not checking for rest…
cs-raj Mar 26, 2024
d6dc0d6
Merge pull request #1353 from contentstack/bugfix/CS-44546
cs-raj Mar 26, 2024
49887f8
solved migration logger not adding the issue
cs-raj Mar 26, 2024
96f1242
Merge pull request #1354 from contentstack/bugfix/CS-44549
cs-raj Mar 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
993 changes: 314 additions & 679 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-audit",
"version": "1.5.0",
"version": "1.5.1",
"description": "Contentstack audit plugin",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/cli",
Expand All @@ -21,7 +21,7 @@
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.6.0",
"@oclif/plugin-help": "^5",
"@oclif/plugin-plugins": "^4.1.9",
"@oclif/plugin-plugins": "^5.0.0",
"chalk": "^4.1.2",
"fast-csv": "^4.3.6",
"fs-extra": "^11.1.1",
Expand Down Expand Up @@ -86,4 +86,4 @@
"keywords": [
"oclif"
]
}
}
28 changes: 21 additions & 7 deletions packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import { print } from './util/log';
import { auditMsg } from './messages';
import { BaseCommand } from './base-command';
import { Entries, GlobalField, ContentType, Extensions, Workflows } from './modules';
import { CommandNames, ContentTypeStruct, OutputColumn, RefErrorReturnType } from './types';
import {
CommandNames,
ContentTypeStruct,
OutputColumn,
RefErrorReturnType,
WorkflowExtensionsRefErrorReturnType,
} from './types';

export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseCommand> {
private currentCommand!: CommandNames;
Expand Down Expand Up @@ -113,7 +119,6 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
config: this.sharedConfig,
fix: this.currentCommand === 'cm:stacks:audit:fix',
};

switch (module) {
case 'content-types':
missingCtRefs = await new ContentType(cloneDeep(constructorParam)).run();
Expand Down Expand Up @@ -303,15 +308,15 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma

const tableKeys = Object.keys(missingRefs[0]);
const arrayOfObjects = tableKeys.map((key) => {
if (['title', 'name', 'uid', 'content_types', 'fixStatus'].includes(key)) {
if (['title', 'name', 'uid', 'content_types', 'branches', 'fixStatus'].includes(key)) {
return {
[key]: {
minWidth: 7,
header: key,
get: (row: Record<string, unknown>) => {
if (key === 'fixStatus') {
return chalk.green(typeof row[key] === 'object' ? JSON.stringify(row[key]) : row[key]);
} else if (key === 'content_types') {
} else if (key === 'content_types' || key === 'branches') {
return chalk.red(typeof row[key] === 'object' ? JSON.stringify(row[key]) : row[key]);
} else {
return chalk.white(typeof row[key] === 'object' ? JSON.stringify(row[key]) : row[key]);
Expand Down Expand Up @@ -371,14 +376,22 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
const ws = createWriteStream(csvPath).on('error', reject);
const defaultColumns = Object.keys(OutputColumn);
const userDefinedColumns = this.sharedConfig.flags.columns ? this.sharedConfig.flags.columns.split(',') : null;
let missingRefs: RefErrorReturnType[] = Object.values(listOfMissingRefs).flat();
let missingRefs: RefErrorReturnType[] | WorkflowExtensionsRefErrorReturnType[] =
Object.values(listOfMissingRefs).flat();
const columns: (keyof typeof OutputColumn)[] = userDefinedColumns
? [...userDefinedColumns, ...defaultColumns.filter((val: string) => !userDefinedColumns.includes(val))]
: defaultColumns;

if (this.sharedConfig.flags.filter) {
const [column, value]: [keyof typeof OutputColumn, string] = this.sharedConfig.flags.filter.split('=');
missingRefs = missingRefs.filter((row: RefErrorReturnType) => row[OutputColumn[column]] === value);
// Filter the missingRefs array
missingRefs = missingRefs.filter((row) => {
if (OutputColumn[column] in row) {
const rowKey = OutputColumn[column] as keyof (RefErrorReturnType | WorkflowExtensionsRefErrorReturnType);
return row[rowKey] === value;
}
return false;
});
}

const rowData: Record<string, string | string[]>[] = [];
Expand All @@ -387,7 +400,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma

for (const column of columns) {
if (Object.keys(issue).includes(OutputColumn[column])) {
row[column] = issue[OutputColumn[column]] as string;
const issueKey = OutputColumn[column] as keyof typeof issue;
row[column] = issue[issueKey] as string;
row[column] = typeof row[column] === 'object' ? JSON.stringify(row[column]) : row[column];
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/contentstack-audit/src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const commonMsg = {
WORKFLOW_FIX_CONFIRMATION: 'Would you like to overwrite existing file?',
EXTENSION_FIX_WARN: `The extension associated with UID {uid} and title '{title}' will be removed.`,
EXTENSION_FIX_CONFIRMATION: `Would you like to overwrite existing file?`,
WF_BRANCH_REMOVAL: `Removing the branch '{branch} from workflow with UID {uid} and name {name} will be removed.'`,
};

const auditMsg = {
Expand Down
35 changes: 32 additions & 3 deletions packages/contentstack-audit/src/modules/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class Workflows {
public missingCtInWorkflows: Workflow[];
public missingCts: Set<string>;
public workflowPath: string;
public isBranchFixDone: boolean;

constructor({
log,
Expand All @@ -41,6 +42,7 @@ export default class Workflows {
this.missingCtInWorkflows = [];
this.missingCts = new Set();
this.workflowPath = '';
this.isBranchFixDone = false;
}
/**
* Check whether the given path for the workflow exists or not
Expand All @@ -55,6 +57,7 @@ export default class Workflows {
return {};
}


this.workflowPath = join(this.folderPath, this.fileName);
this.workflowSchema = existsSync(this.workflowPath)
? values(JSON.parse(readFileSync(this.workflowPath, 'utf8')) as Workflow[])
Expand All @@ -64,9 +67,20 @@ export default class Workflows {

for (const workflow of this.workflowSchema) {
const ctNotPresent = workflow.content_types.filter((ct) => !this.ctUidSet.has(ct));
if (ctNotPresent.length) {
const branch = workflow?.branches?.filter((branch) => branch !== this.config?.branch);

if (ctNotPresent.length || branch?.length) {
const tempwf = cloneDeep(workflow);
tempwf.content_types = ctNotPresent;
tempwf.content_types = ctNotPresent || [];

if (workflow?.branches) {
tempwf.branches = branch;
}

if (branch?.length) {
this.isBranchFixDone = true;
}

ctNotPresent.forEach((ct) => this.missingCts.add(ct));
this.missingCtInWorkflows.push(tempwf);
}
Expand All @@ -80,7 +94,7 @@ export default class Workflows {
);
}

if (this.fix && this.missingCtInWorkflows.length) {
if (this.fix && (this.missingCtInWorkflows.length || this.isBranchFixDone)) {
await this.fixWorkflowSchema();
this.missingCtInWorkflows.forEach((wf) => (wf.fixStatus = 'Fixed'));
}
Expand All @@ -96,6 +110,21 @@ export default class Workflows {
if (Object.keys(newWorkflowSchema).length !== 0) {
for (const workflow of this.workflowSchema) {
const fixedCts = workflow.content_types.filter((ct) => !this.missingCts.has(ct));
const fixedBranches: string[] = [];

workflow?.branches?.forEach((branch) => {
if (branch !== this.config?.branch) {
const { uid, name } = workflow;
this.log($t(commonMsg.WF_BRANCH_REMOVAL, { uid, name, branch }), { color: 'yellow' });
} else {
fixedBranches.push(branch);
}
});

if (fixedBranches.length > 0) {
newWorkflowSchema[workflow.uid].branches = fixedBranches;
}

if (fixedCts.length) {
newWorkflowSchema[workflow.uid].content_types = fixedCts;
} else {
Expand Down
4 changes: 4 additions & 0 deletions packages/contentstack-audit/src/types/content-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type RefErrorReturnType = {
title?: string;
};

type WorkflowExtensionsRefErrorReturnType = RefErrorReturnType & { branches?: string[] };

// NOTE Type 1
type ReferenceFieldDataType = CommonDataTypeStruct & {
reference_to: string[];
Expand Down Expand Up @@ -119,6 +121,7 @@ enum OutputColumn {
title = 'title',
'uid' = 'uid',
'missingCts' = 'content_types',
'Missing Branches' = 'branches',
}

export {
Expand All @@ -137,4 +140,5 @@ export {
OutputColumn,
ContentTypeSchemaType,
GlobalFieldSchemaTypes,
WorkflowExtensionsRefErrorReturnType,
};
3 changes: 2 additions & 1 deletion packages/contentstack-audit/src/types/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export interface Workflow {
enabled?: boolean;
deleted_at?: any;
missingRefs?: any;
fixStatus?:string
fixStatus?: string;
branches?: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"org_uid": "org1",
"api_key": "apiKey",
"content_types": [
"ct1"
"ct1",
"ct45",
"ct14"
],
"enabled": false,
"deleted_at": false
Expand All @@ -16,7 +18,8 @@
"org_uid": "org1",
"api_key": "apiKey",
"content_types": [
"ct2"
"ct2",
"ct6"
],
"enabled": false,
"deleted_at": false
Expand All @@ -43,5 +46,21 @@
],
"enabled": false,
"deleted_at": false
},
"wf5": {
"name": "wf5",
"uid": "wf5",
"org_uid": "org1",
"api_key": "apiKey",
"content_types": [
"ct4"
],
"branches": [
"main",
"development",
"stage"
],
"enabled": false,
"deleted_at": false
}
}
40 changes: 16 additions & 24 deletions packages/contentstack-audit/test/unit/modules/workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('Workflows', () => {
.it(
'should expect missingRefs equal to workflow which has missing refs, missingCts equal to missing Cts',
async () => {
wf.config.branch = 'development';
const missingRefs = await wf.run();
expect(wf.workflowSchema).eql(values(JSON.parse(fs.readFileSync(wf.workflowPath, 'utf8'))));
expect(missingRefs).eql([
Expand All @@ -67,33 +68,22 @@ describe('Workflows', () => {
enabled: false,
deleted_at: false,
},
{
api_key: 'apiKey',
branches: ['main', 'stage'],
content_types: [],
deleted_at: false,
enabled: false,
name: 'wf5',
org_uid: 'org1',
uid: 'wf5',
},
]);
expect(wf.missingCts).eql(new Set(['ct45', 'ct14', 'ct6']));
},
);
});

describe('run method with valid path and empty ctSchema to check the missing references', () => {
const wf = new Workflows({
log: () => {},
moduleName: 'workflows',
ctSchema: [],
config: Object.assign(config, {
basePath: resolve(`./test/unit/mock/contents/`),
flags: {},
}),
});

fancy
.stdout({ print: process.env.PRINT === 'true' || true })
.stub(ux, 'confirm', async () => true)
.it('should expect missingRefs equal to all workflows', async () => {
const missingRefs = await wf.run();
wf.workflowSchema.pop();
expect(missingRefs).eql(wf.workflowSchema);
});
});

describe('run method with audit fix for workflows with valid path and empty ctSchema', () => {
const wf = new Workflows({
log: () => {},
Expand All @@ -111,6 +101,7 @@ describe('Workflows', () => {
.stub(wf, 'log', async () => {})
.stub(ux, 'confirm', async () => true)
.stub(wf, 'WriteFileSync', () => {})
.stub(wf, 'writeFixContent', () => {})
.it('the run function should run and flow should go till fixWorkflowSchema', async () => {
const fixedReference = await wf.run();
expect(fixedReference).eql([
Expand All @@ -136,13 +127,14 @@ describe('Workflows', () => {
},
{
api_key: 'apiKey',
content_types: ['ct88'],
branches: ['main', 'stage'],
content_types: [],
deleted_at: false,
enabled: false,
fixStatus: 'Fixed',
name: 'wf6',
name: 'wf5',
org_uid: 'org1',
uid: 'wf6',
uid: 'wf5',
},
]);
});
Expand Down
6 changes: 3 additions & 3 deletions packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\""
},
"dependencies": {
"@contentstack/cli-cm-seed": "~1.7.0",
"@contentstack/cli-cm-seed": "~1.7.3",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.6.0",
"inquirer": "8.2.4",
"mkdirp": "^1.0.4",
"tar": "^6.1.13"
"tar": "^6.2.1 "
},
"devDependencies": {
"@oclif/test": "^2.5.6",
Expand Down Expand Up @@ -73,4 +73,4 @@
}
},
"repository": "contentstack/cli"
}
}
4 changes: 2 additions & 2 deletions packages/contentstack-branches/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-branches",
"description": "Contentstack CLI plugin to do branches operations",
"version": "1.0.23",
"version": "1.0.24",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down Expand Up @@ -95,4 +95,4 @@
}
},
"repository": "https://github.com/contentstack/cli"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ export function assetFolderCreateScript(contentType) {

const createAssetTask = () => {
return {
title: 'Create Assets Folder',
title: 'Check and create asset folder in base branch',
successTitle: 'Assets folder Created Successfully',
failedTitle: 'Failed to create assets folder',
failedTitle: 'Failed to create assets folder in base branch',
task: async () => {
try {
const baseAssetsFolderCount = await getAssetCount(branch, true);
Expand Down
Loading
Loading