Git仓库分析服务

一个全面的Git仓库分析服务,提供详细的代码库统计和开发者活动洞察,适用于团队生产力分析和项目健康监测。

  • by singhashish4000
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 singhashish4000/mcp-server

使用说明

Git分析MCP服务器

🚀 一个全面的模型上下文协议(MCP)服务器,提供详细的Git存储库分析和见解。非常适合希望通过数据驱动的见解更好地理解代码库的开发人员。

📊 特性

存储库分析

  • 综合统计:提交、作者、分支和代码更改的总数
  • 分析:贡献者排名、提交模式和活动期
  • 分行情报:分支机构健康状况、前进/后退状态和活动指标
  • 文件洞察:修改最多的文件,每个文件的作者贡献
  • 时间分析:提交频率,代码随时间变化
  • 可视化报告:格式化精美的终端输出,带有颜色和表情符号

可用工具

  1. get_repository_overview -包含关键指标和主要贡献者的执行摘要
  2. get_repository_stats -详细的存储库统计信息
  3. get_author_stats -完整的贡献者分析
  4. get_branch_stats -分支健康和比较指标
  5. get_file_stats -文件修改模式和热点
  6. get_commit_history -带有过滤器的详细提交时间表
  7. get_commit_frequency -随时间变化的每日提交模式
  8. get_code_churn -添加/删除行分析

🛠 安装

先决条件

  • Node.js 18+
  • npm或纱线
  • 要分析的Git存储库

快速设置

# Clone or create the project
cd ~/git-analytics-mcp-server

# Install dependencies
npm install

# Build the project
npm run build

# Test the server (optional)
npm test

发展模式

# Run in development with auto-reload
npm run dev

🚀 用法

作为MCP服务器

添加到MCP客户端配置中:

{
  "mcpServers": {
    "git-analytics": {
      "command": "node",
      "args": ["/path/to/git-analytics-mcp-server/dist/index.js"]
    }
  }
}

直接CLI使用

# Install globally
npm install -g .

# Use anywhere
git-analytics-mcp

📈 示例分析

存储库概述

📊 REPOSITORY SUMMARY REPORT
──────────────────────────────────────────────────
Repository Statistics:
  • Total Commits: 1,247
  • Total Authors: 12
  • Active Branches: 8
  • Code Changes: +45,678 -12,345
  • Repository Age: 2023-01-15 to 2024-06-15

Top Contributors:
  🥇 John Doe - 456 commits
  🥈 Jane Smith - 234 commits
  🥉 Bob Wilson - 189 commits
  🏅 Alice Brown - 145 commits
  🏅 Mike Johnson - 123 commits

Recent Activity:
  • a1b2c3d4 Add new authentication module (John Doe)
  • e5f6g7h8 Fix critical security vulnerability (Jane Smith)
  • i9j0k1l2 Update documentation and examples (Bob Wilson)

分析

[
  {
    "name": "John Doe",
    "email": "john@example.com",
    "commits": 456,
    "insertions": 12340,
    "deletions": 3456,
    "firstCommit": "2023-01-15T10:30:00Z",
    "lastCommit": "2024-06-15T14:22:00Z"
  }
]

代码流失分析

[
  {
    "date": "2024-06-01",
    "insertions": 234,
    "deletions": 45,
    "net": 189
  },
  {
    "date": "2024-06-02",
    "insertions": 156,
    "deletions": 89,
    "net": 67
  }
]

🔧 配置

刀具参数

大多数工具都接受这些常见参数:

  • path (字符串):存储库路径(默认:当前目录)
  • days (数字):分析的时间范围(默认值:30)
  • limit (number):返回的最大结果数(默认值:50)

环境变量

# Set default repository path
export GIT_ANALYTICS_DEFAULT_PATH="/path/to/repo"

# Enable debug logging
export GIT_ANALYTICS_DEBUG=true

🧪 测试

# Run all tests
npm test

# Run with coverage
npm run test:coverage

# Test specific functionality
npm run test -- --grep "author stats"

测试库设置

# Create test repository
mkdir test-repo && cd test-repo
git init
echo "# Test" > README.md
git add . && git commit -m "Initial commit"

# Test the server
node dist/index.js

📊 用例

开发团队分析

  • 代码审查见解:确定需要更多关注的文件
  • 团队生产力:跟踪提交模式和贡献指标
  • 技术债:查找流失率高的文件
  • 入职:了解代码库结构和关键贡献者

项目管理

  • 发布计划:分析最近的发展速度
  • 资源分配:确定知识孤岛和需要支持的领域
  • 质量指标:通过流失分析跟踪代码稳定性
  • 时间线分析:了解发展模式和周期

存储库运行状况

  • 分行管理:识别陈旧或有问题的分支
  • 文件热点:查找可能需要重构的文件
  • 贡献者入职培训:欢迎有背景的新团队成员
  • 历史分析:学习过去的发展模式

🛠 高级功能

自定义分析

使用自定义分析扩展服务器:

// Add to git-analytics.ts
async getCustomMetric(): Promise<CustomMetric> {
  // Your custom analysis logic
}

集成示例

# Use with GitHub CLI
gh repo list | xargs -I {} git-analytics-mcp --path {}

# Batch analysis
find ~/projects -name ".git" -type d | \
  xargs -I {} dirname {} | \
  xargs -I {} git-analytics-mcp --path {}

🐛 故障排除

常见问题

“Git存储库无效”

  • 确保您位于Git存储库中或提供正确的路径
  • 检查Git安装: git --version

“权限被拒绝”

  • 验证对存储库的读取权限
  • 检查.git目录上的文件权限

“未找到任何提交”

  • 存储库可能为空或新初始化
  • 尝试使用有提交的存储库

调试模式

# Enable verbose logging
DEBUG=git-analytics:* npm start

# Check server connectivity
echo '{}' | node dist/index.js

🤝 贡献

  1. 分叉存储库
  2. 创建要素分支: git checkout -b feature/amazing-feature
  3. 提交更改: git commit -m 'Add amazing feature'
  4. 推送到分支: git push origin feature/amazing-feature
  5. 打开拉取请求

开发设置

# Install dev dependencies
npm install

# Run in watch mode
npm run dev

# Lint code
npm run lint

# Format code
npm run format

📄 许可证

MIT许可证-请参阅 许可证 文件以获取详细信息。

🌟 致谢


快乐分析! 📊✨

如有疑问、问题或功能请求,请在GitHub上打开问题。

MCP服务器

MCP服务器