@waron97/prbot 2.3.0 → 2.4.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/README.md +61 -0
- package/package.json +1 -1
- package/src/commands/autopr.js +2 -1
- package/src/commands/changelog.js +2 -5
- package/src/commands/export.js +2 -1
- package/src/commands/exportImperex.js +97 -0
- package/src/commands/exportPb.js +2 -2
- package/src/index.js +23 -1
- package/src/lib/fuzzy.js +13 -0
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@ source ~/.bashrc
|
|
|
42
42
|
| `DEVOPS_PROJECT` | Azure DevOps project |
|
|
43
43
|
| `DEVOPS_REPO` | Azure DevOps repository name |
|
|
44
44
|
| `AUTOPR_TARGET_BRANCH` | Target branch for auto-created PRs (default: `15.0-dev`) |
|
|
45
|
+
| `IMPORTEXPORT_URL` | ImportExport API base URL |
|
|
45
46
|
|
|
46
47
|
## Commands
|
|
47
48
|
|
|
@@ -115,10 +116,70 @@ Options:
|
|
|
115
116
|
| `-b, --branch <name>` | Branch name (default: `autopr_<first-task-id>` or `autopr_<first-jira>`) |
|
|
116
117
|
| `-n, --name <text>` | PR title (default: Trident task name) |
|
|
117
118
|
|
|
119
|
+
### `prbot commit`
|
|
120
|
+
|
|
121
|
+
Interactive commit builder. Prompts for operation type (`[IMP]`, `[FIX]`, etc.), what changed (workflow, module, wizard, symphony process), and a message. If nothing is staged, shows unstaged files and lets you select which to stage first. Previews the final commit message before confirming.
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
prbot commit
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### `prbot export workflow <module>`
|
|
128
|
+
|
|
129
|
+
Alias for `prbot pr <module>`. Fetches workflow XML and commits.
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
prbot export workflow config_wf_contestazione
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Options:
|
|
136
|
+
|
|
137
|
+
| Flag | Description |
|
|
138
|
+
| -------------------- | ------------------------------------------------------------------------- |
|
|
139
|
+
| `-b, --bump <level>` | Also bump manifest version after commit. Level: `major`, `minor`, `patch` |
|
|
140
|
+
|
|
141
|
+
### `prbot export pb`
|
|
142
|
+
|
|
143
|
+
Exports a Process Builder process from the ImportExport API and writes the ZIP to `ADDONS_PATH/.cloudbuild/pb/B2WA/processes/`. Updates the file in place if it already exists, otherwise writes to the `all/` subdirectory. Prompts to select the process via fuzzy search.
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
prbot export pb
|
|
147
|
+
prbot export pb --no-commit
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Options:
|
|
151
|
+
|
|
152
|
+
| Flag | Description |
|
|
153
|
+
| ------------- | ------------------------ |
|
|
154
|
+
| `--no-commit` | Skip the git commit step |
|
|
155
|
+
|
|
156
|
+
### `prbot export imperex`
|
|
157
|
+
|
|
158
|
+
Exports a single Imperex record from Odoo via RIP and writes the resulting YAML into `ADDONS_PATH/sorgenia_imperex_metadata/migrations/0.0.0/imperex/<model>/`. Prompts first for the model (from local folder names), then for the record (fetched from API). Both prompts support fuzzy search.
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
prbot export imperex
|
|
162
|
+
prbot export imperex --no-commit
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Options:
|
|
166
|
+
|
|
167
|
+
| Flag | Description |
|
|
168
|
+
| ------------- | ------------------------ |
|
|
169
|
+
| `--no-commit` | Skip the git commit step |
|
|
170
|
+
|
|
118
171
|
### `prbot init`
|
|
119
172
|
|
|
120
173
|
Interactive setup: writes `~/.config/prbot/config` and installs shell completion.
|
|
121
174
|
|
|
175
|
+
### `prbot update`
|
|
176
|
+
|
|
177
|
+
Reinstalls the latest published version from npm.
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
prbot update
|
|
181
|
+
```
|
|
182
|
+
|
|
122
183
|
## Tab completion
|
|
123
184
|
|
|
124
185
|
After `prbot init` and sourcing `~/.bashrc`, `<module>` arguments autocomplete from directories in `ADDONS_PATH/config/`.
|
package/package.json
CHANGED
package/src/commands/autopr.js
CHANGED
|
@@ -4,6 +4,7 @@ import search from '@inquirer/search';
|
|
|
4
4
|
import inquirer from 'inquirer';
|
|
5
5
|
import fetch from 'node-fetch';
|
|
6
6
|
import { resolveAddonsPath } from '../lib/addons.js';
|
|
7
|
+
import { fuzzyMatch } from '../lib/fuzzy.js';
|
|
7
8
|
import { execGit } from '../lib/git.js';
|
|
8
9
|
import {
|
|
9
10
|
appendPrToLine,
|
|
@@ -176,7 +177,7 @@ async function selectSection(sections, candidates) {
|
|
|
176
177
|
message: 'Select changelog section:',
|
|
177
178
|
source: async (input) => {
|
|
178
179
|
if (!input) return allChoices;
|
|
179
|
-
return allChoices.filter((c) => c.value
|
|
180
|
+
return allChoices.filter((c) => fuzzyMatch(c.value, input));
|
|
180
181
|
},
|
|
181
182
|
});
|
|
182
183
|
return sections.find((s) => s.heading === selected);
|
|
@@ -3,6 +3,7 @@ import fs from 'fs/promises';
|
|
|
3
3
|
import search from '@inquirer/search';
|
|
4
4
|
import inquirer from 'inquirer';
|
|
5
5
|
import { resolveAddonsPath } from '../lib/addons.js';
|
|
6
|
+
import { fuzzyMatch } from '../lib/fuzzy.js';
|
|
6
7
|
|
|
7
8
|
function buildRefString(tridents, jiras, prNumber) {
|
|
8
9
|
const refs = [];
|
|
@@ -159,11 +160,7 @@ async function changelog(prNumber, options) {
|
|
|
159
160
|
return sectionChoices;
|
|
160
161
|
}
|
|
161
162
|
|
|
162
|
-
|
|
163
|
-
choice.name.toLowerCase().includes(input.toLowerCase())
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
return filtered;
|
|
163
|
+
return sectionChoices.filter((choice) => fuzzyMatch(choice.name, input));
|
|
167
164
|
},
|
|
168
165
|
});
|
|
169
166
|
|
package/src/commands/export.js
CHANGED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fetch from 'node-fetch';
|
|
4
|
+
import search from '@inquirer/search';
|
|
5
|
+
import { getToken } from '../lib/auth.js';
|
|
6
|
+
import { execGit } from '../lib/git.js';
|
|
7
|
+
import { resolveAddonsPath } from '../lib/addons.js';
|
|
8
|
+
import { fuzzyMatch } from '../lib/fuzzy.js';
|
|
9
|
+
|
|
10
|
+
const IMPEREX_REL = 'sorgenia_imperex_metadata/migrations/0.0.0/imperex';
|
|
11
|
+
|
|
12
|
+
async function getModels(addonsPath) {
|
|
13
|
+
const dir = path.join(addonsPath, IMPEREX_REL);
|
|
14
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
15
|
+
return entries.filter((e) => e.isDirectory()).map((e) => e.name);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function listRecords(model, token) {
|
|
19
|
+
const url = `${process.env.RIP_URL}/helpdesk.ticket/prbot_list_records`;
|
|
20
|
+
const response = await fetch(url, {
|
|
21
|
+
method: 'POST',
|
|
22
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
|
23
|
+
body: JSON.stringify({ model }),
|
|
24
|
+
});
|
|
25
|
+
if (!response.ok) throw new Error(await response.text());
|
|
26
|
+
return await response.json();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function exportRecord(model, id, token) {
|
|
30
|
+
const url = `${process.env.RIP_URL}/helpdesk.ticket/prbot_imperex_export`;
|
|
31
|
+
const response = await fetch(url, {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
|
34
|
+
body: JSON.stringify({
|
|
35
|
+
export_to: 'yaml',
|
|
36
|
+
make_zip: true,
|
|
37
|
+
manifest: {},
|
|
38
|
+
recs: { [model]: [id] },
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
if (!response.ok) throw new Error(await response.text());
|
|
42
|
+
return await response.json();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function exportImperex(opts) {
|
|
46
|
+
const token = await getToken();
|
|
47
|
+
const ADDONS_PATH = resolveAddonsPath(process.env.ADDONS_PATH);
|
|
48
|
+
|
|
49
|
+
const models = await getModels(ADDONS_PATH);
|
|
50
|
+
const modelChoices = models.map((m) => ({ name: m, value: m }));
|
|
51
|
+
const model = await search({
|
|
52
|
+
message: 'Select Imperex model:',
|
|
53
|
+
source: async (input) => {
|
|
54
|
+
if (!input) return modelChoices;
|
|
55
|
+
return modelChoices.filter((c) => fuzzyMatch(c.name, input));
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
console.log(`Fetching records for ${model}...`);
|
|
60
|
+
const records = await listRecords(model, token);
|
|
61
|
+
const recChoices = records.map((r) => ({ name: String(r.name ?? r.id), value: r.id }));
|
|
62
|
+
const recordId = await search({
|
|
63
|
+
message: 'Select record to export:',
|
|
64
|
+
source: async (input) => {
|
|
65
|
+
if (!input) return recChoices;
|
|
66
|
+
return recChoices.filter((c) => fuzzyMatch(c.name, input));
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
console.log(`Exporting record ${recordId}...`);
|
|
71
|
+
const { attachments } = await exportRecord(model, recordId, token);
|
|
72
|
+
|
|
73
|
+
const modelDir = path.join(ADDONS_PATH, IMPEREX_REL, model);
|
|
74
|
+
await fs.mkdir(modelDir, { recursive: true });
|
|
75
|
+
|
|
76
|
+
const saved = [];
|
|
77
|
+
for (const att of attachments) {
|
|
78
|
+
if (att.name === '__manifest__.yaml') continue;
|
|
79
|
+
const destPath = path.join(modelDir, path.basename(att.name));
|
|
80
|
+
await fs.writeFile(destPath, att.content, 'utf-8');
|
|
81
|
+
console.log(`Written: ${destPath}`);
|
|
82
|
+
saved.push(destPath);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (opts.commit !== false) {
|
|
86
|
+
for (const p of saved) {
|
|
87
|
+
await execGit(['add', p], ADDONS_PATH);
|
|
88
|
+
}
|
|
89
|
+
await execGit(
|
|
90
|
+
['commit', '-m', `[IMP][sorgenia_imperex_metadata] update ${model} record`],
|
|
91
|
+
ADDONS_PATH,
|
|
92
|
+
);
|
|
93
|
+
console.log('Committed.');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { exportImperex };
|
package/src/commands/exportPb.js
CHANGED
|
@@ -5,6 +5,7 @@ import search from '@inquirer/search';
|
|
|
5
5
|
import { getToken } from '../lib/auth.js';
|
|
6
6
|
import { execGit } from '../lib/git.js';
|
|
7
7
|
import { resolveAddonsPath } from '../lib/addons.js';
|
|
8
|
+
import { fuzzyMatch } from '../lib/fuzzy.js';
|
|
8
9
|
|
|
9
10
|
async function getProcessList(token) {
|
|
10
11
|
const url = `${process.env.IMPORTEXPORT_URL}/object/process_builder?addLanguageParam=true`;
|
|
@@ -112,8 +113,7 @@ async function exportPb(opts) {
|
|
|
112
113
|
message: 'Select PB process to export:',
|
|
113
114
|
source: async (input) => {
|
|
114
115
|
if (!input) return choices;
|
|
115
|
-
|
|
116
|
-
return choices.filter((c) => c.name.toLowerCase().includes(q));
|
|
116
|
+
return choices.filter((c) => fuzzyMatch(c.name, input));
|
|
117
117
|
},
|
|
118
118
|
});
|
|
119
119
|
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readdirSync, readFileSync } from 'fs';
|
|
3
|
+
import { execFile } from 'child_process';
|
|
3
4
|
import path from 'path';
|
|
4
5
|
import { program } from 'commander';
|
|
5
6
|
import { configDotenv } from 'dotenv';
|
|
@@ -7,7 +8,7 @@ import omelette from 'omelette';
|
|
|
7
8
|
import { autopr } from './commands/autopr.js';
|
|
8
9
|
import { changelog } from './commands/changelog.js';
|
|
9
10
|
import { commit } from './commands/commit.js';
|
|
10
|
-
import { exportPb, exportRip } from './commands/export.js';
|
|
11
|
+
import { exportPb, exportRip, exportImperex } from './commands/export.js';
|
|
11
12
|
import { init } from './commands/init.js';
|
|
12
13
|
import { main as prMain } from './commands/pr.js';
|
|
13
14
|
import { verbot } from './commands/ver.js';
|
|
@@ -137,4 +138,25 @@ exportCmd
|
|
|
137
138
|
});
|
|
138
139
|
});
|
|
139
140
|
|
|
141
|
+
exportCmd
|
|
142
|
+
.command('imperex')
|
|
143
|
+
.option('--no-commit')
|
|
144
|
+
.action((opts) => {
|
|
145
|
+
exportImperex(opts).catch((err) => {
|
|
146
|
+
throw err;
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
program.command('update').action(() => {
|
|
151
|
+
console.log('Updating prbot...');
|
|
152
|
+
execFile('npm', ['i', '-g', '@waron97/prbot'], (error, stdout, stderr) => {
|
|
153
|
+
if (error) {
|
|
154
|
+
console.error(stderr || error.message);
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
console.log(stdout);
|
|
158
|
+
console.log('Done.');
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
140
162
|
program.parse();
|
package/src/lib/fuzzy.js
ADDED