refactor(mcp-server): tighten MCP tool typing after review
This commit is contained in:
parent
b199ea7976
commit
d365bc59d6
@ -2,6 +2,23 @@ import { z } from 'zod';
|
||||
import { registerTool } from '../tools/registry.js';
|
||||
import { platformFetch } from '../../lib/platform-client.js';
|
||||
|
||||
type CommitFile = {
|
||||
path: string;
|
||||
additions: number;
|
||||
deletions: number;
|
||||
};
|
||||
|
||||
type ChangelogCommit = {
|
||||
sha: string;
|
||||
message: string;
|
||||
author: string;
|
||||
date: string;
|
||||
prNumber?: number;
|
||||
prTitle?: string;
|
||||
prBody?: string;
|
||||
files: CommitFile[];
|
||||
};
|
||||
|
||||
registerTool({
|
||||
name: 'changelog.generate',
|
||||
description:
|
||||
@ -117,13 +134,13 @@ registerTool({
|
||||
};
|
||||
|
||||
const categorized = commitsResponse.commits.reduce(
|
||||
(acc: Record<string, any[]>, commit: any) => {
|
||||
(acc: Record<string, ChangelogCommit[]>, commit: ChangelogCommit) => {
|
||||
const category = categorizeCommit(commit.message, commit.files);
|
||||
if (!acc[category]) acc[category] = [];
|
||||
acc[category].push(commit);
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, any[]>
|
||||
{} as Record<string, ChangelogCommit[]>
|
||||
);
|
||||
|
||||
// Step 4: Generate changelog content
|
||||
@ -179,7 +196,7 @@ registerTool({
|
||||
|
||||
md += `## ${categoryEmojis[category]} ${category.charAt(0).toUpperCase() + category.slice(1)} (${commits.length})\n\n`;
|
||||
|
||||
commits.forEach((commit: any) => {
|
||||
commits.forEach((commit: ChangelogCommit) => {
|
||||
md += `### ${commit.prTitle || commit.message.split('\n')[0]}\n\n`;
|
||||
md += `**Commit:** \`${commit.sha.substring(0, 7)}\`\n`;
|
||||
md += `**Author:** ${commit.author}\n`;
|
||||
@ -190,15 +207,15 @@ registerTool({
|
||||
}
|
||||
|
||||
const totalChanges = commit.files.reduce(
|
||||
(sum: number, file: any) => sum + file.additions + file.deletions,
|
||||
(sum: number, file: CommitFile) => sum + file.additions + file.deletions,
|
||||
0
|
||||
);
|
||||
md += `**Changes:** +${commit.files.reduce((sum: number, f: any) => sum + f.additions, 0)} -${commit.files.reduce((sum: number, f: any) => sum + f.deletions, 0)} (${totalChanges} total)\n`;
|
||||
md += `**Changes:** +${commit.files.reduce((sum: number, f: CommitFile) => sum + f.additions, 0)} -${commit.files.reduce((sum: number, f: CommitFile) => sum + f.deletions, 0)} (${totalChanges} total)\n`;
|
||||
|
||||
// List modified files (limit to 10)
|
||||
const modifiedFiles = commit.files
|
||||
.slice(0, 10)
|
||||
.map((f: any) => f.path)
|
||||
.map((f: CommitFile) => f.path)
|
||||
.join(', ');
|
||||
md += `**Files:** ${modifiedFiles}${commit.files.length > 10 ? '...' : ''}\n`;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user