GitHub PR评论提取工具

一个通过GitHub CLI获取拉取请求评论并集成到开发工作流中的工具,支持VS Code、Claude Desktop和Cline。

  • by power-tester
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 power-tester/get-github-pr-comments

使用说明

获取GitHub PR评论

一个模型上下文协议(MCP)服务器,使用GitHub CLI获取GitHub拉取请求审查评论。通过VS Code、Claude Desktop或Cline将PR审查意见无缝集成到您的开发工作流程中。

特性

  • 📝 获取所有PR评论 -从任何pull请求中获取所有评论
  • 📄 文件特定注释 -按特定文件路径筛选注释
  • 📊 多种格式 -以摘要或详细格式查看评论
  • 🔄 自动检测 -自动检测当前PR或接受PR编号
  • 🚀 易于集成 -适用于VS Code、Claude Desktop和Cline

先决条件

安装

选项1:从npm安装(推荐)

全局安装以在任何地方使用:

npm install -g get-github-pr-comments

或者在不通过npx安装的情况下使用:

npx get-github-pr-comments

选项2:本地开发/测试

克隆此存储库并安装依赖项:

git clone https://github.com/power-tester/get-github-pr-comments.git
cd get-github-pr-comments
npm install
npm run build

配置

VS代码(使用GitHub Copilot)

添加到您的VS代码MCP设置(.vscode/mcp.json 在您的工作空间中):

使用npm包(推荐):

{
  "mcpServers": {
    "get-github-pr-comments": {
      "command": "npx",
      "args": ["get-github-pr-comments"]
    }
  }
}

或者,如果全局安装(软件包通常安装在 /usr/local/bin 在macOS或 %APPDATA%\npm 在Windows上):

{
  "mcpServers": {
    "get-github-pr-comments": {
      "command": "get-github-pr-comments"
    }
  }
}

使用本地安装:

{
  "mcpServers": {
    "get-github-pr-comments": {
      "command": "node",
      "args": ["/absolute/path/to/get-github-pr-comments/build/index.js"]
    }
  }
}

重要提示: 替换 /absolute/path/to/get-github-pr-comments/build/index.js 与您构建的实际绝对路径 index.js 文件。

克劳德桌面

在macOS上: ~/Library/Application Support/Claude/claude_desktop_config.json
在Windows上: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "get-github-pr-comments": {
      "command": "npx",
      "args": ["get-github-pr-comments"]
    }
  }
}

克莱恩

在Cline MCP设置文件中:

{
  "mcpServers": {
    "get-github-pr-comments": {
      "command": "npx",
      "args": ["get-github-pr-comments"]
    }
  }
}

重新加载您的客户端

添加配置后,重新加载VS Code或重新启动MCP客户端以激活服务器。

可用工具

服务器提供两个MCP工具:

1. get_pr_comments

从拉取请求中获取所有评论。

参数:

  • pr_number (可选):用于获取评论的PR编号。如果未提供,则使用当前PR。
  • format (可选):输出格式- "summary" 或 "detailed"默认值为 "detailed".

输出:

  • 摘要格式:每条注释一行,显示文件路径、行号和注释的第一行
  • 详细格式:带有作者、日期、文件路径和行号的完整注释文本

示例用法:

Get PR comments
Show PR comments in summary format
Get comments for PR #123

2. get_pr_comments_by_file

在拉取请求中获取特定文件的审核评论。

参数:

  • file_path (必填):获取注释的文件路径
  • pr_number (可选):用于获取评论的PR编号。如果未提供,则使用当前PR。

输出:

  • 显示指定文件所有注释的详细格式
  • 包括作者、日期、行号和完整的评论文本

示例用法:

Get PR comments for src/index.ts
Show comments for package.json in PR #123

用法

使用GitHub Copilot编写VS代码

配置后,您可以询问Copilot:

  • “获取公关评论,告诉我你对它们的看法?”
  • “获取公关评论,并修复你认为重要的评论。总结一下你修复了哪些评论,没有修复哪些评论,以及为什么”
  • “显示此PR的评论”
  • “src/index.ts的注释是什么?”
  • “以摘要格式获取公关评论”
  • “显示PR#456的评论”

在克劳德桌面或克莱恩

问助理:

  • “获取PR评论”
  • “显示对此拉取请求的所有评论”
  • “对身份验证码给出了什么反馈?”
  • “获取main.py文件的注释”

运作原理

  1. 自动检测:使用GitHub CLI检测当前存储库和PR
  2. API调用:通过以下方式获取评论数据 gh api 命令
  3. 格式化:处理和格式化注释以提高可读性
  4. 上下文感知:提供相关上下文(作者、日期、行号)

安全

此服务器:

  • 仅读取PR注释数据(无写入操作)
  • 使用经过身份验证的GitHub CLI访问API
  • 尊重您的GitHub权限和存储库访问权限
  • 不向外部服务存储或传输数据

故障排除

常见问题:

“获取PR信息失败”错误

  • 确保你在一个有已签出PR的git存储库中
  • 跑 gh pr view 验证PR检测是否有效
  • 检查GitHub CLI是否经过身份验证: gh auth status

“GitHub CLI命令失败”错误

  • 验证是否安装了GitHub CLI: gh --version
  • 确保您已通过身份验证: gh auth login
  • 检查存储库权限

MCP服务器未连接

  • 验证MCP设置文件中的配置路径
  • 配置更改后重新启动VS Code或MCP客户端
  • 检查客户端的开发人员控制台是否有错误消息

未返回任何评论

  • 验证PR是否有审查意见(而不仅仅是PR意见)
  • 检查您是否有权查看PR
  • 尝试明确指定PR编号

发展

设置

# Clone the repository
git clone https://github.com/power-tester/get-github-pr-comments.git
cd get-github-pr-comments

# Install dependencies
npm install

# Build
npm run build

# Watch mode for development
npm run watch

本地测试

# Build the project
npm run build

# Test with MCP inspector (if available)
npx @modelcontextprotocol/inspector node build/index.js

贡献

欢迎投稿!请随时提交拉取请求。

贡献领域:

  • 支持不同的评论类型(PR评论与评论评论)
  • 按作者、日期范围或已解决状态筛选
  • 导出为不同格式(CSV、JSON)
  • 评论线程和对话跟踪
  • 与代码审查工作流集成

作者

普拉莫德·库马尔·亚达夫

许可证

麻省理工学院

支持

有关问题、疑问或贡献,请访问 GitHub 仓库.