GitHub PR Helper

Integrations

  • Works with local Git repositories to create Pull Requests and add comments, requiring proper repository state and branch management.

  • Provides tools for creating GitHub Pull Requests with structured titles and descriptions, and adding code review comments to specific lines in files within PRs.

  • Integrates with Jira ticket numbers, allowing them to be included in Pull Request titles when creating PRs through the GitHub integration.

GitHub PR Helper

這是一個 GitHub Pull Request 創建工具 MCP Service,使用 GitHub CLI (gh) 命令行工具來創建 PR 和進行代碼審查,無需手動處理權限問題。

功能

該服務提供以下功能:

  1. 創建 GitHub Pull Request:根據提供的標題、描述、票號和目標分支,自動創建 GitHub PR。PR 標題將由 "標題 [票號]" 組成,PR 描述將由 PR 標題和描述組成。
  2. Code Review:在 PR 添加評論,方便進行代碼審查。

前置條件

  1. 安裝 GitHub CLI
    • macOS: brew install gh
    • Windows: winget install --id GitHub.cli
    • Linux: 參考 GitHub CLI 官方文檔
  2. 登入 GitHub CLI
    gh auth login
    按照提示完成登入流程。這將自動處理身份驗證,無需手動管理 token。

安裝與設定

  1. 安裝依賴:
    npm install
  2. 配置環境變數(可選): 在 .env 檔案中設定以下變數:
    • PORT:服務器端口(預設為 3000)

使用方式

HTTP 服務

開發模式

npm run dev

生產模式

npm start

MCP 服務

npm run mcp

API 端點

HTTP API

  • POST /api/github/pr:創建 GitHub Pull Request
    • 請求體:
      { "repoPath": "本地 Git 倉庫路徑", "title": "PR 標題", "description": "PR 描述", "ticketNumber": "票號", "baseBranch": "目標分支" }
  • POST /api/github/pr/comment:在 PR 添加評論
    • 請求體:
      { "repoPath": "本地 Git 倉庫路徑", "baseBranch": "比較的基準分支", "filePath": "文件路徑", "lineNumber": 10, "comment": "評論內容" }

MCP 工具

  • create_pull_request:創建 GitHub Pull Request
    • 參數:
      • repoPath:本地 Git 倉庫路徑
      • title:PR 標題
      • description:PR 描述
      • ticketNumber:票號
      • baseBranch:目標分支
  • add_pr_comment:在 PR 添加評論
    • 參數:
      • repoPath:本地 Git 倉庫路徑
      • baseBranch:比較的基準分支
      • filePath:文件路徑
      • lineNumber:行號
      • comment:評論內容

安裝到 AI 助手

安裝到 Roo Code (VSCode)

  1. 確保已經安裝並設定好 Roo Code 擴充功能。
  2. 找到 Roo Code 的 MCP 設定檔案:
    /Users/aaron/Library/Application Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json
  3. 編輯該檔案,在 mcpServers 物件中添加以下配置:
    "github-pr-helper": { "command": "node", "args": ["/Users/aaron/CascadeProjects/app-github-pr-helper/src/mcp-server.js"], "disabled": false, "alwaysAllow": [] }
  4. 儲存檔案後,重新啟動 VSCode。
  5. 在 Roo Code 中,你現在應該可以使用 create_pull_requestadd_pr_comment 工具。

安裝到 Claude (Anthropic)

  1. 找到 Claude 的設定檔案:
    /Users/aaron/Library/Application Support/Claude/claude_desktop_config.json
  2. 編輯該檔案,在 mcpServers 物件中添加以下配置:
    "github-pr-helper": { "command": "node", "args": ["/Users/aaron/CascadeProjects/app-github-pr-helper/src/mcp-server.js"], "disabled": false, "alwaysAllow": [] }
  3. 儲存檔案後,重新啟動 Claude 應用程式。
  4. 在 Claude 中,你現在應該可以使用 create_pull_requestadd_pr_comment 工具。

