Dropstone Docs

GitHub

在 GitHub 議題和拉取請求中使用 Dropstone。

Dropstone 與您的 GitHub 工作流程整合。在任何評論中提及 /dropstone,Dropstone 將在您的 GitHub Actions 執行器中執行任務。


功能

  • 分類議題:要求 Dropstone 查看議題並向您解釋。
  • 修復和實現:要求 Dropstone 修復議題或實現功能。它將在新分支中工作並提交包含所有變更的 PR。
  • 安全:Dropstone 在您的 GitHub 執行器內執行。

安裝

在位於 GitHub 儲存庫中的專案中執行以下命令:

dropstone github install

這將引導您完成安裝 GitHub 應用程式、建立工作流程和設定密鑰。


手動設定

或者您可以手動設定。

  1. 安裝 GitHub 應用程式

    前往 github.com/apps/dropstone-agent。確保它已安裝在目標儲存庫上。

  2. 新增工作流程

    將以下工作流程檔案新增到您的儲存庫中的 .github/workflows/dropstone.yml。確保在 env 中設定適當的 model 和必需的 API 金鑰。

    name: dropstone
    
    on:
      issue_comment:
        types: [created]
      pull_request_review_comment:
        types: [created]
    
    jobs:
      dropstone:
        if: contains(github.event.comment.body, '/dropstone')
        runs-on: ubuntu-latest
        permissions:
          id-token: write
        steps:
          - name: Checkout repository
            uses: actions/checkout@v6
            with:
              fetch-depth: 1
              persist-credentials: false
    
          - name: Run Dropstone
            uses: blankline-org/dropstone-cli/github@latest
            env:
              DROPSTONE_API_KEY: ${{ secrets.DROPSTONE_API_KEY }}
            with:
              model: dropstone/dropstone-pro
              # share: true
              # github_token: xxxx
    
  3. 在儲存庫密鑰中儲存您的 API 金鑰

    在您的組織或儲存庫設定中,展開左側的密鑰和變數並選擇操作。新增 DROPSTONE_API_KEY 作為新的儲存庫密鑰。


配置

  • model:要使用的 Dropstone 層級。為 dropstone/dropstone-fastdropstone/dropstone-prodropstone/dropstone-heavy 之一。這是必需的

  • agent:要使用的代理。必須是主要代理。如果未找到,則回退到配置中的 default_agent"build"

  • share:是否共享 Dropstone 工作階段。對於公開儲存庫,預設為

  • prompt:可選的自訂提示,用於覆蓋預設行為。使用此選項來自訂 Dropstone 如何處理請求。

  • token:可選的 GitHub 存取令牌,用於執行建立評論、提交變更和開啟拉取請求等操作。預設情況下,Dropstone 使用來自 Dropstone GitHub 應用程式的安裝存取令牌,因此提交、評論和拉取請求顯示為來自應用程式。

    或者,您可以使用 GitHub Action 執行器的內建 GITHUB_TOKEN,而無需安裝 Dropstone GitHub 應用程式。只需確保在您的工作流程中授予必需的權限:

    permissions:
      id-token: write
      contents: write
      pull-requests: write
      issues: write
    

    如果您願意,也可以使用個人存取令牌(PAT)。


支援的事件

Dropstone 可以由以下 GitHub 事件觸發:

事件類型觸發者詳情
issue_comment對議題或 PR 的評論在您的評論中提及 /dropstone。Dropstone 讀取上下文並可以建立分支、開啟 PR 或回覆。
pull_request_review_comment對 PR 中特定程式碼行的評論在審查程式碼時提及 /dropstone。Dropstone 接收檔案路徑、行號和差異上下文。
issues議題已開啟或編輯當建立或修改議題時自動觸發 Dropstone。需要 prompt 輸入。
pull_requestPR 已開啟或更新當 PR 被開啟、同步或重新開啟時自動觸發 Dropstone。適用於自動審查。
schedule基於 Cron 的排程按排程執行 Dropstone。需要 prompt 輸入。輸出進入日誌和 PR(沒有要評論的議題)。
workflow_dispatch從 GitHub UI 手動觸發透過操作標籤按需觸發 Dropstone。需要 prompt 輸入。輸出進入日誌和 PR。

排程範例

按排程執行 Dropstone 以執行自動化任務:

name: Scheduled Dropstone Task

