-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFindMissingChangesets.js
More file actions
executable file
·112 lines (97 loc) · 3.5 KB
/
Copy pathFindMissingChangesets.js
File metadata and controls
executable file
·112 lines (97 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env node
/*jshint esversion: 8 */
/*jshint -W069 */
const BaseScript = require('./lib/BaseScript.js');
const objectPath = require("object-path");
const chalk = require('chalk');
const Logger = require('basic-logger');
const log = new Logger({
showMillis: false,
showTimestamp: false
});
Logger.setLevel('info', true);
// For each node, grabe it's changeset it and verify that the changeset exists. If not then refresh the node
module.exports = class FindMissingChangesets extends BaseScript {
constructor() {
super(defaultOptions, defaultHelpMessage);
}
/** exec()
* entry point
*/
async exec() {
await this.connect();
log.info(chalk.yellow("Connected to project: \"" + this.project.title + "\" and branch: " + this.branch.title || this.branch._doc));
this.option_queryFilePath = this.options["query-file-path"] || null;
this.option_refreshNodes = this.options["refresh-nodes"] || false;
let query = {};
if (this.option_queryFilePath) {
query = require(this.option_queryFilePath);
}
query._fields = {
"_system.changeset": 1
};
let offset = 0;
let limit = 50;
while (true) {
let result = await this.session.queryNodes(this.repository, this.branch, query, { metadata: true, full: true, limit: limit, offset: offset });
result.rows.forEach(async node => {
// log.info(`${node._doc}: ${node._system.changeset}`);
// check for valid changeset id
let changeset = await this.session.readChangeset(this.repository, node._system.changeset);
if (changeset && changeset._doc) {
// log.info(`${node._doc}: ${node._system.changeset}`);
// log.info(`\t${JSON.stringify(changeset, null, 2)}`);
} else {
log.info(`\tchangeset ${node._system.changeset} not found for node ${node._doc}`);
if (this.option_refreshNodes) {
log.info('\trefreshing node...');
this.session.refreshNode(this.repository, this.branch, patch.node);
}
}
});
offset += limit;
log.info(`Checked ${offset} of ${result.total_rows} nodes`);
if (result.total_rows <= offset) {
break;
}
}
log.info("Done");
}
};
const defaultOptions = [
{
name: 'query-file-path',
alias: 'y',
type: String,
required: true,
description: 'path to a json file defining the query'
},
{
name: 'refresh-nodes',
type: Boolean,
default: false,
description: 'if true only list nodes with missing changesets (don\'t call refresh). If true, call refresh for those nodes'
}
];
const defaultHelpMessage = [
{
header: 'Cloud CMS Patch Nodes',
content: 'Update nodes in a branch by applying an HTTP PATCH method API call. The nodes to update are identified by a provided query.'
},
{
header: 'Examples',
content: [{
desc: '\n1. Report nodes with missing changeset:',
},
{
desc: 'npx cloudcms-util find-missing-changesets'
},
{
desc: '\n2. Call refresh api for nodes with missing changeset:',
},
{
desc: 'npx cloudcms-util find-missing-changesets --refresh-nodes'
}
]
}
];