Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7f82767
add csv utility for branches diff
Sep 12, 2025
f23e031
Merge branch 'development' into enhancement/DX-3527
Sep 12, 2025
c8dccca
version bump
Sep 12, 2025
536b95a
resolve PR comments
Sep 14, 2025
4afefec
Merge pull request #2120 from contentstack/main
harshithad0703 Sep 15, 2025
d539ee5
Merge pull request #2121 from contentstack/staging
harshithad0703 Sep 15, 2025
977ac35
removed modified value column
Sep 15, 2025
8033da5
updated flag description
Sep 15, 2025
bf70a79
update logger to v2 and fix import path validation
Sep 16, 2025
c18d4d0
version bumps
Sep 16, 2025
be3e28a
resolved comments
Sep 16, 2025
bffbe51
resolve comments
Sep 16, 2025
8678c6e
Merge branch 'development' into enhancement/DX-3527
Sep 16, 2025
51c82cf
updated test cases
Sep 16, 2025
5e67f6e
resolve comments
Sep 16, 2025
ffcc0bb
Merge pull request #2122 from contentstack/fix/DX-3491
naman-contentstack Sep 17, 2025
68b7ef6
fix: refresh token issue with custom region(dev, stage)
aman19K Sep 17, 2025
56d4f5a
Merge pull request #2124 from contentstack/fix/DX-3539
harshithad0703 Sep 17, 2025
d6eefc0
Merge pull request #2125 from contentstack/development
harshithad0703 Sep 17, 2025
5d52910
Merge branch 'development' into enhancement/DX-3527
Sep 17, 2025
c705c77
Merge pull request #2116 from contentstack/enhancement/DX-3527
naman-contentstack Sep 17, 2025
95072dd
Merge pull request #2127 from contentstack/development
harshithad0703 Sep 17, 2025
97d65a5
update package lock
harshithad0703 Sep 18, 2025
99ebda1
Merge pull request #2128 from contentstack/fix/update-packagelock
harshithad0703 Sep 18, 2025
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
6 changes: 3 additions & 3 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fileignoreconfig:
- filename: package-lock.json
checksum: e99f717f726226d79c6d484b44fa3d8e758038fbaca671301377741e36802b6d
checksum: b07cb236b78aa3149b89e2ed18851ee005db8ef735062f91e0e91b2adf013c12
- filename: pnpm-lock.yaml
checksum: d26dfe4137bcd958a79beff8a2867fbbad531f81ef0c8c8a8786e8680b79b52e
checksum: 577582ed82062ad359d8bc2bc0a309ab4d344a2a4122573d8cf77aeb481268f2
- 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 @@ -86,5 +86,5 @@ fileignoreconfig:
- filename: packages/contentstack-import-setup/src/utils/backup-handler.ts
checksum: 7db02c6f2627400b28fc96d505bf074d477080a45ba13943709d4845b6ca0908
- filename: packages/contentstack-import/src/utils/backup-handler.ts
checksum: 4f7a8bea92ebffbc34a0979b3a63fef327562a899b773481d67a675140cfa4bf
checksum: 0a9accdafce01837166223ed00cd801e2ebb39a4ef952231f67232859a5beea8
version: "1.0"
1,582 changes: 807 additions & 775 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions packages/contentstack-branches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-branches/1.5.0 darwin-arm64 node-v23.11.0
@contentstack/cli-cm-branches/1.6.0 darwin-arm64 node-v22.13.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand All @@ -51,7 +51,7 @@ USAGE
* [`csdx cm:branches`](#csdx-cmbranches)
* [`csdx cm:branches:create`](#csdx-cmbranchescreate)
* [`csdx cm:branches:delete [-uid <value>] [-k <value>]`](#csdx-cmbranchesdelete--uid-value--k-value)
* [`csdx cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>]`](#csdx-cmbranchesdiff---base-branch-value---compare-branch-value--k-value--module-value)
* [`csdx cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>] [--format <value>] [--csv-path <value>]`](#csdx-cmbranchesdiff---base-branch-value---compare-branch-value--k-value--module-value---format-value---csv-path-value)
* [`csdx cm:branches:merge [-k <value>][--compare-branch <value>] [--no-revert] [--export-summary-path <value>] [--use-merge-summary <value>] [--comment <value>] [--base-branch <value>]`](#csdx-cmbranchesmerge--k-value--compare-branch-value---no-revert---export-summary-path-value---use-merge-summary-value---comment-value---base-branch-value)

## `csdx cm:branches`
Expand Down Expand Up @@ -136,18 +136,21 @@ EXAMPLES

_See code: [src/commands/cm/branches/delete.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-export/src/commands/cm/branches/delete.ts)_

## `csdx cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>]`
## `csdx cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>] [--format <value>] [--csv-path <value>]`

Differences between two branches

```
USAGE
$ csdx cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>]
$ csdx cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>] [--format
<value>] [--csv-path <value>]

FLAGS
-k, --stack-api-key=<value> [optional] Provide the stack API key to show the difference between branches.
--base-branch=<value> [optional] Base branch (Target branch).
--compare-branch=<value> [optional] Compare branch (Source branch).
--csv-path=<value> [optional] Custom path for CSV output file. If not provided, will use the current
working directory.
--format=<option> [default: compact-text] [default: compact-text] [optional] Type of flags to show the
difference between two branches. <options: compact-text, detailed-text>
<options: compact-text|detailed-text>
Expand Down Expand Up @@ -181,6 +184,10 @@ EXAMPLES
$ csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types"

$ csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types" --format "detailed-text"

$ csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types" --format "compact-text"

$ csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types" --format "detailed-text" --csv-path "./reports/diff-report.csv"
```

_See code: [src/commands/cm/branches/diff.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-export/src/commands/cm/branches/diff.ts)_
Expand Down
2 changes: 1 addition & 1 deletion 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.5.2",
"version": "1.6.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
17 changes: 12 additions & 5 deletions packages/contentstack-branches/src/branch/diff-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import startCase from 'lodash/startCase';
import camelCase from 'lodash/camelCase';
import { cliux } from '@contentstack/cli-utilities';
import { getbranchConfig } from '../utils';
import { BranchOptions, BranchDiffRes, BranchDiffPayload } from '../interfaces';
import { BranchOptions, BranchDiffPayload } from '../interfaces';
import { askBaseBranch, askCompareBranch, askStackAPIKey, selectModule } from '../utils/interactive';
import {
fetchBranchesDiff,
Expand All @@ -14,6 +14,7 @@ import {
printVerboseTextView,
filterBranchDiffDataByModule,
} from '../utils/branch-diff-utility';
import { exportCSVReport } from '../utils/csv-utility';

export default class BranchDiffHandler {
private options: BranchOptions;
Expand Down Expand Up @@ -55,6 +56,10 @@ export default class BranchDiffHandler {
this.options.module = await selectModule();
}

if (this.options.format === 'detailed-text' && !this.options.csvPath) {
this.options.csvPath = process.cwd();
}

if(baseBranch){
cliux.print(`\nBase branch: ${baseBranch}`, { color: 'grey' });
}
Expand Down Expand Up @@ -87,15 +92,15 @@ export default class BranchDiffHandler {

if(this.options.module === 'all'){
for (let module in diffData) {
const branchDiff = diffData[module];
const branchDiff = diffData[module];
payload.module = module;
this.displaySummary(branchDiff, module);
await this.displayBranchDiffTextAndVerbose(branchDiff, payload);
}
}else{
const branchDiff = diffData[payload.module];
this.displaySummary(branchDiff, this.options.module);
await this.displayBranchDiffTextAndVerbose(branchDiff, payload);
const branchDiff = diffData[payload.module];
this.displaySummary(branchDiff, this.options.module);
await this.displayBranchDiffTextAndVerbose(branchDiff, payload);
}
}

Expand Down Expand Up @@ -126,6 +131,8 @@ export default class BranchDiffHandler {
const verboseRes = await parseVerbose(branchDiffData, payload);
cliux.loaderV2('', spinner);
printVerboseTextView(verboseRes);

exportCSVReport(payload.module, verboseRes, this.options.csvPath);
}
}
}
18 changes: 13 additions & 5 deletions packages/contentstack-branches/src/commands/cm/branches/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ export default class BranchDiffCommand extends Command {
'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --module "content-types"',
'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types"',
'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types" --format "detailed-text"',
]
'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types" --format "compact-text"',
'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types" --format "detailed-text" --csv-path "./reports/diff-report.csv"',
];

static usage: string = 'cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>]';
static usage: string =
'cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>] [--format <value>] [--csv-path <value>]';

static flags = {
'base-branch': flags.string({
Expand All @@ -43,9 +46,13 @@ export default class BranchDiffCommand extends Command {
default: 'compact-text',
multiple: false,
options: ['compact-text', 'detailed-text'],
description: '[default: compact-text] [optional] Type of flags to show the difference between two branches. <options: compact-text, detailed-text>',
description:
'[default: compact-text] [optional] Type of flags to show the difference between two branches. <options: compact-text, detailed-text>',
}),
};
'csv-path': flags.string({
description: '[optional] Custom path for CSV output file. If not provided, will use the current working directory.',
}),
};

static aliases: string[] = []; // Note: alternative usage if any

Expand All @@ -58,7 +65,8 @@ export default class BranchDiffCommand extends Command {
compareBranch: branchDiffFlags['compare-branch'],
module: branchDiffFlags.module,
format: branchDiffFlags.format,
host: this.cmaHost
csvPath: branchDiffFlags['csv-path'],
host: this.cmaHost,
};
if (!isAuthenticated()) {
const err = { errorMessage: 'You are not logged in. Please login with command $ csdx auth:login' };
Expand Down
42 changes: 42 additions & 0 deletions packages/contentstack-branches/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface BranchOptions {
baseBranch?: string;
authToken?: string;
host?: string;
csvPath?: string;
}

export interface BranchDiffRes {
Expand Down Expand Up @@ -64,6 +65,46 @@ export interface ModifiedFieldsType {
displayName: string;
path: string;
field: string;
propertyChanges?: PropertyChange[];
changeCount?: number;
changeDetails?: string;
oldValue?: any;
newValue?: any;
}

export interface PropertyChange {
property: string;
changeType: 'modified' | 'added' | 'deleted';
oldValue?: any;
newValue?: any;
}

export interface CSVRow {
srNo: number;
contentTypeName: string;
fieldName: string;
fieldPath: string;
operation: string;
sourceBranchValue: string;
targetBranchValue: string;
}

export interface AddCSVRowParams {
srNo: number;
contentTypeName: string;
fieldName: string;
fieldType: string;
sourceValue: string;
targetValue: string;
}

export const FIELD_TYPES = ['modified', 'added', 'deleted'] as const;

export const CSV_HEADER = 'Sr No,Content Type Name,Field Name,Field Path,Operation,Source Branch Value,Target Branch Value\n';

export interface ContentTypeItem {
title?: string;
uid?: string;
}

export interface ModifiedFieldsInput {
Expand All @@ -81,6 +122,7 @@ export interface BranchDiffVerboseRes {
modified?: BranchModifiedDetails[];
added?: BranchDiffRes[];
deleted?: BranchDiffRes[];
csvData?: CSVRow[]; // Pre-processed CSV data
}

export interface BranchDiffPayload {
Expand Down
Loading
Loading