feat: Error reports create GitHub Issues (alexpolo1/dwroller)

This commit is contained in:
2026-06-25 18:56:30 +02:00
parent c0fc0d1aab
commit 4630272171
2 changed files with 41 additions and 4 deletions

View File

@@ -13253,3 +13253,16 @@ Connected to MongoDB
[2026-06-25T16:30:01.040Z] Session created: session_christoffer_1782405000961_eyfh1k
[2026-06-25T16:30:01.042Z] API: Player login christoffer success
[2026-06-25T16:45:07.930Z] MariaDB: Tables created successfully
[2026-06-25T16:45:38.841Z] Session created: session_christoffer_1782405938711_21fls2
[2026-06-25T16:45:38.844Z] API: Player login christoffer success
[2026-06-25T16:45:38.886Z] API: Error report #1 created by christoffer
[2026-06-25T16:45:54.912Z] Session created: session_gm_1782405954894_xwppfb
[2026-06-25T16:45:54.914Z] API: Player login gm success
[2026-06-25T16:45:54.949Z] API: Error report #1 deleted by gm
[2026-06-25T16:46:31.868Z] API: Fetch all players (public) 6
[2026-06-25T16:46:39.780Z] Session created: session_phillip_1782405999617_eaf5nw
[2026-06-25T16:46:39.782Z] API: Player login phillip success
[2026-06-25T16:46:39.829Z] API: Fetch player phillip success
[2026-06-25T16:46:39.841Z] SESSION: Session validation successful phillip
[2026-06-25T16:46:39.879Z] API: Fetch player phillip success
[2026-06-25T16:47:37.213Z] MariaDB: Tables created successfully

View File

@@ -1,6 +1,8 @@
const express = require('express');
const { errorReportHelpers, logToFile } = require('../mariadb');
const { errorReportHelpers, logToFile, pool } = require('../mariadb');
const { validateSession } = require('../sessionModel');
const { exec } = require('child_process');
const execPromise = (cmd) => new Promise((resolve, reject) => exec(cmd, { timeout: 30000 }, (err, stdout) => err ? reject(err) : resolve(stdout)));
const router = express.Router();
// Middleware: require valid session (logged-in user)
@@ -23,15 +25,37 @@ router.post('/', requireSession, async (req, res) => {
if (!title || !description) {
return res.status(400).json({ error: 'Title and description are required' });
}
const id = await errorReportHelpers.create({
const reportId = await errorReportHelpers.create({
playerName: req.sessionPlayerName,
title,
description,
category: category || 'other',
pageUrl: pageUrl || ''
});
logToFile(`API: Error report #${id} created by ${req.sessionPlayerName}`);
res.json({ success: true, id });
logToFile(`API: Error report #${reportId} created by ${req.sessionPlayerName}`);
// Also create a GitHub issue
let issueUrl = null;
try {
const body = [
`**Category:** ${category || 'other'}\n`,
`**Reported by:** ${req.sessionPlayerName}\n`,
`**Page:** ${pageUrl || 'N/A'}\n`,
`**Description:**\n${description}`
].join('\n');
const label = category && category !== 'other' ? category : 'other';
const result = await execPromise(`cd /nas/git/dwroller && gh issue create --title "Error: ${title}" --body '${body.replace(/'/g, "\\'")}' --label '${label}' --repo alexpolo1/dwroller`);
// gh issue create outputs: https://github.com/...#issue-xxx
issueUrl = result.trim();
logToFile(`API: GitHub issue created: ${issueUrl}`);
// Update DB with the GitHub issue URL
await pool.execute('UPDATE error_reports SET github_issue_url = ? WHERE id = ?', [issueUrl, reportId]);
} catch (ghError) {
logToFile('API: Failed to create GitHub issue', ghError);
// Don't fail the request — the DB report still succeeded
}
res.json({ success: true, id: reportId, githubIssueUrl: issueUrl });
} catch (error) {
logToFile('API: Error creating report', error);
res.status(500).json({ error: String(error) });