@waron97/prbot 3.0.2 → 3.0.4
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/package.json +1 -1
- package/src/agrippa/commands/init.js +11 -7
- package/src/agrippa/commands/pull.js +10 -40
- package/src/agrippa/lib/config.js +1 -1
- package/src/commands/autopr.js +4 -2
- package/src/index.js +11 -1
- package/src/lib/updateCheck.js +60 -0
package/package.json
CHANGED
|
@@ -74,16 +74,20 @@ async function init() {
|
|
|
74
74
|
},
|
|
75
75
|
]);
|
|
76
76
|
if (!overwrite) {
|
|
77
|
-
console.log('
|
|
78
|
-
|
|
77
|
+
console.log('Skipped workspace file.');
|
|
78
|
+
} else {
|
|
79
|
+
writeFileSync(WORKSPACE_FILE, TEMPLATE, 'utf-8');
|
|
80
|
+
console.log(`Created ${WORKSPACE_FILE}`);
|
|
81
|
+
console.log(`Run 'agrippa clone' to add resources to this workspace.`);
|
|
82
|
+
console.log(`Add ${WORKSPACE_FILE} to .gitignore if it contains credentials.`);
|
|
79
83
|
}
|
|
84
|
+
} else {
|
|
85
|
+
writeFileSync(WORKSPACE_FILE, TEMPLATE, 'utf-8');
|
|
86
|
+
console.log(`Created ${WORKSPACE_FILE}`);
|
|
87
|
+
console.log(`Run 'agrippa clone' to add resources to this workspace.`);
|
|
88
|
+
console.log(`Add ${WORKSPACE_FILE} to .gitignore if it contains credentials.`);
|
|
80
89
|
}
|
|
81
90
|
|
|
82
|
-
writeFileSync(WORKSPACE_FILE, TEMPLATE, 'utf-8');
|
|
83
|
-
console.log(`Created ${WORKSPACE_FILE}`);
|
|
84
|
-
console.log(`Run 'agrippa clone' to add resources to this workspace.`);
|
|
85
|
-
console.log(`Add ${WORKSPACE_FILE} to .gitignore if it contains credentials.`);
|
|
86
|
-
|
|
87
91
|
if (!existsSync('pyproject.toml')) {
|
|
88
92
|
writeFileSync('pyproject.toml', PYPROJECT_TOML, 'utf-8');
|
|
89
93
|
console.log('Created pyproject.toml (ruff builtins)');
|
|
@@ -162,55 +162,25 @@ async function fetchRemoteCode(token, ripUrl, workspace) {
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
async function selectEntries(changed, verb, mode = 'pull') {
|
|
165
|
-
// Group by parent folder for folder-level pre-selection
|
|
166
|
-
const folderMap = new Map();
|
|
167
|
-
for (const entry of changed) {
|
|
168
|
-
const folder = dirname(entry.path) || '.';
|
|
169
|
-
if (!folderMap.has(folder)) folderMap.set(folder, []);
|
|
170
|
-
folderMap.get(folder).push(entry);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const folders = [...folderMap.keys()];
|
|
174
|
-
|
|
175
|
-
// Folder-level pre-selection (only shown when there are multiple folders)
|
|
176
|
-
let includedFolders = new Set(folders);
|
|
177
|
-
if (folders.length > 1) {
|
|
178
|
-
const { selectedFolders } = await inquirer.prompt([
|
|
179
|
-
{
|
|
180
|
-
type: 'checkbox',
|
|
181
|
-
name: 'selectedFolders',
|
|
182
|
-
message: `Select workflows/folders to ${verb}:`,
|
|
183
|
-
choices: folders.map((f) => ({
|
|
184
|
-
name: `${f}/ (${folderMap.get(f).length} changed)`,
|
|
185
|
-
value: f,
|
|
186
|
-
checked: true,
|
|
187
|
-
})),
|
|
188
|
-
},
|
|
189
|
-
]);
|
|
190
|
-
includedFolders = new Set(selectedFolders);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const candidates = changed.filter((e) => includedFolders.has(dirname(e.path) || '.'));
|
|
194
|
-
|
|
195
|
-
if (!candidates.length) return [];
|
|
196
|
-
|
|
197
165
|
const badgeFor = (status) => {
|
|
198
166
|
if (mode === 'push') {
|
|
199
|
-
return status === 'fast-forward' ? '↑
|
|
167
|
+
return status === 'fast-forward' ? '↑ safe' : '⚠ conflict';
|
|
200
168
|
}
|
|
201
|
-
return status === 'fast-forward' ? '↑
|
|
169
|
+
return status === 'fast-forward' ? '↑ safe' : '⚠ conflict';
|
|
202
170
|
};
|
|
203
171
|
|
|
172
|
+
const choices = changed.map((e) => ({
|
|
173
|
+
name: `${e.name} [${badgeFor(e.status)}]`,
|
|
174
|
+
value: e,
|
|
175
|
+
checked: true,
|
|
176
|
+
}));
|
|
177
|
+
|
|
204
178
|
const { selected } = await inquirer.prompt([
|
|
205
179
|
{
|
|
206
180
|
type: 'checkbox',
|
|
207
181
|
name: 'selected',
|
|
208
|
-
message: `
|
|
209
|
-
choices
|
|
210
|
-
name: `[${dirname(e.path) || '.'}] ${e.name} [${badgeFor(e.status)}]`,
|
|
211
|
-
value: e,
|
|
212
|
-
checked: true,
|
|
213
|
-
})),
|
|
182
|
+
message: `Select records to ${verb}:`,
|
|
183
|
+
choices,
|
|
214
184
|
pageSize: 20,
|
|
215
185
|
},
|
|
216
186
|
]);
|
|
@@ -19,7 +19,7 @@ function writeConfig(config) {
|
|
|
19
19
|
function loadEffectiveEnv(localConfig) {
|
|
20
20
|
// Load global prbot config as the base (KC_URL, KC_USER, RIP_URL, etc. live here)
|
|
21
21
|
if (existsSync(CONFIG_FILE)) {
|
|
22
|
-
configDotenv({ path: CONFIG_FILE });
|
|
22
|
+
configDotenv({ path: CONFIG_FILE, quiet: true });
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// Overlay workspace-level overrides from agrippa.yaml's agrippa: section
|
package/src/commands/autopr.js
CHANGED
|
@@ -150,9 +150,11 @@ function scoreSections(sections, candidates) {
|
|
|
150
150
|
continue;
|
|
151
151
|
}
|
|
152
152
|
// Token fallback
|
|
153
|
-
const tokens = lc.split(/[\s|_\-.]+/).filter((t) => t.length >
|
|
153
|
+
const tokens = lc.split(/[\s|_\-.]+/).filter((t) => t.length > 1);
|
|
154
154
|
for (const token of tokens) {
|
|
155
|
-
if (heading.includes(token))
|
|
155
|
+
if (heading.includes(token)) {
|
|
156
|
+
score += /^\d+$/.test(token) ? 5 : 1;
|
|
157
|
+
}
|
|
156
158
|
}
|
|
157
159
|
}
|
|
158
160
|
if (score > 0) results.push({ ...section, score });
|
package/src/index.js
CHANGED
|
@@ -10,8 +10,18 @@ import { init } from './commands/init.js';
|
|
|
10
10
|
import { main as prMain } from './commands/pr.js';
|
|
11
11
|
import { verbot } from './commands/ver.js';
|
|
12
12
|
import { CONFIG_FILE } from './config.js';
|
|
13
|
+
import { checkForUpdate, currentVersion } from './lib/updateCheck.js';
|
|
13
14
|
|
|
14
|
-
configDotenv({ path: CONFIG_FILE });
|
|
15
|
+
configDotenv({ path: CONFIG_FILE, quiet: true });
|
|
16
|
+
|
|
17
|
+
let _updateAvailable = null;
|
|
18
|
+
checkForUpdate().then((v) => { _updateAvailable = v; });
|
|
19
|
+
|
|
20
|
+
process.on('exit', () => {
|
|
21
|
+
if (_updateAvailable) {
|
|
22
|
+
console.log(`\nUpdate available: ${currentVersion} → ${_updateAvailable}\nRun: prbot update`);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
15
25
|
|
|
16
26
|
program
|
|
17
27
|
.command('pr <module>')
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { execFile } from 'child_process';
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { CONFIG_DIR } from '../config.js';
|
|
6
|
+
|
|
7
|
+
const CACHE_FILE = path.join(CONFIG_DIR, '.update-check');
|
|
8
|
+
const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
9
|
+
|
|
10
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const pkg = JSON.parse(readFileSync(path.join(__dirname, '../../package.json'), 'utf8'));
|
|
12
|
+
|
|
13
|
+
export const currentVersion = pkg.version;
|
|
14
|
+
|
|
15
|
+
function semverGt(a, b) {
|
|
16
|
+
const pa = a.split('.').map(Number);
|
|
17
|
+
const pb = b.split('.').map(Number);
|
|
18
|
+
for (let i = 0; i < 3; i++) {
|
|
19
|
+
if (pa[i] > pb[i]) return true;
|
|
20
|
+
if (pa[i] < pb[i]) return false;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function readCache() {
|
|
26
|
+
try {
|
|
27
|
+
if (!existsSync(CACHE_FILE)) return null;
|
|
28
|
+
const data = JSON.parse(readFileSync(CACHE_FILE, 'utf8'));
|
|
29
|
+
if (Date.now() - new Date(data.checkedAt).getTime() > CACHE_TTL_MS) return null;
|
|
30
|
+
return data.latestVersion;
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function writeCache(latestVersion) {
|
|
37
|
+
try {
|
|
38
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
39
|
+
writeFileSync(CACHE_FILE, JSON.stringify({ checkedAt: new Date().toISOString(), latestVersion }));
|
|
40
|
+
} catch {
|
|
41
|
+
// non-critical
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function fetchLatest() {
|
|
46
|
+
return new Promise((resolve) => {
|
|
47
|
+
execFile('npm', ['view', '@waron97/prbot', 'version'], { timeout: 5000 }, (err, stdout) => {
|
|
48
|
+
if (err) resolve(null);
|
|
49
|
+
else resolve(stdout.trim());
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function checkForUpdate() {
|
|
55
|
+
const cached = readCache();
|
|
56
|
+
const latest = cached ?? (await fetchLatest());
|
|
57
|
+
if (latest && !cached) writeCache(latest);
|
|
58
|
+
if (latest && semverGt(latest, currentVersion)) return latest;
|
|
59
|
+
return null;
|
|
60
|
+
}
|