@waron97/prbot 3.0.3 → 3.0.5
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
CHANGED
|
@@ -114,7 +114,7 @@ async function initPhase() {
|
|
|
114
114
|
// Resolve result objects — API may return IDs or full objects
|
|
115
115
|
let results = phase.allowed_phase_result_ids || [];
|
|
116
116
|
if (results.length > 0 && typeof results[0] === 'number') {
|
|
117
|
-
results = await getPhaseResults(token, ripUrl,
|
|
117
|
+
results = await getPhaseResults(token, ripUrl, results);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
const code = generateCode(results);
|
package/src/agrippa/lib/api.js
CHANGED
|
@@ -48,11 +48,12 @@ function updateMfa(token, ripUrl, mfaId, code) {
|
|
|
48
48
|
return makeRequest('POST', '/symple.workflow/update_mfa', token, ripUrl, { id: mfaId, code });
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
async function getPhaseResults(token, ripUrl,
|
|
51
|
+
async function getPhaseResults(token, ripUrl, ids) {
|
|
52
|
+
if (!ids || ids.length === 0) return [];
|
|
52
53
|
try {
|
|
53
54
|
return await makeRequest(
|
|
54
55
|
'GET',
|
|
55
|
-
`/symple.triplet.phase.result/*?_filter_=[('
|
|
56
|
+
`/symple.triplet.phase.result/*?_filter_=[('id', 'in', [${ids.join(',')}])]`,
|
|
56
57
|
token,
|
|
57
58
|
ripUrl,
|
|
58
59
|
);
|
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/commands/ver.js
CHANGED
|
@@ -3,7 +3,7 @@ import fs from 'fs/promises';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { resolveAddonsPath } from '../lib/addons.js';
|
|
5
5
|
|
|
6
|
-
async function verbot(module_name, level) {
|
|
6
|
+
async function verbot(module_name, level, opts = {}) {
|
|
7
7
|
if (!['major', 'minor', 'patch'].includes(level)) {
|
|
8
8
|
throw new Error('Level must be one of major, minor, patch');
|
|
9
9
|
}
|
|
@@ -52,6 +52,8 @@ async function verbot(module_name, level) {
|
|
|
52
52
|
await fs.writeFile(manifestPath, newContent);
|
|
53
53
|
console.log(`Updated version: ${currentVersion} -> ${newVersion}`);
|
|
54
54
|
|
|
55
|
+
if (opts.commit === false) return;
|
|
56
|
+
|
|
55
57
|
await new Promise((resolve, reject) => {
|
|
56
58
|
execFile('git', ['add', manifestPath], { cwd: ADDONS_PATH }, (error) => {
|
|
57
59
|
if (error) reject(error);
|
package/src/index.js
CHANGED
|
@@ -10,9 +10,19 @@ 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
15
|
configDotenv({ path: CONFIG_FILE, quiet: true });
|
|
15
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
|
+
});
|
|
25
|
+
|
|
16
26
|
program
|
|
17
27
|
.command('pr <module>')
|
|
18
28
|
.option('-b, --bump <level>')
|
|
@@ -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
|
+
}
|