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 会话。对于公开仓库,默认为true

  • 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