Dropstone Docs

GitLab

在 GitLab 議題和合併請求中使用 Dropstone。

Dropstone 透過 GitLab CI/CD 管道或 GitLab Duo 與您的 GitLab 工作流程整合。

在這兩種情況下,Dropstone 都會在您的 GitLab 執行器上執行。


GitLab CI

Dropstone 可在常規 GitLab 管道中運作。您可以將其作為 CI 元件 建置到管道中。

這裡我們使用社群建立的 Dropstone CI/CD 元件:nagyv/gitlab-dropstone


功能

  • 每個工作使用自訂配置:使用自訂配置目錄(例如 ./config/#custom-directory)配置 Dropstone,以便針對每次 Dropstone 呼叫啟用或停用功能。
  • 最小化設定:CI 元件在背景設定 Dropstone,您只需建立 Dropstone 配置和初始提示。
  • 靈活:CI 元件支援多個輸入以自訂其行為。

設定

  1. Settings > CI/CD > Variables 下將您的 Dropstone 驗證 JSON 儲存為檔案類型 CI 環境變數。確保將其標記為「已遮罩且隱藏」。

  2. 將以下內容新增到您的 .gitlab-ci.yml 檔案。

    include:
      - component: $CI_SERVER_FQDN/nagyv/gitlab-dropstone/dropstone@2
        inputs:
          config_dir: ${CI_PROJECT_DIR}/dropstone-config
          auth_json: $DROPSTONE_AUTH_JSON # 您的 Dropstone 驗證 JSON 的變數名稱
          command: optional-custom-command
          message: "您的提示在此"
    

如需更多輸入和使用案例,請 查看此元件的文件


GitLab Duo

Dropstone 與您的 GitLab 工作流程整合。 在評論中提及 @dropstone,Dropstone 將在您的 GitLab CI 管道中執行任務。


功能

  • 分類議題:要求 Dropstone 查看議題並向您解釋。
  • 修復和實現:要求 Dropstone 修復議題或實現功能。 它將建立新分支並提出包含變更的合併請求。
  • 安全:Dropstone 在您的 GitLab 執行器上執行。

設定

Dropstone 在您的 GitLab CI/CD 管道中執行,以下是設定所需的內容:

提示:

查看 GitLab 文件 以取得最新說明。

  1. 配置您的 GitLab 環境
  2. 設定 CI/CD
  3. 取得 Dropstone API 金鑰(請參閱 快速入門
  4. 建立服務帳戶
  5. 配置 CI/CD 變數
  6. 建立流程配置檔案。範例:
image: node:22-slim
commands:
  - echo "Installing Dropstone"
  - curl -fsSL https://dropstone.io/install | bash
  - echo "Installing glab"
  - export GITLAB_TOKEN=$GITLAB_TOKEN_DROPSTONE
  - apt-get update --quiet && apt-get install --yes curl wget gpg git && rm --recursive --force /var/lib/apt/lists/*
  - curl --silent --show-error --location "https://raw.githubusercontent.com/upciti/wakemeops/main/assets/install_repository" | bash
  - apt-get install --yes glab
  - echo "Configuring glab"
  - echo $GITLAB_HOST
  - echo "Creating Dropstone auth configuration"
  - mkdir --parents ~/.local/share/dropstone
  - |
    cat > ~/.local/share/dropstone/auth.json << EOF
    {
      "dropstone": {
        "type": "api",
        "key": "$DROPSTONE_API_KEY"
      }
    }
    EOF
  - echo "Configuring git"
  - git config --global user.email "dropstone@gitlab.com"
  - git config --global user.name "Dropstone"
  - echo "Testing glab"
  - glab issue list
  - echo "Running Dropstone"
  - |
    dropstone run "
    You are an AI assistant helping with GitLab operations.

    Context: $AI_FLOW_CONTEXT
    Task: $AI_FLOW_INPUT
    Event: $AI_FLOW_EVENT

    Please execute the requested task using the available GitLab tools.
    Be thorough in your analysis and provide clear explanations.

    Use the glab CLI to access data from GitLab. The glab CLI is already authenticated.

    If you are asked to summarize an MR or issue, or provide more information,
    post back a note to the MR/Issue so the user can see it.
    "
  - git checkout --branch $CI_WORKLOAD_REF origin/$CI_WORKLOAD_REF
  - echo "Checking for git changes and pushing if any exist"
  - |
    if ! git diff --quiet || ! git diff --cached --quiet || [ -n "$(git ls-files --others --exclude-standard)" ]; then
      echo "Git changes detected, adding and pushing..."
      git add .
      if git diff --cached --quiet; then
        echo "No staged changes to commit"
      else
        echo "Committing changes to branch: $CI_WORKLOAD_REF"
        git commit --message "Dropstone changes"
        echo "Pushing changes up to $CI_WORKLOAD_REF"
        git push "https://gitlab-ci-token:$GITLAB_TOKEN@$GITLAB_HOST/$CI_PROJECT_PATH.git" $CI_WORKLOAD_REF
        echo "Changes successfully pushed"
      fi
    else
      echo "No git changes detected, skipping push"
    fi
variables:
  - DROPSTONE_API_KEY
  - GITLAB_TOKEN_DROPSTONE
  - GITLAB_HOST

您可以參考 GitLab Duo Agent Platform 文件 以取得詳細說明。


範例

以下是您可以在 GitLab 中使用 Dropstone 的一些範例。

提示:

您可以配置不同的觸發短語而不是 @dropstone

  • 解釋議題

    在 GitLab 議題中新增此評論。

    @dropstone explain this issue
    

    Dropstone 將讀取議題並回覆清晰的解釋。

  • 修復議題

    在 GitLab 議題中,說:

    @dropstone fix this
    

    Dropstone 將建立新分支、實現變更,並開啟包含變更的合併請求。

  • 審查合併請求

    在 GitLab 合併請求上留下以下評論。

    @dropstone review this merge request
    

    Dropstone 將審查合併請求並提供回饋。

Ctrl+I