@waron97/prbot 1.0.0
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/dotenv +85908 -0
- package/example.xml +3903 -0
- package/index.js +247 -0
- package/out/xml_data_for_ML - RISOLUZIONE CONTRATTUALE - Relazioni mancanti: Fasi - Workflow e Fasi - Esiti Consentiti_2026-01-23 09:21:16.xml +3122 -0
- package/out/xml_data_for_ML - RISOLUZIONE CONTRATTUALE - Relazioni mancanti: Fasi - Workflow e Fasi - Esiti Consentiti_2026-01-23 09:25:03.xml +3122 -0
- package/out/xml_data_for_ML - RISOLUZIONE CONTRATTUALE - Relazioni mancanti: Fasi - Workflow e Fasi - Esiti Consentiti_2026-01-23 09:28:23.xml +3122 -0
- package/out/xml_data_for_ML - RISOLUZIONE CONTRATTUALE - Relazioni mancanti: Fasi - Workflow e Fasi - Esiti Consentiti_2026-01-23 09:31:30.xml +3122 -0
- package/out/xml_data_for_ML - RISOLUZIONE CONTRATTUALE - Relazioni mancanti: Fasi - Workflow e Fasi - Esiti Consentiti_2026-01-26 22:53:31.xml +3170 -0
- package/out/xml_data_for_ML - RISOLUZIONE CONTRATTUALE - Relazioni mancanti: Fasi - Workflow e Fasi - Esiti Consentiti_2026-01-29 09:38:23.xml +3170 -0
- package/out/xml_data_for_ML - RISOLUZIONE CONTRATTUALE_2026-01-23 09:21:17.xml +4160 -0
- package/out/xml_data_for_ML - RISOLUZIONE CONTRATTUALE_2026-01-23 09:25:05.xml +4160 -0
- package/out/xml_data_for_ML - RISOLUZIONE CONTRATTUALE_2026-01-23 09:28:25.xml +4160 -0
- package/out/xml_data_for_ML - RISOLUZIONE CONTRATTUALE_2026-01-23 09:31:31.xml +4160 -0
- package/out/xml_data_for_ML - RISOLUZIONE CONTRATTUALE_2026-01-26 22:53:34.xml +4208 -0
- package/out/xml_data_for_ML - RISOLUZIONE CONTRATTUALE_2026-01-29 09:38:25.xml +4208 -0
- package/out/xml_data_for_ML - Taglio Colonna Gas per Morosit/303/240 - Relazioni mancanti: Fasi - Workflow e Fasi - Esiti Consentiti_2026-01-26 22:57:38.xml" +2358 -0
- package/out/xml_data_for_ML - Taglio Colonna Gas per Morosit/303/240_2026-01-26 22:57:40.xml" +3667 -0
- package/package.json +31 -0
package/index.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { configDotenv } from "dotenv";
|
|
4
|
+
import fetch from "node-fetch";
|
|
5
|
+
import fs from "fs/promises";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { execFile } from "child_process";
|
|
8
|
+
import { program } from "commander";
|
|
9
|
+
|
|
10
|
+
configDotenv({ path: path.join(process.env.HOME, ".prbot") });
|
|
11
|
+
|
|
12
|
+
async function getToken() {
|
|
13
|
+
const url = process.env.KC_URL;
|
|
14
|
+
const payload = new URLSearchParams();
|
|
15
|
+
|
|
16
|
+
payload.append("username", process.env.KC_USER);
|
|
17
|
+
payload.append("password", process.env.KC_PASSWORD);
|
|
18
|
+
payload.append("client_id", process.env.KC_ID);
|
|
19
|
+
payload.append("client_secret", process.env.KC_SECRET);
|
|
20
|
+
payload.append("grant_type", "password");
|
|
21
|
+
|
|
22
|
+
const response = await fetch(url, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: {
|
|
25
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
26
|
+
},
|
|
27
|
+
body: payload.toString(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const json = await response.json();
|
|
31
|
+
return json.access_token;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function getFiles(module_name, token) {
|
|
35
|
+
const url = `${process.env.RIP_URL}/ir.model/xml_prbot`;
|
|
36
|
+
const body = JSON.stringify({ module_name });
|
|
37
|
+
const headers = {
|
|
38
|
+
Authorization: `Bearer ${token}`,
|
|
39
|
+
"Content-Type": "application/json",
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const response = await fetch(url, { method: "POST", body, headers });
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
throw new Error(await response.text());
|
|
45
|
+
}
|
|
46
|
+
return await response.json();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function main(module_name) {
|
|
50
|
+
const token = await getToken();
|
|
51
|
+
const files = await getFiles(module_name, token);
|
|
52
|
+
|
|
53
|
+
let ADDONS_PATH = process.env.ADDONS_PATH;
|
|
54
|
+
if (ADDONS_PATH.startsWith("~")) {
|
|
55
|
+
ADDONS_PATH = ADDONS_PATH.replace("~", process.env.HOME);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Create out directory
|
|
59
|
+
|
|
60
|
+
// Write files temporarily and process them
|
|
61
|
+
for (const file of files) {
|
|
62
|
+
const buffer = Buffer.from(file.data, "base64");
|
|
63
|
+
|
|
64
|
+
// Read and process the file
|
|
65
|
+
let content = buffer.toString();
|
|
66
|
+
|
|
67
|
+
// Remove the last two lines
|
|
68
|
+
const lines = content.split("\n");
|
|
69
|
+
if (lines.length > 2) {
|
|
70
|
+
lines.splice(-2);
|
|
71
|
+
}
|
|
72
|
+
content = lines.join("\n");
|
|
73
|
+
|
|
74
|
+
// Remove the bpmn_diagram field pattern
|
|
75
|
+
content = content.replace(
|
|
76
|
+
/<field name="bpmn_diagram"><!\[CDATA\[[\s\S]*?\]\]><\/field>/g,
|
|
77
|
+
"",
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// Determine the destination path based on filename
|
|
81
|
+
let destPath;
|
|
82
|
+
if (file.name.includes("Relazioni mancanti")) {
|
|
83
|
+
destPath = `${ADDONS_PATH}/config/${module_name}/data/workflow_missing_relations.xml`;
|
|
84
|
+
} else {
|
|
85
|
+
destPath = `${ADDONS_PATH}/config/${module_name}/data/workflow_configuration.xml`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Create destination directory if needed
|
|
89
|
+
await fs.mkdir(path.dirname(destPath), { recursive: true });
|
|
90
|
+
|
|
91
|
+
// Write the processed file
|
|
92
|
+
await fs.writeFile(destPath, content);
|
|
93
|
+
console.log(`Processed: ${file.name} -> ${destPath}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Git operations
|
|
97
|
+
const workflowDir = path.join(ADDONS_PATH, "config", module_name, "data");
|
|
98
|
+
const filesToAdd = [
|
|
99
|
+
path.join(workflowDir, "workflow_missing_relations.xml"),
|
|
100
|
+
path.join(workflowDir, "workflow_configuration.xml"),
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
// Add files to git
|
|
104
|
+
for (const filePath of filesToAdd) {
|
|
105
|
+
await new Promise((resolve, reject) => {
|
|
106
|
+
execFile("git", ["add", filePath], { cwd: ADDONS_PATH }, (error) => {
|
|
107
|
+
if (error) reject(error);
|
|
108
|
+
else resolve();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Commit changes
|
|
114
|
+
const commitMessage = `[IMP][${module_name}] Update workflow`;
|
|
115
|
+
await new Promise((resolve, reject) => {
|
|
116
|
+
execFile(
|
|
117
|
+
"git",
|
|
118
|
+
["commit", "-m", commitMessage],
|
|
119
|
+
{ cwd: ADDONS_PATH },
|
|
120
|
+
(error) => {
|
|
121
|
+
if (error) reject(error);
|
|
122
|
+
else resolve();
|
|
123
|
+
},
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
console.log(`Committed with message: ${commitMessage}`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function verbot(module_name, level) {
|
|
131
|
+
if (!["major", "minor", "patch"].includes(level)) {
|
|
132
|
+
throw new Error("Level must be one of major, minor, patch");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let ADDONS_PATH = process.env.ADDONS_PATH;
|
|
136
|
+
if (ADDONS_PATH.startsWith("~")) {
|
|
137
|
+
ADDONS_PATH = ADDONS_PATH.replace("~", process.env.HOME);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Try to find manifest file in either location
|
|
141
|
+
let manifestPath = path.join(ADDONS_PATH, module_name, "__manifest__.py");
|
|
142
|
+
try {
|
|
143
|
+
await fs.access(manifestPath);
|
|
144
|
+
} catch {
|
|
145
|
+
manifestPath = path.join(
|
|
146
|
+
ADDONS_PATH,
|
|
147
|
+
"config",
|
|
148
|
+
module_name,
|
|
149
|
+
"__manifest__.py",
|
|
150
|
+
);
|
|
151
|
+
try {
|
|
152
|
+
await fs.access(manifestPath);
|
|
153
|
+
} catch {
|
|
154
|
+
throw new Error(`__manifest__.py not found for module ${module_name}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Read the manifest file
|
|
159
|
+
const content = await fs.readFile(manifestPath, "utf-8");
|
|
160
|
+
|
|
161
|
+
// Find and increment version
|
|
162
|
+
const versionMatch = content.match(/"version":\s*"(15\.0\.\d+\.\d+\.\d+)"/);
|
|
163
|
+
if (!versionMatch) {
|
|
164
|
+
throw new Error("Version not found in manifest");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const currentVersion = versionMatch[1];
|
|
168
|
+
const parts = currentVersion.split(".");
|
|
169
|
+
const base = `${parts[0]}.${parts[1]}`;
|
|
170
|
+
const major = parseInt(parts[2]);
|
|
171
|
+
const minor = parseInt(parts[3]);
|
|
172
|
+
const patch = parseInt(parts[4]);
|
|
173
|
+
|
|
174
|
+
let newVersion;
|
|
175
|
+
if (level === "patch") {
|
|
176
|
+
newVersion = `${base}.${major}.${minor}.${patch + 1}`;
|
|
177
|
+
} else if (level === "minor") {
|
|
178
|
+
newVersion = `${base}.${major}.${minor + 1}.0`;
|
|
179
|
+
} else if (level === "major") {
|
|
180
|
+
newVersion = `${base}.${major + 1}.0.0`;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Replace only the version line
|
|
184
|
+
const newContent = content.replace(
|
|
185
|
+
`"version": "${currentVersion}"`,
|
|
186
|
+
`"version": "${newVersion}"`,
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
// Write back the manifest
|
|
190
|
+
await fs.writeFile(manifestPath, newContent);
|
|
191
|
+
console.log(`Updated version: ${currentVersion} -> ${newVersion}`);
|
|
192
|
+
|
|
193
|
+
// Git add and commit
|
|
194
|
+
await new Promise((resolve, reject) => {
|
|
195
|
+
execFile("git", ["add", manifestPath], { cwd: ADDONS_PATH }, (error) => {
|
|
196
|
+
if (error) reject(error);
|
|
197
|
+
else resolve();
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const commitMessage = `[VER][${module_name}] Bump`;
|
|
202
|
+
await new Promise((resolve, reject) => {
|
|
203
|
+
execFile(
|
|
204
|
+
"git",
|
|
205
|
+
["commit", "-m", commitMessage],
|
|
206
|
+
{ cwd: ADDONS_PATH },
|
|
207
|
+
(error) => {
|
|
208
|
+
if (error) reject(error);
|
|
209
|
+
else resolve();
|
|
210
|
+
},
|
|
211
|
+
);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
console.log(`Committed with message: ${commitMessage}`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
program
|
|
218
|
+
.command("pr")
|
|
219
|
+
.option("-m, --module <module>")
|
|
220
|
+
.option("-b, --bump <level>")
|
|
221
|
+
.action((opts) => {
|
|
222
|
+
if (!opts.module) {
|
|
223
|
+
throw new Error("No module specified");
|
|
224
|
+
}
|
|
225
|
+
main(opts.module)
|
|
226
|
+
.then(() => {
|
|
227
|
+
if (opts.bump) {
|
|
228
|
+
return verbot(opts.module, opts.bump);
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
.catch((err) => {
|
|
232
|
+
throw err;
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
program
|
|
237
|
+
.command("ver")
|
|
238
|
+
.option("-m, --module <module>")
|
|
239
|
+
.option("-b, --bump <level>")
|
|
240
|
+
.action((opts) => {
|
|
241
|
+
if (!opts.module || !opts.bump) {
|
|
242
|
+
throw new Error("No module or level specified");
|
|
243
|
+
}
|
|
244
|
+
verbot(opts.module, opts.bump);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
program.parse();
|