Mantis summary updates.

This commit is contained in:
Cameron Redmore 2025-04-26 10:53:07 +01:00
parent 0e0d1bffb3
commit af8cc56e79
7 changed files with 168 additions and 16 deletions

View file

@ -3,7 +3,8 @@ import { PrismaClient } from '@prisma/client'; // Import Prisma Client
import { getMantisSettings, saveTicketToDatabase } from '../services/mantisDownloader.js';
import axios from 'axios';
import reader from '@kenjiuno/msgreader';
import SuperJSON from 'superjson';
import { askGemini } from '../utils/gemini.js';
import { usernameMap } from '../services/mantisSummarizer.js';
const MsgReader = reader.default;
const prisma = new PrismaClient(); // Instantiate Prisma Client
@ -356,4 +357,42 @@ router.get('/stats/comments', async(req, res) =>
}
});
router.get('/summary/:ticketId', async(req, res) =>
{
const { ticketId } = req.params;
try
{
const ticket = await prisma.mantisIssue.findUnique({
where: { id: parseInt(ticketId, 10) },
include: {
comments: true,
},
});
if (!ticket)
{
return res.status(404).json({ error: 'Mantis ticket not found' });
}
//We need to change the usernames using the usernameMap
ticket.reporterUsername = usernameMap[ticket.reporterUsername] || ticket.reporterUsername;
ticket.comments = ticket.comments.map((comment) =>
{
comment.senderUsername = usernameMap[comment.senderUsername] || comment.senderUsername;
return comment;
});
//Ask Gemini to summarize the ticket
const summary = await askGemini(`Please summarize the following Mantis ticket in the form of a markdown list of bullet points formatted as "[Date] Point" (ensure a newline between each point, format the date as DD/MM/YYY and surround it with square brackets "[]"). Then after your summary, list any outstanding actions as a markdown list in the format "[Name] Action" (again surrounding the name with square brackets).
Output a heading 6 "Summary:", a newline, the summary, then two newlines, a heading 6 "Actions:" then the actions. Do not wrap the output in a code block.\n\n### Ticket Data ###\n\n` + JSON.stringify(ticket, null, 2));
res.status(200).json({ summary });
}
catch (error)
{
console.error('Error fetching Mantis summary:', error.message);
res.status(500).json({ error: 'Failed to fetch Mantis summary' });
}
});
export default router;