@teamvibe/poller 0.1.53 → 0.1.54
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/dist/maintenance-reporter.js +16 -0
- package/package.json +1 -1
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { readdir, readFile, unlink } from 'fs/promises';
|
|
2
2
|
import { join } from 'path';
|
|
3
|
+
import { execFile } from 'child_process';
|
|
4
|
+
import { promisify } from 'util';
|
|
3
5
|
import { config } from './config.js';
|
|
4
6
|
import { logger } from './logger.js';
|
|
7
|
+
const execFileAsync = promisify(execFile);
|
|
5
8
|
const OPERATION_TO_EVENT_TYPE = {
|
|
6
9
|
consolidation: 'maintenance.consolidation',
|
|
7
10
|
reflection: 'maintenance.reflection',
|
|
@@ -21,6 +24,7 @@ export async function postMaintenanceReports(brainPath, channelId) {
|
|
|
21
24
|
if (jsonFiles.length === 0)
|
|
22
25
|
return;
|
|
23
26
|
logger.info(`[MaintenanceReporter] Found ${jsonFiles.length} JSON report(s) in ${reportsDir}`);
|
|
27
|
+
const postedFiles = [];
|
|
24
28
|
for (const file of jsonFiles) {
|
|
25
29
|
const filePath = join(reportsDir, file);
|
|
26
30
|
try {
|
|
@@ -51,6 +55,7 @@ export async function postMaintenanceReports(brainPath, channelId) {
|
|
|
51
55
|
if (response.ok) {
|
|
52
56
|
logger.info(`[MaintenanceReporter] Posted ${file} as ${eventType}`);
|
|
53
57
|
await unlink(filePath).catch(() => { });
|
|
58
|
+
postedFiles.push(`reports/${file}`);
|
|
54
59
|
}
|
|
55
60
|
else {
|
|
56
61
|
const errorBody = await response.text().catch(() => 'unknown');
|
|
@@ -61,6 +66,17 @@ export async function postMaintenanceReports(brainPath, channelId) {
|
|
|
61
66
|
logger.warn(`[MaintenanceReporter] Error processing ${file}: ${err instanceof Error ? err.message : err}`);
|
|
62
67
|
}
|
|
63
68
|
}
|
|
69
|
+
// Remove posted JSON reports from git so they don't resurrect on next pull
|
|
70
|
+
if (postedFiles.length > 0) {
|
|
71
|
+
try {
|
|
72
|
+
await execFileAsync('git', ['rm', '--cached', '--ignore-unmatch', ...postedFiles], { cwd: brainPath });
|
|
73
|
+
await execFileAsync('git', ['commit', '-m', 'chore: remove posted maintenance reports'], { cwd: brainPath });
|
|
74
|
+
logger.info(`[MaintenanceReporter] Committed removal of ${postedFiles.length} posted report(s) from git`);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
logger.debug(`[MaintenanceReporter] Could not git-rm reports (may not be a git repo): ${err instanceof Error ? err.message : err}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
64
80
|
}
|
|
65
81
|
catch (err) {
|
|
66
82
|
logger.warn(`[MaintenanceReporter] Error scanning reports: ${err instanceof Error ? err.message : err}`);
|