Skip to content
Merged
2 changes: 2 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ fileignoreconfig:
checksum: f93aa9b0c964608b60c88d4c72ff33840b58ec900297c4bae1f4ea365aa51048
- filename: packages/contentstack-auth/test/utils/mfa-handler.test.ts
checksum: b067f93cf0185d794e8419cc41e8fac96ed790dea8fc48dc083ee242ccacbd4d
- filename: packages/contentstack-import/src/import/module-importer.ts
checksum: bdcfad1ec3a329f9ab49a203e8ea9cb97a9db2250bc202b92cd47ccc5a193010
version: "1.0"
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
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,7 +167,7 @@ export default class ImportCommand extends Command {

const managementAPIClient: ContentstackClient = await managementSDKClient(importConfig);

if (!flags.branch) {
if (!flags.branch && !importConfig.branchAlias) {
Comment thread
cs-raj marked this conversation as resolved.
Outdated
try {
// Use stack configuration to check for branch availability
// false positive - no hardcoded secret here
Expand Down
37 changes: 17 additions & 20 deletions packages/contentstack-import/src/import/module-importer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { resolve } from 'path';
import { AuditFix } from '@contentstack/cli-audit';
import messages, { $t } from '@contentstack/cli-audit/lib/messages';
import { addLocale, cliux, ContentstackClient, Logger } from '@contentstack/cli-utilities';
import { addLocale, cliux, ContentstackClient, getBranchFromAlias, Logger } from '@contentstack/cli-utilities';

import startModuleImport from './modules';
import startJSModuleImport from './modules-js';
Expand All @@ -28,7 +28,16 @@ class ModuleImporter {
this.importConfig.stackName = stackDetails.name as string;
this.importConfig.org_uid = stackDetails.org_uid as string;
}
if (this.importConfig.branchName) {

if (!this.importConfig.branchName && this.importConfig.branchAlias) {
Comment thread
cs-raj marked this conversation as resolved.
Outdated
this.importConfig.branchName = await getBranchFromAlias(this.stackAPIClient, this.importConfig.branchAlias);
this.importConfig.branchDir = this.importConfig.contentDir;
this.stackAPIClient = this.managementAPIClient.stack({
api_key: this.importConfig.apiKey,
management_token: this.importConfig.management_token,
branch_uid: this.importConfig.branchName,
});
} else {
await validateBranch(this.stackAPIClient, this.importConfig, this.importConfig.branchName);
}

Expand All @@ -50,15 +59,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 +153,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
Expand Up @@ -98,6 +98,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
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.15.2",
"@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
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading