GitLab
在 GitLab issue 和 merge request 中使用 Dropstone。
Dropstone 可透過您的 GitLab CI/CD pipeline 或 GitLab Duo 整合至您的 GitLab 工作流程。
在兩種情況下,Dropstone 都會在您的 GitLab runners 上執行。
GitLab CI
Dropstone 可在一般的 GitLab pipeline 中運作。您可以將其建置為 pipeline 中的 CI component。
這裡我們使用社群建立的 Dropstone CI/CD component:nagyv/gitlab-dropstone。
功能
- 每個 job 使用自訂設定:使用自訂設定目錄(例如
./config/#custom-directory)設定 Dropstone,以在每次 Dropstone 呼叫時啟用或停用功能。 - 設定簡單:CI component 會在背景設定 Dropstone,您只需建立 Dropstone 設定和初始提示即可。
- 彈性:CI component 支援多種輸入,可自訂其行為。
設定
-
將您的 Dropstone 驗證 JSON 儲存為 Settings > CI/CD > Variables 下的 File 類型 CI 環境變數。請務必將其標記為「Masked and hidden」。
-
在您的
.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 # The variable name for your Dropstone authentication JSON command: optional-custom-command message: "Your prompt here"
如需更多輸入和應用情境,請查看此 component 的文件。
GitLab Duo
Dropstone 可整合至您的 GitLab 工作流程。
在留言中提及 @dropstone,Dropstone 便會在您的 GitLab CI pipeline 中執行任務。
功能
- 分類 issue:要求 Dropstone 查看 issue 並向您說明。
- 修復與實作:要求 Dropstone 修復 issue 或實作功能。 它會建立新分支,並以變更內容提出 merge request。
- 安全:Dropstone 在您的 GitLab runners 上執行。
設定
Dropstone 在您的 GitLab CI/CD pipeline 中執行,以下是設定所需項目:
Tip
請參閱 GitLab 文件 以取得最新指示。
- 設定您的 GitLab 環境
- 設定 CI/CD
- 取得 Dropstone API 金鑰(請參閱 快速入門)
- 建立服務帳戶
- 設定 CI/CD 變數
- 建立 flow 設定檔。範例:
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 的範例。
Tip
您可以設定不同的觸發詞,而非 @dropstone。
-
說明 issue
在 GitLab issue 中新增此留言。
@dropstone explain this issueDropstone 會讀取 issue 並回覆清楚的說明。
-
修復 issue
在 GitLab issue 中輸入:
@dropstone fix thisDropstone 會建立新分支、實作變更,並以變更內容開啟 merge request。
-
審查 merge requests
在 GitLab merge request 上留下以下留言。
@dropstone review this merge requestDropstone 會審查 merge request 並提供回饋。