get_issue_statistics
Analyze Mantis bug tracking data by grouping issues based on status, priority, severity, handler, or reporter. Use project ID and time range filters for detailed insights.
Instructions
獲取 Mantis 問題統計數據,根據不同維度進行分析
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| groupBy | Yes | 分組依據 | |
| period | No | 時間範圍<all-全部, today-今天, week-本週, month-本月> | all |
| projectId | No | 專案 ID |
Implementation Reference
- src/server.ts:200-291 (registration)Registration of the 'get_issue_statistics' tool using server.tool(), including schema and inline handler implementation.server.tool( "get_issue_statistics", "獲取 Mantis 問題統計數據,根據不同維度進行分析", { projectId: z.number().optional().describe("專案 ID"), groupBy: z.enum(['status', 'priority', 'severity', 'handler', 'reporter']).describe("分組依據"), period: z.enum(['all', 'today', 'week', 'month']).default('all').describe("時間範圍<all-全部, today-今天, week-本週, month-本月>"), }, async (params) => { return withMantisConfigured("get_issue_statistics", async () => { // 從 Mantis API 獲取問題並處理統計 const issues = await mantisApi.getIssues({ projectId: params.projectId, pageSize: 1000 // 獲取大量數據用於統計 }); // 建立統計結果 const statistics = { total: issues.length, groupedBy: params.groupBy, period: params.period, data: {} as Record<string, number> }; // 根據時間範圍過濾 let filteredIssues = issues; log.debug("根據時間範圍過濾issues", { issues, params }); const now = new Date(); const startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate()); const startOfWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - now.getDay()); const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1); switch (params.period) { case 'today': filteredIssues = issues.filter(issue => { const createdAt = new Date(issue.created_at); return createdAt >= startOfDay; }); break; case 'week': filteredIssues = issues.filter(issue => { const createdAt = new Date(issue.created_at); return createdAt >= startOfWeek; }); break; case 'month': filteredIssues = issues.filter(issue => { const createdAt = new Date(issue.created_at); return createdAt >= startOfMonth; }); break; case 'all': default: // 保持原有的issues不變 break; } if (!filteredIssues || filteredIssues.length === 0) { return { error: "沒有查詢到任何Issue" }; } // 根據分組依據進行統計 filteredIssues.forEach(issue => { let key = ''; switch (params.groupBy) { case 'status': key = issue.status?.name || 'unknown'; break; case 'priority': key = issue.priority?.name || 'unknown'; break; case 'severity': key = issue.severity?.name || 'unknown'; break; case 'handler': key = issue.handler?.name || 'unassigned'; break; case 'reporter': key = issue.reporter?.name || 'unknown'; break; } statistics.data[key] = (statistics.data[key] || 0) + 1; }); return JSON.stringify(statistics, null, 2); }); } );
- src/server.ts:208-290 (handler)Handler function that fetches issues using mantisApi.getIssues, filters by period, groups by specified field (status, priority, etc.), and returns JSON statistics.async (params) => { return withMantisConfigured("get_issue_statistics", async () => { // 從 Mantis API 獲取問題並處理統計 const issues = await mantisApi.getIssues({ projectId: params.projectId, pageSize: 1000 // 獲取大量數據用於統計 }); // 建立統計結果 const statistics = { total: issues.length, groupedBy: params.groupBy, period: params.period, data: {} as Record<string, number> }; // 根據時間範圍過濾 let filteredIssues = issues; log.debug("根據時間範圍過濾issues", { issues, params }); const now = new Date(); const startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate()); const startOfWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - now.getDay()); const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1); switch (params.period) { case 'today': filteredIssues = issues.filter(issue => { const createdAt = new Date(issue.created_at); return createdAt >= startOfDay; }); break; case 'week': filteredIssues = issues.filter(issue => { const createdAt = new Date(issue.created_at); return createdAt >= startOfWeek; }); break; case 'month': filteredIssues = issues.filter(issue => { const createdAt = new Date(issue.created_at); return createdAt >= startOfMonth; }); break; case 'all': default: // 保持原有的issues不變 break; } if (!filteredIssues || filteredIssues.length === 0) { return { error: "沒有查詢到任何Issue" }; } // 根據分組依據進行統計 filteredIssues.forEach(issue => { let key = ''; switch (params.groupBy) { case 'status': key = issue.status?.name || 'unknown'; break; case 'priority': key = issue.priority?.name || 'unknown'; break; case 'severity': key = issue.severity?.name || 'unknown'; break; case 'handler': key = issue.handler?.name || 'unassigned'; break; case 'reporter': key = issue.reporter?.name || 'unknown'; break; } statistics.data[key] = (statistics.data[key] || 0) + 1; }); return JSON.stringify(statistics, null, 2); }); } );
- src/server.ts:203-207 (schema)Zod input schema defining parameters for projectId (optional), groupBy (status/priority/etc.), period (all/today/week/month).{ projectId: z.number().optional().describe("專案 ID"), groupBy: z.enum(['status', 'priority', 'severity', 'handler', 'reporter']).describe("分組依據"), period: z.enum(['all', 'today', 'week', 'month']).default('all').describe("時間範圍<all-全部, today-今天, week-本週, month-本月>"), },