on:
  schedule:
    - cron: "0 9 * * 1" # Every Monday at 9am UTC

jobs:
  dropstone:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: write
      pull-requests: write
      issues: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6
        with:
          persist-credentials: false

      - name: Run Dropstone
        uses: blankline-org/dropstone-cli/github@latest
        env:
          DROPSTONE_API_KEY: ${{ secrets.DROPSTONE_API_KEY }}
        with:
          model: dropstone/dropstone-pro
          prompt: |
            Review the codebase for any TODO comments and create a summary.
            If you find issues worth addressing, open an issue to track them.

對於排程事件,prompt 輸入是必需的,因為沒有要提取指令的評論。排程工作流程在沒有使用者上下文的情況下執行以進行權限檢查,因此如果您期望 Dropstone 建立分支或 PR,工作流程必須授予 contents: writepull-requests: write


拉取請求範例

當 PR 被開啟或更新時自動審查它們:

name: dropstone-review

on:
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]

jobs:
  review:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read
      pull-requests: read
      issues: read
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
      - uses: blankline-org/dropstone-cli/github@latest
        env:
          DROPSTONE_API_KEY: ${{ secrets.DROPSTONE_API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          model: dropstone/dropstone-pro
          use_github_token: true
          prompt: |
            Review this pull request:
            - Check for code quality issues
            - Look for potential bugs
            - Suggest improvements

對於 pull_request 事件,如果未提供 prompt,Dropstone 預設為審查拉取請求。


議題分類範例

自動分類新議題。此範例篩選帳戶超過 30 天的帳戶以減少垃圾郵件:

name: Issue Triage

on:
  issues:
    types: [opened]

jobs:
  triage:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: write
      pull-requests: write
      issues: write
    steps:
      - name: Check account age
        id: check
        uses: actions/github-script@v7
        with:
          script: |
            const user = await github.rest.users.getByUsername({
              username: context.payload.issue.user.login
            });
            const created = new Date(user.data.created_at);
            const days = (Date.now() - created) / (1000 * 60 * 60 * 24);
            return days >= 30;
          result-encoding: string

      - uses: actions/checkout@v6
        if: steps.check.outputs.result == 'true'
        with:
          persist-credentials: false

      - uses: blankline-org/dropstone-cli/github@latest
        if: steps.check.outputs.result == 'true'
        env:
          DROPSTONE_API_KEY: ${{ secrets.DROPSTONE_API_KEY }}
        with:
          model: dropstone/dropstone-pro
          prompt: |
            Review this issue. If there's a clear fix or relevant docs:
            - Provide documentation links
            - Add error handling guidance for code examples
            Otherwise, do not comment.

對於 issues 事件,prompt 輸入是必需的,因為沒有要提取指令的評論。


自訂提示

覆蓋預設提示以自訂 Dropstone 對您的工作流程的行為。

- uses: blankline-org/dropstone-cli/github@latest
  with:
    model: dropstone/dropstone-pro
    prompt: |
      Review this pull request:
      - Check for code quality issues
      - Look for potential bugs
      - Suggest improvements

這對於強制執行特定的審查標準、編碼標準或與您的專案相關的焦點區域很有用。


範例

以下是一些如何在 GitHub 中使用 Dropstone 的範例。

  • 解釋議題

    在 GitHub 議題中新增此評論。

    /dropstone explain this issue
    

    Dropstone 將讀取整個執行緒,包括所有評論,並回覆清晰的解釋。

  • 修復議題

    在 GitHub 議題中,說:

    /dropstone fix this
    

    Dropstone 將建立新分支、實現變更並開啟包含變更的 PR。

  • 審查 PR 並進行變更

    在 GitHub PR 上留下以下評論。

    /dropstone delete the attachment from S3 when the note is removed
    

    Dropstone 將實現請求的變更並將其提交到同一 PR。

  • 審查特定程式碼行

    直接在 PR 的「檔案」標籤中的程式碼行上留下評論。Dropstone 自動偵測檔案、行號和差異上下文以提供精確的回應。

    [Comment on specific lines in Files tab]
    /dropstone add error handling here
    

    在評論特定行時,Dropstone 接收:

    • 正在審查的確切檔案
    • 特定的程式碼行
    • 周圍的差異上下文
    • 行號資訊

    這允許進行更有針對性的請求,而無需手動指定檔案路徑或行號。

Ctrl+I