@waron97/prbot 2.2.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 +8 -0
- package/src/commands/exportImperex.js +97 -0
- package/src/commands/exportPb.js +156 -0
- package/src/commands/init.js +8 -0
- package/src/commands/pr.js +1 -22
- package/src/index.js +51 -0
- package/src/lib/auth.js +25 -0
- 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
|
|
|
@@ -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 };
|
|
@@ -0,0 +1,156 @@
|
|
|
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
|
+
async function getProcessList(token) {
|
|
11
|
+
const url = `${process.env.IMPORTEXPORT_URL}/object/process_builder?addLanguageParam=true`;
|
|
12
|
+
const response = await fetch(url, {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
Authorization: `Bearer ${token}`,
|
|
17
|
+
},
|
|
18
|
+
body: JSON.stringify({ page: 1, size: 999999, filters: [] }),
|
|
19
|
+
});
|
|
20
|
+
if (!response.ok) throw new Error(await response.text());
|
|
21
|
+
const json = await response.json();
|
|
22
|
+
return json.data;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function initiateExport(guid, token) {
|
|
26
|
+
const url = `${process.env.IMPORTEXPORT_URL}/symphony/export`;
|
|
27
|
+
const response = await fetch(url, {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers: {
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
Authorization: `Bearer ${token}`,
|
|
32
|
+
},
|
|
33
|
+
body: JSON.stringify([{ object_guid: guid, object_type: 'process_builder' }]),
|
|
34
|
+
});
|
|
35
|
+
if (!response.ok) throw new Error(await response.text());
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function pollExportResult(guid, requestTime, token) {
|
|
39
|
+
const url = `${process.env.IMPORTEXPORT_URL}/export/info/processKey=ExportElement&subProcess=true&status=FAILED,COMPLETED&referenceId=process_builder`;
|
|
40
|
+
// Server createDate is offset -1hr from system time; subtract 1hr+5s buffer
|
|
41
|
+
const cutoff = requestTime - 3_605_000;
|
|
42
|
+
|
|
43
|
+
while (true) {
|
|
44
|
+
await new Promise((r) => setTimeout(r, 3000));
|
|
45
|
+
|
|
46
|
+
const response = await fetch(url, {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: {
|
|
49
|
+
'Content-Type': 'application/json',
|
|
50
|
+
Authorization: `Bearer ${token}`,
|
|
51
|
+
},
|
|
52
|
+
body: JSON.stringify({ page: 1, size: 7, sorters: [] }),
|
|
53
|
+
});
|
|
54
|
+
if (!response.ok) throw new Error(await response.text());
|
|
55
|
+
|
|
56
|
+
const { data } = await response.json();
|
|
57
|
+
const match = data.find(
|
|
58
|
+
(item) =>
|
|
59
|
+
item.customResponse?.guid === guid &&
|
|
60
|
+
new Date(item.createdDate).getTime() >= cutoff
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
if (!match) continue;
|
|
64
|
+
if (match.status === 'FAILED') throw new Error(`Export failed for guid ${guid}`);
|
|
65
|
+
return match.requestId;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function downloadZip(requestId, token) {
|
|
70
|
+
const url = `${process.env.IMPORTEXPORT_URL}/export/${requestId}`;
|
|
71
|
+
const response = await fetch(url, {
|
|
72
|
+
headers: {
|
|
73
|
+
'Content-Type': 'application/json',
|
|
74
|
+
Authorization: `Bearer ${token}`,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
if (!response.ok) throw new Error(await response.text());
|
|
78
|
+
return Buffer.from(await response.arrayBuffer());
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function findExistingZip(baseDir, filename) {
|
|
82
|
+
async function walk(dir) {
|
|
83
|
+
let entries;
|
|
84
|
+
try {
|
|
85
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
86
|
+
} catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
for (const entry of entries) {
|
|
90
|
+
const full = path.join(dir, entry.name);
|
|
91
|
+
if (entry.isDirectory()) {
|
|
92
|
+
const found = await walk(full);
|
|
93
|
+
if (found) return found;
|
|
94
|
+
} else if (entry.name === filename) {
|
|
95
|
+
return full;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
return walk(baseDir);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function exportPb(opts) {
|
|
104
|
+
const token = await getToken();
|
|
105
|
+
|
|
106
|
+
const processes = await getProcessList(token);
|
|
107
|
+
const choices = processes.map((p) => ({
|
|
108
|
+
name: `${p.process_name} (${p.document_id})`,
|
|
109
|
+
value: { guid: p.guid, document_id: p.document_id },
|
|
110
|
+
}));
|
|
111
|
+
|
|
112
|
+
const selected = await search({
|
|
113
|
+
message: 'Select PB process to export:',
|
|
114
|
+
source: async (input) => {
|
|
115
|
+
if (!input) return choices;
|
|
116
|
+
return choices.filter((c) => fuzzyMatch(c.name, input));
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const { guid, document_id } = selected;
|
|
121
|
+
const filename = `${document_id}.zip`;
|
|
122
|
+
|
|
123
|
+
console.log(`Initiating export for ${document_id}...`);
|
|
124
|
+
const requestTime = Date.now();
|
|
125
|
+
await initiateExport(guid, token);
|
|
126
|
+
|
|
127
|
+
console.log('Waiting for export to complete...');
|
|
128
|
+
const requestId = await pollExportResult(guid, requestTime, token);
|
|
129
|
+
|
|
130
|
+
console.log(`Downloading ${filename}...`);
|
|
131
|
+
const zipBuffer = await downloadZip(requestId, token);
|
|
132
|
+
|
|
133
|
+
const ADDONS_PATH = resolveAddonsPath(process.env.ADDONS_PATH);
|
|
134
|
+
const processesDir = path.join(ADDONS_PATH, '.cloudbuild', 'pb', 'B2WA', 'processes');
|
|
135
|
+
|
|
136
|
+
const existing = await findExistingZip(processesDir, filename);
|
|
137
|
+
let savePath;
|
|
138
|
+
if (existing) {
|
|
139
|
+
savePath = existing;
|
|
140
|
+
await fs.writeFile(savePath, zipBuffer);
|
|
141
|
+
console.log(`Updated existing file at ${savePath}`);
|
|
142
|
+
} else {
|
|
143
|
+
savePath = path.join(processesDir, 'all', filename);
|
|
144
|
+
await fs.mkdir(path.dirname(savePath), { recursive: true });
|
|
145
|
+
await fs.writeFile(savePath, zipBuffer);
|
|
146
|
+
console.log(`Created new file at ${savePath}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (opts.commit !== false) {
|
|
150
|
+
await execGit(['add', savePath], ADDONS_PATH);
|
|
151
|
+
await execGit(['commit', '-m', '[IMP][.cloudbuild] Update wizard'], ADDONS_PATH);
|
|
152
|
+
console.log('Committed.');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { exportPb };
|
package/src/commands/init.js
CHANGED
|
@@ -116,6 +116,14 @@ async function init(completion) {
|
|
|
116
116
|
message: 'AutoPR target branch:',
|
|
117
117
|
default: existing.AUTOPR_TARGET_BRANCH ?? '15.0-dev',
|
|
118
118
|
},
|
|
119
|
+
{
|
|
120
|
+
type: 'input',
|
|
121
|
+
name: 'IMPORTEXPORT_URL',
|
|
122
|
+
message: 'ImportExport URL:',
|
|
123
|
+
default:
|
|
124
|
+
existing.IMPORTEXPORT_URL ??
|
|
125
|
+
'https://sorgenia-test-02.symple.cloud/api/importexport/v1/',
|
|
126
|
+
},
|
|
119
127
|
]);
|
|
120
128
|
|
|
121
129
|
if (!answers.KC_PASSWORD && existing.KC_PASSWORD) {
|
package/src/commands/pr.js
CHANGED
|
@@ -3,28 +3,7 @@ import fs from 'fs/promises';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import fetch from 'node-fetch';
|
|
5
5
|
import { resolveAddonsPath } from '../lib/addons.js';
|
|
6
|
-
|
|
7
|
-
async function getToken() {
|
|
8
|
-
const url = process.env.KC_URL;
|
|
9
|
-
const payload = new URLSearchParams();
|
|
10
|
-
|
|
11
|
-
payload.append('username', process.env.KC_USER);
|
|
12
|
-
payload.append('password', process.env.KC_PASSWORD);
|
|
13
|
-
payload.append('client_id', process.env.KC_ID);
|
|
14
|
-
payload.append('client_secret', process.env.KC_SECRET);
|
|
15
|
-
payload.append('grant_type', 'password');
|
|
16
|
-
|
|
17
|
-
const response = await fetch(url, {
|
|
18
|
-
method: 'POST',
|
|
19
|
-
headers: {
|
|
20
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
21
|
-
},
|
|
22
|
-
body: payload.toString(),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const json = await response.json();
|
|
26
|
-
return json.access_token;
|
|
27
|
-
}
|
|
6
|
+
import { getToken } from '../lib/auth.js';
|
|
28
7
|
|
|
29
8
|
async function getFiles(module_name, token) {
|
|
30
9
|
const url = `${process.env.RIP_URL}/ir.model/xml_prbot`;
|
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,6 +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';
|
|
11
|
+
import { exportPb, exportRip, exportImperex } from './commands/export.js';
|
|
10
12
|
import { init } from './commands/init.js';
|
|
11
13
|
import { main as prMain } from './commands/pr.js';
|
|
12
14
|
import { verbot } from './commands/ver.js';
|
|
@@ -108,4 +110,53 @@ program.command('commit').action((opts) => {
|
|
|
108
110
|
});
|
|
109
111
|
});
|
|
110
112
|
|
|
113
|
+
const exportCmd = program.command('export');
|
|
114
|
+
|
|
115
|
+
exportCmd
|
|
116
|
+
.command('workflow <module>')
|
|
117
|
+
.option('-b, --bump <level>')
|
|
118
|
+
.action((module, opts) => {
|
|
119
|
+
prMain(module)
|
|
120
|
+
.then(() => {
|
|
121
|
+
if (opts.bump) {
|
|
122
|
+
return verbot(module, opts.bump);
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
.catch((err) => {
|
|
126
|
+
throw err;
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
exportCmd.command('rip').action(() => exportRip());
|
|
131
|
+
|
|
132
|
+
exportCmd
|
|
133
|
+
.command('pb')
|
|
134
|
+
.option('--no-commit')
|
|
135
|
+
.action((opts) => {
|
|
136
|
+
exportPb(opts).catch((err) => {
|
|
137
|
+
throw err;
|
|
138
|
+
});
|
|
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
|
+
|
|
111
162
|
program.parse();
|
package/src/lib/auth.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
|
|
3
|
+
async function getToken() {
|
|
4
|
+
const url = process.env.KC_URL;
|
|
5
|
+
const payload = new URLSearchParams();
|
|
6
|
+
|
|
7
|
+
payload.append('username', process.env.KC_USER);
|
|
8
|
+
payload.append('password', process.env.KC_PASSWORD);
|
|
9
|
+
payload.append('client_id', process.env.KC_ID);
|
|
10
|
+
payload.append('client_secret', process.env.KC_SECRET);
|
|
11
|
+
payload.append('grant_type', 'password');
|
|
12
|
+
|
|
13
|
+
const response = await fetch(url, {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
17
|
+
},
|
|
18
|
+
body: payload.toString(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const json = await response.json();
|
|
22
|
+
return json.access_token;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { getToken };
|
package/src/lib/fuzzy.js
ADDED