安裝到 Windsurf

  1. 找到 Winsurf 的設定檔案,通常位於:
    /Users/aaron/Library/Application Support/Winsurf/winsurf_config.json
    如果找不到這個檔案,可以嘗試搜尋:
    find ~/Library/Application\ Support -name "*winsurf*" -type f
  2. 編輯該檔案,在 mcpServers 物件中添加以下配置:
    "github-pr-helper": { "command": "node", "args": ["/Users/aaron/CascadeProjects/app-github-pr-helper/src/mcp-server.js"], "disabled": false, "alwaysAllow": [] }
  3. 如果 mcpServers 物件不存在,則需要創建它:
    { "mcpServers": { "github-pr-helper": { "command": "node", "args": ["/Users/aaron/CascadeProjects/app-github-pr-helper/src/mcp-server.js"], "disabled": false, "alwaysAllow": [] } } }
  4. 儲存檔案後,重新啟動 Winsurf。
  5. 在 Winsurf 中,你現在應該可以使用 create_pull_requestadd_pr_comment 工具。

安裝到 Cursor

方法一:通過 GUI 設定(推薦)

  1. 在 Cursor 中,打開設定頁面。
  2. 找到 MCP 服務設定區域,點擊添加新服務。
  3. 填寫以下欄位:
    • Name: github-pr-helper(服務名稱)
    • Type: command(選擇命令類型)
    • Command: node /Users/aaron/CascadeProjects/app-github-pr-helper/src/mcp-server.js(MCP 服務路徑)
  4. 儲存設定後,重新啟動 Cursor。
  5. 在 Cursor 中,你現在應該可以使用 create_pull_requestadd_pr_comment 工具。

方法二:通過編輯設定檔案

  1. 找到 Cursor 的設定檔案:
    /Users/aaron/Library/Application Support/Cursor/User/settings.json
  2. 編輯該檔案,添加或修改 cursor.experimental.mcp.servers 設定:
    "cursor.experimental.mcp.servers": { "github-pr-helper": { "command": "node", "args": ["/Users/aaron/CascadeProjects/app-github-pr-helper/src/mcp-server.js"], "disabled": false, "alwaysAllow": [] } }
  3. 儲存檔案後,重新啟動 Cursor。
  4. 在 Cursor 中,你現在應該可以使用 create_pull_requestadd_pr_comment 工具。

使用範例

在 AI 助手中,你可以使用以下提示來創建 GitHub PR:

請使用 create_pull_request 工具創建 GitHub Pull Request。 參數: { "repoPath": "/path/to/your/repo", "title": "實現新功能", "description": "這個 PR 實現了新功能,包括...", "ticketNumber": "JIRA-123", "baseBranch": "main" }

你也可以使用以下提示在 PR 添加評論:

請使用 add_pr_comment 工具在 PR 添加評論。 參數: { "repoPath": "/path/to/your/repo", "baseBranch": "main", "filePath": "src/index.js", "lineNumber": 42, "comment": "這裡可以使用更簡潔的寫法" }

注意事項

  1. 使用此工具前,請確保你已經:
    • 使用 gh auth login 登入 GitHub CLI
    • 在本地 Git 倉庫中創建並切換到了你想要提交 PR 的分支
    • 已經提交了所有更改
    • 已經將分支推送到遠程倉庫
  2. 此工具使用 GitHub CLI (gh) 來處理 GitHub 相關操作,無需手動管理 token,大大簡化了權限管理。
  3. 如果遇到權限問題,請確保你已經正確登入 GitHub CLI,可以通過以下命令檢查登入狀態:
    gh auth status
-
security - not tested
F
license - not found
-
quality - not tested

An MCP service that enables creating GitHub Pull Requests and adding code review comments using GitHub CLI, eliminating the need to manually handle authentication and permissions.

  1. 功能
    1. 前置條件
      1. 安裝與設定
        1. 使用方式
          1. HTTP 服務
          2. MCP 服務
        2. API 端點
          1. HTTP API
          2. MCP 工具
        3. 安裝到 AI 助手
          1. 安裝到 Roo Code (VSCode)
          2. 安裝到 Claude (Anthropic)
          3. 安裝到 Windsurf
          4. 安裝到 Cursor
        4. 使用範例
          1. 注意事項
            ID: q6vev3ox0u