GitLab
GitLab の問題とマージリクエストで OpenCode を使用します。
OpenCode は、GitLab CI/CD パイプラインまたは GitLab Duo を通じて GitLab ワークフローと統合します。
どちらの場合も、OpenCode は GitLab ランナー上で実行されます。
GitLab CI
OpenCode は通常の GitLab パイプラインで動作します。 CI コンポーネント としてパイプラインに組み込むことができます。
ここでは、コミュニティが作成した OpenCode 用の CI/CD コンポーネント — nagyv/gitlab-opencode.
特徴
- ジョブごとにカスタム構成を使用する: カスタム構成ディレクトリ (
./config/#custom-directoryなど) を使用して OpenCode を構成し、OpenCode の呼び出しごとに機能を有効または無効にします。 - 最小限のセットアップ: CI コンポーネントはバックグラウンドで OpenCode をセットアップします。必要なのは、OpenCode 構成と初期プロンプトを作成することだけです。
- 柔軟性: CI コンポーネントは、動作をカスタマイズするための複数の入力をサポートしています。
設定
-
OpenCode 認証 JSON をファイル タイプ CI 環境変数として [設定] > [CI/CD] > [変数] に保存します。必ず「マスクして非表示」としてマークしてください。
-
以下を
.gitlab-ci.ymlファイルに追加します。.gitlab-ci.yml include:- component: $CI_SERVER_FQDN/nagyv/gitlab-opencode/opencode@2inputs:config_dir: ${CI_PROJECT_DIR}/opencode-configauth_json: $OPENCODE_AUTH_JSON # The variable name for your OpenCode authentication JSONcommand: optional-custom-commandmessage: "Your prompt here"
さらに多くの入力と使用例については、このコンポーネントの docs](https://gitlab.com/explore/catalog/nagyv/gitlab-opencode) をチェックしてください。
GitLab Duo
OpenCode は GitLab ワークフローと統合します。
コメントで @opencode に言及すると、OpenCode が GitLab CI パイプライン内でタスクを実行します。
特徴
- 問題のトリアージ: OpenCode に問題を調べて説明してもらいます。
- 修正と実装: OpenCode に問題の修正または機能の実装を依頼します。 新しいブランチを作成し、変更を加えたマージリクエストを発行します。
- 安全: OpenCode は GitLab ランナー上で実行されます。
設定
OpenCode は GitLab CI/CD パイプラインで実行されます。セットアップするには次のものが必要です。
-
GitLab 環境を構成する
-
CI/CD のセットアップ
-
AI モデル プロバイダー API キーを取得する
-
サービスアカウントを作成する
-
CI/CD変数を構成する
-
フロー構成ファイルを作成します。例を次に示します。
Flow configuration
image: node:22-slimcommands:- echo "Installing opencode"- npm install --global opencode-ai- echo "Installing glab"- export GITLAB_TOKEN=$GITLAB_TOKEN_OPENCODE- 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 OpenCode auth configuration"- mkdir --parents ~/.local/share/opencode- |cat > ~/.local/share/opencode/auth.json << EOF{"anthropic": {"type": "api","key": "$ANTHROPIC_API_KEY"}}EOF- echo "Configuring git"- git config --global user.email "opencode@gitlab.com"- git config --global user.name "OpenCode"- echo "Testing glab"- glab issue list- echo "Running OpenCode"- |opencode run "You are an AI assistant helping with GitLab operations.Context: $AI_FLOW_CONTEXTTask: $AI_FLOW_INPUTEvent: $AI_FLOW_EVENTPlease execute the requested task using the available GitLab tools.Be thorough in your analysis and provide clear explanations.<important>Please use the glab CLI to access data from GitLab. The glab CLI has already been authenticated. You can run the corresponding commands.If you are asked to summarize an MR or issue or asked to provide more information then please post back a note to the MR/Issue so that the user can see it.You don't need to commit or push up changes, those will be done automatically based on the file changes you make.</important>"- 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 || [ --not --zero "$(git ls-files --others --exclude-standard)" ]; thenecho "Git changes detected, adding and pushing..."git add .if git diff --cached --quiet; thenecho "No staged changes to commit"elseecho "Committing changes to branch: $CI_WORKLOAD_REF"git commit --message "Codex changes"echo "Pushing changes up to $CI_WORKLOAD_REF"git push https://gitlab-ci-token:$GITLAB_TOKEN@$GITLAB_HOST/gl-demo-ultimate-dev-ai-epic-17570/test-java-project.git $CI_WORKLOAD_REFecho "Changes successfully pushed"fielseecho "No git changes detected, skipping push"fivariables:- ANTHROPIC_API_KEY- GITLAB_TOKEN_OPENCODE- GITLAB_HOST
詳細な手順については、GitLab CLI エージェント docsを参照してください。
例
GitLab で OpenCode を使用する方法の例をいくつか示します。
- 問題の説明
このコメントを GitLab の問題に追加します。
@opencode explain this issueOpenCode は問題を読み、明確な説明を返信します。
- 問題を修正
GitLab の問題では、次のように言います。
@opencode fix thisOpenCode は新しいブランチを作成し、変更を実装し、変更を含むマージ リクエストを開きます。
- マージリクエストを確認する
GitLab マージ リクエストに次のコメントを残してください。
@opencode review this merge requestOpenCode はマージ リクエストをレビューし、フィードバックを提供します。