@contentstack/cli-cm-branches 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -5
- package/lib/branch/merge-handler.js +15 -2
- package/lib/commands/cm/branches/merge.js +1 -1
- package/lib/utils/branch-diff-utility.js +40 -18
- package/lib/utils/index.js +19 -1
- package/lib/utils/merge-helper.js +47 -5
- package/oclif.manifest.json +1 -1
- package/package.json +9 -2
package/README.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
# @contentstack/cli-cm-
|
|
2
|
-
|
|
3
|
-
It is Contentstack’s CLI plugin to export content from the stack. To learn how to export and import content in Contentstack, refer to the [Migration guide](https://www.contentstack.com/docs/developers/cli/migration/).
|
|
1
|
+
# @contentstack/cli-cm-branches
|
|
4
2
|
|
|
3
|
+
It is Contentstack’s CLI plugin to compare and merge content.
|
|
5
4
|
[](https://github.com/contentstack/cli/blob/main/LICENSE)
|
|
6
5
|
|
|
7
6
|
<!-- toc -->
|
|
8
|
-
* [@contentstack/cli-cm-
|
|
7
|
+
* [@contentstack/cli-cm-branches](#contentstackcli-cm-branches)
|
|
9
8
|
* [Usage](#usage)
|
|
10
9
|
* [Commands](#commands)
|
|
11
10
|
<!-- tocstop -->
|
|
@@ -38,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
|
|
|
38
37
|
$ csdx COMMAND
|
|
39
38
|
running command...
|
|
40
39
|
$ csdx (--version)
|
|
41
|
-
@contentstack/cli-cm-branches/1.0.
|
|
40
|
+
@contentstack/cli-cm-branches/1.0.7 linux-x64 node-v16.20.1
|
|
42
41
|
$ csdx --help [COMMAND]
|
|
43
42
|
USAGE
|
|
44
43
|
$ csdx COMMAND
|
|
@@ -15,7 +15,7 @@ class MergeHandler {
|
|
|
15
15
|
this.branchCompareData = options.branchCompareData;
|
|
16
16
|
this.displayFormat = options.format;
|
|
17
17
|
this.exportSummaryPath = options.exportSummaryPath || path_1.default.resolve(process.cwd());
|
|
18
|
-
this.
|
|
18
|
+
this.mergeSummary = options.mergeSummary;
|
|
19
19
|
this.userInputs = options;
|
|
20
20
|
this.mergeSettings = {
|
|
21
21
|
baseBranch: options.baseBranch,
|
|
@@ -28,10 +28,15 @@ class MergeHandler {
|
|
|
28
28
|
this.enableEntryExp = options.enableEntryExp;
|
|
29
29
|
}
|
|
30
30
|
async start() {
|
|
31
|
+
if (this.mergeSummary) {
|
|
32
|
+
this.loadMergeSettings();
|
|
33
|
+
await this.displayMergeSummary();
|
|
34
|
+
return await this.executeMerge(this.mergeSummary.requestPayload);
|
|
35
|
+
}
|
|
31
36
|
await this.collectMergeSettings();
|
|
32
|
-
// Merge final process
|
|
33
37
|
const mergePayload = (0, utils_1.prepareMergeRequestPayload)(this.mergeSettings);
|
|
34
38
|
if (this.executeOption === 'execute') {
|
|
39
|
+
await this.exportSummary(mergePayload);
|
|
35
40
|
await this.executeMerge(mergePayload);
|
|
36
41
|
}
|
|
37
42
|
else if (this.executeOption === 'export') {
|
|
@@ -223,5 +228,13 @@ class MergeHandler {
|
|
|
223
228
|
this.mergeSettings.itemMergeStrategies = [];
|
|
224
229
|
await this.start();
|
|
225
230
|
}
|
|
231
|
+
loadMergeSettings() {
|
|
232
|
+
this.mergeSettings.baseBranch = this.mergeSummary.requestPayload.base_branch;
|
|
233
|
+
this.mergeSettings.compareBranch = this.mergeSummary.requestPayload.compare_branch;
|
|
234
|
+
this.mergeSettings.strategy = this.mergeSummary.requestPayload.default_merge_strategy;
|
|
235
|
+
this.mergeSettings.itemMergeStrategies = this.mergeSummary.requestPayload.item_merge_strategies;
|
|
236
|
+
this.mergeSettings.noRevert = this.mergeSummary.requestPayload.no_revert;
|
|
237
|
+
this.mergeSettings.mergeComment = this.mergeSummary.requestPayload.merge_comment;
|
|
238
|
+
}
|
|
226
239
|
}
|
|
227
240
|
exports.default = MergeHandler;
|
|
@@ -29,7 +29,7 @@ class BranchMergeCommand extends cli_command_1.Command {
|
|
|
29
29
|
noRevert: branchMergeFlags['no-revert'],
|
|
30
30
|
format: 'compact-text',
|
|
31
31
|
exportSummaryPath: branchMergeFlags['export-summary-path'],
|
|
32
|
-
|
|
32
|
+
mergeSummary: branchMergeFlags.mergeSummary,
|
|
33
33
|
host: this.cmaHost,
|
|
34
34
|
enableEntryExp: true,
|
|
35
35
|
}).start();
|
|
@@ -270,42 +270,63 @@ async function baseAndCompareBranchDiff(params) {
|
|
|
270
270
|
await prepareModifiedDiff(params);
|
|
271
271
|
}
|
|
272
272
|
else if (baseBranchFieldExists && !compareBranchFieldExists) {
|
|
273
|
+
let displayName = baseBranchFieldExists === null || baseBranchFieldExists === void 0 ? void 0 : baseBranchFieldExists.display_name;
|
|
274
|
+
let path = baseBranchFieldExists === null || baseBranchFieldExists === void 0 ? void 0 : baseBranchFieldExists.uid;
|
|
275
|
+
let field = baseBranchFieldExists === null || baseBranchFieldExists === void 0 ? void 0 : baseBranchFieldExists.data_type;
|
|
276
|
+
if (baseBranchFieldExists.path === 'description') {
|
|
277
|
+
displayName = 'Description';
|
|
278
|
+
path = baseBranchFieldExists === null || baseBranchFieldExists === void 0 ? void 0 : baseBranchFieldExists.path;
|
|
279
|
+
field = 'metadata';
|
|
280
|
+
}
|
|
273
281
|
params.listOfDeletedFields.push({
|
|
274
|
-
path:
|
|
275
|
-
displayName:
|
|
282
|
+
path: path,
|
|
283
|
+
displayName: displayName,
|
|
276
284
|
uid: baseBranchFieldExists === null || baseBranchFieldExists === void 0 ? void 0 : baseBranchFieldExists.uid,
|
|
277
|
-
field:
|
|
285
|
+
field: field,
|
|
278
286
|
});
|
|
279
287
|
}
|
|
280
288
|
else if (!baseBranchFieldExists && compareBranchFieldExists) {
|
|
289
|
+
let displayName = compareBranchFieldExists === null || compareBranchFieldExists === void 0 ? void 0 : compareBranchFieldExists.display_name;
|
|
290
|
+
let path = compareBranchFieldExists === null || compareBranchFieldExists === void 0 ? void 0 : compareBranchFieldExists.uid;
|
|
291
|
+
let field = compareBranchFieldExists === null || compareBranchFieldExists === void 0 ? void 0 : compareBranchFieldExists.data_type;
|
|
292
|
+
if (compareBranchFieldExists.path === 'description') {
|
|
293
|
+
displayName = 'Description';
|
|
294
|
+
path = compareBranchFieldExists === null || compareBranchFieldExists === void 0 ? void 0 : compareBranchFieldExists.path;
|
|
295
|
+
field = 'metadata';
|
|
296
|
+
}
|
|
281
297
|
params.listOfAddedFields.push({
|
|
282
|
-
path:
|
|
283
|
-
displayName:
|
|
298
|
+
path: path,
|
|
299
|
+
displayName: displayName,
|
|
284
300
|
uid: compareBranchFieldExists === null || compareBranchFieldExists === void 0 ? void 0 : compareBranchFieldExists.uid,
|
|
285
|
-
field:
|
|
301
|
+
field: field,
|
|
286
302
|
});
|
|
287
303
|
}
|
|
288
304
|
}
|
|
289
305
|
async function prepareModifiedDiff(params) {
|
|
290
306
|
const { baseBranchFieldExists, compareBranchFieldExists } = params;
|
|
291
|
-
if (
|
|
292
|
-
|
|
293
|
-
|
|
307
|
+
if (compareBranchFieldExists.path === 'description' ||
|
|
308
|
+
compareBranchFieldExists.path === 'title' ||
|
|
309
|
+
compareBranchFieldExists.path === 'options.singleton') {
|
|
294
310
|
let displayName;
|
|
295
311
|
if (baseBranchFieldExists.path === 'options.singleton') {
|
|
296
|
-
|
|
312
|
+
if (compareBranchFieldExists.value) {
|
|
313
|
+
displayName = 'Single';
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
displayName = 'Multiple';
|
|
317
|
+
}
|
|
297
318
|
}
|
|
298
319
|
else if (baseBranchFieldExists.path === 'description') {
|
|
299
320
|
displayName = 'Description';
|
|
300
321
|
}
|
|
301
322
|
else if (baseBranchFieldExists.path === 'title') {
|
|
302
|
-
displayName = 'Name';
|
|
323
|
+
displayName = 'Display Name';
|
|
303
324
|
}
|
|
304
325
|
params.listOfModifiedFields.push({
|
|
305
|
-
path:
|
|
326
|
+
path: '',
|
|
306
327
|
displayName: displayName,
|
|
307
328
|
uid: baseBranchFieldExists.path,
|
|
308
|
-
field: '
|
|
329
|
+
field: 'changed',
|
|
309
330
|
});
|
|
310
331
|
}
|
|
311
332
|
else {
|
|
@@ -337,7 +358,7 @@ async function prepareModifiedDiff(params) {
|
|
|
337
358
|
path: field['path'],
|
|
338
359
|
displayName: field['displayName'],
|
|
339
360
|
uid: field['uid'],
|
|
340
|
-
field: field['fieldType']
|
|
361
|
+
field: `${field['fieldType']} field`,
|
|
341
362
|
});
|
|
342
363
|
}
|
|
343
364
|
}
|
|
@@ -377,14 +398,15 @@ exports.printVerboseTextView = printVerboseTextView;
|
|
|
377
398
|
function printModifiedFields(modfiedFields) {
|
|
378
399
|
var _a, _b, _c;
|
|
379
400
|
if (((_a = modfiedFields.modified) === null || _a === void 0 ? void 0 : _a.length) || ((_b = modfiedFields.added) === null || _b === void 0 ? void 0 : _b.length) || ((_c = modfiedFields.deleted) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
401
|
+
(0, forEach_1.default)(modfiedFields.modified, (diff) => {
|
|
402
|
+
const field = diff.field ? `${diff.field}` : 'field';
|
|
403
|
+
const fieldDetail = diff.path ? `(${diff.path}) ${field}` : `${field}`;
|
|
404
|
+
cli_utilities_1.cliux.print(` ${chalk_1.default.blue(`± "${diff.displayName}" ${fieldDetail}`)}`);
|
|
405
|
+
});
|
|
380
406
|
(0, forEach_1.default)(modfiedFields.added, (diff) => {
|
|
381
407
|
const field = diff.field ? `${diff.field} field` : 'field';
|
|
382
408
|
cli_utilities_1.cliux.print(` ${chalk_1.default.green(`+ "${diff.displayName}" (${diff.path}) ${field}`)}`);
|
|
383
409
|
});
|
|
384
|
-
(0, forEach_1.default)(modfiedFields.modified, (diff) => {
|
|
385
|
-
const field = diff.field ? `${diff.field} field` : 'field';
|
|
386
|
-
cli_utilities_1.cliux.print(` ${chalk_1.default.blue(`± "${diff.displayName}" (${diff.path}) ${field}`)}`);
|
|
387
|
-
});
|
|
388
410
|
(0, forEach_1.default)(modfiedFields.deleted, (diff) => {
|
|
389
411
|
const field = diff.field ? `${diff.field} field` : 'field';
|
|
390
412
|
cli_utilities_1.cliux.print(` ${chalk_1.default.red(`- "${diff.displayName}" (${diff.path}) ${field}`)}`);
|
package/lib/utils/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteBranchUtility = exports.branchDiffUtility = exports.interactive = exports.handleErrorMsg = exports.executeMergeRequest = exports.getMergeQueueStatus = exports.writeFile = exports.refreshbranchConfig = exports.getbranchConfig = exports.getbranchesList = void 0;
|
|
3
|
+
exports.deleteBranchUtility = exports.branchDiffUtility = exports.interactive = exports.handleErrorMsg = exports.executeMergeRequest = exports.getMergeQueueStatus = exports.readFile = exports.writeFile = exports.refreshbranchConfig = exports.getbranchConfig = exports.getbranchesList = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
/**
|
|
6
6
|
* Command specific utilities can be written here
|
|
@@ -47,6 +47,24 @@ const writeFile = (filePath, data) => {
|
|
|
47
47
|
});
|
|
48
48
|
};
|
|
49
49
|
exports.writeFile = writeFile;
|
|
50
|
+
// by default file type is json
|
|
51
|
+
const readFile = (filePath, options = { type: 'json' }) => {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
filePath = path_1.default.resolve(filePath);
|
|
54
|
+
fs_1.default.readFile(filePath, 'utf-8', (error, data) => {
|
|
55
|
+
if (error) {
|
|
56
|
+
reject(error);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
if (options.type !== 'json') {
|
|
60
|
+
return resolve(data);
|
|
61
|
+
}
|
|
62
|
+
resolve(JSON.parse(data));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
exports.readFile = readFile;
|
|
50
68
|
async function getMergeQueueStatus(stackAPIClient, payload) {
|
|
51
69
|
const mergeJobUID = payload.uid;
|
|
52
70
|
return await stackAPIClient
|
|
@@ -18,20 +18,62 @@ const prepareMergeRequestPayload = (options) => {
|
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
exports.prepareMergeRequestPayload = prepareMergeRequestPayload;
|
|
21
|
+
function validateMergeSummary(mergeSummary) {
|
|
22
|
+
if (!mergeSummary) {
|
|
23
|
+
cli_utilities_1.cliux.error(`Error: Invalid merge summary`, { color: 'red' });
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
else if (!mergeSummary.requestPayload) {
|
|
27
|
+
cli_utilities_1.cliux.print(`Error: Invalid merge summary, required 'requestPayload'`, { color: 'red' });
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
else if (!mergeSummary.requestPayload.base_branch) {
|
|
31
|
+
cli_utilities_1.cliux.print(`Error: Invalid merge summary, required 'requestPayload.base_branch'`, { color: 'red' });
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
else if (!mergeSummary.requestPayload.compare_branch) {
|
|
35
|
+
cli_utilities_1.cliux.print(`Error: Invalid merge summary, required 'requestPayload.compare_branch'`, { color: 'red' });
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
else if (!mergeSummary.requestPayload.default_merge_strategy) {
|
|
39
|
+
cli_utilities_1.cliux.print(`Error: Invalid merge summary, required 'requestPayload.default_merge_strategy'`, { color: 'red' });
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
else if (!mergeSummary.requestPayload.default_merge_strategy) {
|
|
43
|
+
cli_utilities_1.cliux.print(`Error: Invalid merge summary, required 'requestPayload.default_merge_strategy'`, { color: 'red' });
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
21
47
|
const setupMergeInputs = async (mergeFlags) => {
|
|
48
|
+
if (mergeFlags['use-merge-summary']) {
|
|
49
|
+
let mergeSummary = (await (0, _1.readFile)(mergeFlags['use-merge-summary']));
|
|
50
|
+
validateMergeSummary(mergeSummary);
|
|
51
|
+
mergeFlags.mergeSummary = mergeSummary;
|
|
52
|
+
}
|
|
53
|
+
let { requestPayload: { base_branch = null, compare_branch = null } = {} } = mergeFlags.mergeSummary || {};
|
|
22
54
|
if (!mergeFlags['stack-api-key']) {
|
|
23
55
|
mergeFlags['stack-api-key'] = await (0, _1.askStackAPIKey)();
|
|
24
56
|
}
|
|
25
57
|
if (!mergeFlags['compare-branch']) {
|
|
26
|
-
|
|
58
|
+
if (!compare_branch) {
|
|
59
|
+
mergeFlags['compare-branch'] = await (0, _1.askCompareBranch)();
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
mergeFlags['compare-branch'] = compare_branch;
|
|
63
|
+
}
|
|
27
64
|
}
|
|
28
65
|
if (!mergeFlags['base-branch']) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
mergeFlags['base-branch']
|
|
66
|
+
if (!base_branch) {
|
|
67
|
+
mergeFlags['base-branch'] = (0, _1.getbranchConfig)(mergeFlags['stack-api-key']);
|
|
68
|
+
if (!mergeFlags['base-branch']) {
|
|
69
|
+
mergeFlags['base-branch'] = await (0, _1.askBaseBranch)();
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
cli_utilities_1.cliux.print(`\nBase branch: ${mergeFlags['base-branch']}\n`, { color: 'grey' });
|
|
73
|
+
}
|
|
32
74
|
}
|
|
33
75
|
else {
|
|
34
|
-
|
|
76
|
+
mergeFlags['base-branch'] = base_branch;
|
|
35
77
|
}
|
|
36
78
|
}
|
|
37
79
|
return mergeFlags;
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-branches",
|
|
3
3
|
"description": "Contentstack CLI plugin to do branches operations",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.7",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -87,6 +87,13 @@
|
|
|
87
87
|
"bin": "csdx",
|
|
88
88
|
"repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-export/<%- commandPath %>"
|
|
89
89
|
},
|
|
90
|
-
"csdxConfig": {
|
|
90
|
+
"csdxConfig": {
|
|
91
|
+
"shortCommandName": {
|
|
92
|
+
"cm:branches:create": "BRCR",
|
|
93
|
+
"cm:branches:delete": "BRDEL",
|
|
94
|
+
"cm:branches:diff": "BRDIF",
|
|
95
|
+
"cm:branches:merge": "BRMRG"
|
|
96
|
+
}
|
|
97
|
+
},
|
|
91
98
|
"repository": "https://github.com/contentstack/cli"
|
|
92
99
|
}
|