Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 9 additions & 7 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fileignoreconfig:
- filename: package-lock.json
checksum: 60cf06e944b51a620589f6785874c0c771e6e12a01cb561ec60fc92bfddf70ee
checksum: 353b5b39c9f8242902e6198b3f6c5981c813af16ce16ebbe845ebf369c1c1ff1
- filename: pnpm-lock.yaml
checksum: bee7058cd14780ac1a012ca95dccb89e62918f0e1bc9ea0d13d4c58d284e21e0
checksum: 3e8de376815b1514490bcd0348e91178fa467467a3a33460300abd50edc633f9
- filename: packages/contentstack-import-setup/test/unit/backup-handler.test.ts
checksum: 0582d62b88834554cf12951c8690a73ef3ddbb78b82d2804d994cf4148e1ef93
- filename: packages/contentstack-import-setup/test/config.json
Expand Down Expand Up @@ -57,8 +57,10 @@ fileignoreconfig:
checksum: f93aa9b0c964608b60c88d4c72ff33840b58ec900297c4bae1f4ea365aa51048
- filename: packages/contentstack-auth/test/utils/mfa-handler.test.ts
checksum: b067f93cf0185d794e8419cc41e8fac96ed790dea8fc48dc083ee242ccacbd4d
- filename: packages/contentstack-utilities/src/logger/logger.ts
checksum: 76429bc87e279624b386f00e7eb3f4ec25621ace7056289f812b9a076d6e184e
- filename: packages/contentstack-import/src/import/modules/entries.ts
checksum: 2fd4e8ecf75e077632a6408d09997f0921d2a3508f9f2cb8f47fe79a28592300
version: "1.0"
- filename: packages/contentstack-import/src/import/module-importer.ts
checksum: 93fac2407e20070aa393f783e5a21093e99424e5fd2873aabc2099ac3ea02b27
- filename: packages/contentstack-import/src/utils/import-config-handler.ts
checksum: bb8093633dc7de888541990623c3e02a482b7e6f5db0ba396bedc20c4c74b782
- filename: packages/contentstack-import/src/utils/setup-branch.ts
checksum: a4a968a20d5ab7cbc08c266819907541bbf793cc098521a5e810ada3cbacbee6
version: "1.0"
404 changes: 202 additions & 202 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@colors/colors": "^1.6.0",
"@contentstack/cli-cm-export": "~1.20.0",
"@contentstack/cli-cm-import": "~1.26.3",
"@contentstack/cli-cm-import": "~1.27.0",
"@contentstack/cli-command": "~1.6.1",
"@contentstack/cli-utilities": "~1.14.0",
"@oclif/core": "^4.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-import",
"description": "Contentstack CLI plugin to import content into stack",
"version": "1.26.3",
"version": "1.27.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
26 changes: 6 additions & 20 deletions packages/contentstack-import/src/commands/cm/stacks/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ export default class ImportCommand extends Command {
description:
"The name of the branch where you want to import your content. If you don't mention the branch name, then by default the content will be imported to the main branch.",
parse: printFlagDeprecation(['-B'], ['--branch']),
exclusive: ['branch-alias'],
}),
'branch-alias': flags.string({
description:
"The alias of the branch where you want to import your content. If you don't mention the branch alias, then by default the content will be imported to the main branch.",
exclusive: ['branch'],
}),
'import-webhook-status': flags.string({
description:
Expand Down Expand Up @@ -161,26 +167,6 @@ export default class ImportCommand extends Command {

const managementAPIClient: ContentstackClient = await managementSDKClient(importConfig);

if (!flags.branch) {
try {
// Use stack configuration to check for branch availability
// false positive - no hardcoded secret here
// @ts-ignore-next-line secret-detection
const keyProp = 'api_key';
const branches = await managementAPIClient
.stack({ [keyProp]: importConfig.apiKey })
.branch()
.query()
.find()
.then(({ items }: any) => items);
if (branches.length) {
flags.branch = 'main';
}
} catch (error) {
// Branch not enabled, just the let flow continue
}
}

const moduleImporter = new ModuleImporter(managementAPIClient, importConfig);
const result = await moduleImporter.start();
backupDir = importConfig.backupDir;
Expand Down
43 changes: 22 additions & 21 deletions packages/contentstack-import/src/import/module-importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import { addLocale, cliux, ContentstackClient, Logger } from '@contentstack/cli-
import startModuleImport from './modules';
import startJSModuleImport from './modules-js';
import { ImportConfig, Modules } from '../types';
import { backupHandler, log, validateBranch, masterLocalDetails, sanitizeStack, initLogger, trace } from '../utils';
import {
backupHandler,
log,
masterLocalDetails,
sanitizeStack,
initLogger,
setupBranchConfig,
} from '../utils';

class ModuleImporter {
private managementAPIClient: ContentstackClient;
Expand All @@ -28,8 +35,14 @@ class ModuleImporter {
this.importConfig.stackName = stackDetails.name as string;
this.importConfig.org_uid = stackDetails.org_uid as string;
}
if (this.importConfig.branchName) {
await validateBranch(this.stackAPIClient, this.importConfig, this.importConfig.branchName);

await setupBranchConfig(this.importConfig, this.stackAPIClient);
if (this.importConfig.branchAlias && this.importConfig.branchName) {
this.stackAPIClient = this.managementAPIClient.stack({
api_key: this.importConfig.apiKey,
management_token: this.importConfig.management_token,
branch_uid: this.importConfig.branchName,
});
}

if (this.importConfig.management_token) {
Expand All @@ -50,15 +63,9 @@ class ModuleImporter {
if (
!this.importConfig.skipAudit &&
(!this.importConfig.moduleName ||
[
'content-types',
'global-fields',
'entries',
'extensions',
'workflows',
'custom-roles',
'assets'
].includes(this.importConfig.moduleName))
['content-types', 'global-fields', 'entries', 'extensions', 'workflows', 'custom-roles', 'assets'].includes(
this.importConfig.moduleName,
))
) {
if (!(await this.auditImportData(logger))) {
return { noSuccessMsg: true };
Expand Down Expand Up @@ -150,15 +157,9 @@ class ModuleImporter {
} else if (this.importConfig.modules.types.length) {
this.importConfig.modules.types
.filter((val) =>
[
'content-types',
'global-fields',
'entries',
'extensions',
'workflows',
'custom-roles',
'assets'
].includes(val),
['content-types', 'global-fields', 'entries', 'extensions', 'workflows', 'custom-roles', 'assets'].includes(
val,
),
)
.forEach((val) => {
args.push('--modules', val);
Expand Down
1 change: 1 addition & 0 deletions packages/contentstack-import/src/types/import-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default interface ImportConfig extends DefaultConfig, ExternalConfig {
branches?: branch[];
branchEnabled?: boolean;
branchDir?: string;
branchAlias?: string;
moduleName?: Modules;
master_locale: masterLocale;
headers?: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import merge from 'merge';
import * as path from 'path';
import { omit, filter, includes, isArray } from 'lodash';
import { configHandler, isAuthenticated, cliux, sanitizePath, log } from '@contentstack/cli-utilities';
import {
configHandler,
isAuthenticated,
cliux,
sanitizePath,
log,
} from '@contentstack/cli-utilities';
import defaultConfig from '../config';
import { readFile, fileExistsSync } from './file-helper';
import { askContentDir, askAPIKey } from './interactive';
Expand Down Expand Up @@ -98,6 +104,10 @@ const setupConfig = async (importCmdFlags: any): Promise<ImportConfig> => {
config.importWebhookStatus = importCmdFlags['import-webhook-status'];
config.skipPrivateAppRecreationIfExist = !importCmdFlags['skip-app-recreation'];

if (importCmdFlags['branch-alias']) {
config.branchAlias = importCmdFlags['branch-alias'];
}

if (importCmdFlags['branch']) {
config.branchName = importCmdFlags['branch'];
config.branchDir = config.contentDir;
Expand Down
1 change: 1 addition & 0 deletions packages/contentstack-import/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { setupBranchConfig } from './setup-branch';
export * as interactive from './interactive';
export { default as setupImportConfig } from './import-config-handler';
export * as fileHelper from './file-helper';
Expand Down
30 changes: 30 additions & 0 deletions packages/contentstack-import/src/utils/setup-branch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ContentstackClient, getBranchFromAlias, log } from '@contentstack/cli-utilities';
import { ImportConfig } from 'src/types';
import { validateBranch } from './common-helper';

export const setupBranchConfig = async (
config: ImportConfig,
stackAPIClient: ReturnType<ContentstackClient['stack']>,
): Promise<void> => {
if (config.branchName) {
await validateBranch(stackAPIClient, config, config.branchName);
return;
}

if (config.branchAlias) {
config.branchName = await getBranchFromAlias(stackAPIClient, config.branchAlias);
}
try {
const branches = await stackAPIClient
.branch()
.query()
.find()
.then(({ items }) => items);
if (branches.length) {
log.info(`Stack is branch Enabled and Branch is not passed by default import will be done in main branch`);
}
} catch (error) {
// Here the stack is not branch enabled or any network issue
log.debug('Failed to fetch branches', { error });
}
};
2 changes: 1 addition & 1 deletion packages/contentstack-seed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-cm-import": "~1.26.3",
"@contentstack/cli-cm-import": "~1.27.0",
"@contentstack/cli-command": "~1.6.1",
"@contentstack/cli-utilities": "~1.14.0",
"@contentstack/management": "~1.22.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-utilities/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const doesBranchExist = async (stack, branchName) => {

export const getBranchFromAlias = async (stack: ReturnType<ContentstackClient['stack']>, branchAlias: string) => {
if (!stack || !branchAlias || typeof branchAlias !== 'string') {
throw new Error('Invalid input: stack and branch alias are required');
throw new Error('Invalid input. Both stack and branch alias are required.');
}
try {
const response = await stack.branchAlias(branchAlias).fetch();
Expand Down
12 changes: 6 additions & 6 deletions packages/contentstack-utilities/test/unit/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Testing the getBranchFromAlias function', () => {
expect.fail('Expected function to throw an error');
} catch (error) {
expect(error).to.be.instanceOf(Error);
expect((error as Error).message).to.equal('Invalid input: stack and branch alias are required');
expect((error as Error).message).to.equal('Invalid input. Both stack and branch alias are required.');
}
});

Expand All @@ -55,7 +55,7 @@ describe('Testing the getBranchFromAlias function', () => {
expect.fail('Expected function to throw an error');
} catch (error) {
expect(error).to.be.instanceOf(Error);
expect((error as Error).message).to.equal('Invalid input: stack and branch alias are required');
expect((error as Error).message).to.equal('Invalid input. Both stack and branch alias are required.');
}
});

Expand All @@ -71,7 +71,7 @@ describe('Testing the getBranchFromAlias function', () => {
expect.fail('Expected function to throw an error');
} catch (error) {
expect(error).to.be.instanceOf(Error);
expect((error as Error).message).to.equal('Invalid input: stack and branch alias are required');
expect((error as Error).message).to.equal('Invalid input. Both stack and branch alias are required.');
}
});

Expand All @@ -87,7 +87,7 @@ describe('Testing the getBranchFromAlias function', () => {
expect.fail('Expected function to throw an error');
} catch (error) {
expect(error).to.be.instanceOf(Error);
expect((error as Error).message).to.equal('Invalid input: stack and branch alias are required');
expect((error as Error).message).to.equal('Invalid input. Both stack and branch alias are required.');
}
});

Expand All @@ -103,7 +103,7 @@ describe('Testing the getBranchFromAlias function', () => {
expect.fail('Expected function to throw an error');
} catch (error) {
expect(error).to.be.instanceOf(Error);
expect((error as Error).message).to.equal('Invalid input: stack and branch alias are required');
expect((error as Error).message).to.equal('Invalid input. Both stack and branch alias are required.');
}
});

Expand All @@ -119,7 +119,7 @@ describe('Testing the getBranchFromAlias function', () => {
expect.fail('Expected function to throw an error');
} catch (error) {
expect(error).to.be.instanceOf(Error);
expect((error as Error).message).to.equal('Invalid input: stack and branch alias are required');
expect((error as Error).message).to.equal('Invalid input. Both stack and branch alias are required.');
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@contentstack/cli-cm-clone": "~1.16.0",
"@contentstack/cli-cm-export": "~1.20.0",
"@contentstack/cli-cm-export-to-csv": "~1.9.1",
"@contentstack/cli-cm-import": "~1.26.3",
"@contentstack/cli-cm-import": "~1.27.0",
"@contentstack/cli-cm-import-setup": "1.4.2",
"@contentstack/cli-cm-migrate-rte": "~1.6.1",
"@contentstack/cli-cm-seed": "~1.12.1",
Expand Down
Loading
Loading