gitlab.mdx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. ---
  2. title: GitLab
  3. description: GitLab の問題とマージリクエストで OpenCode を使用します。
  4. ---
  5. OpenCode は、GitLab CI/CD パイプラインまたは GitLab Duo を通じて GitLab ワークフローと統合します。
  6. どちらの場合も、OpenCode は GitLab ランナー上で実行されます。
  7. ---
  8. ## GitLab CI
  9. OpenCode は通常の GitLab パイプラインで動作します。 [CI コンポーネント](https://docs.gitlab.com/ee/ci/components/) としてパイプラインに組み込むことができます。
  10. ここでは、コミュニティが作成した OpenCode 用の CI/CD コンポーネント — [nagyv/gitlab-opencode](https://gitlab.com/nagyv/gitlab-opencode).
  11. ---
  12. ### 特徴
  13. - **ジョブごとにカスタム構成を使用する**: カスタム構成ディレクトリ (`./config/#custom-directory` など) を使用して OpenCode を構成し、OpenCode の呼び出しごとに機能を有効または無効にします。
  14. - **最小限のセットアップ**: CI コンポーネントはバックグラウンドで OpenCode をセットアップします。必要なのは、OpenCode 構成と初期プロンプトを作成することだけです。
  15. - **柔軟性**: CI コンポーネントは、動作をカスタマイズするための複数の入力をサポートしています。
  16. ---
  17. ### 設定
  18. 1. OpenCode 認証 JSON をファイル タイプ CI 環境変数として [**設定**] > [**CI/CD**] > [**変数**] に保存します。必ず「マスクして非表示」としてマークしてください。
  19. 2. 以下を `.gitlab-ci.yml` ファイルに追加します。
  20. ```yaml title=".gitlab-ci.yml"
  21. include:
  22. - component: $CI_SERVER_FQDN/nagyv/gitlab-opencode/opencode@2
  23. inputs:
  24. config_dir: ${CI_PROJECT_DIR}/opencode-config
  25. auth_json: $OPENCODE_AUTH_JSON # The variable name for your OpenCode authentication JSON
  26. command: optional-custom-command
  27. message: "Your prompt here"
  28. ```
  29. さらに多くの入力と使用例については、このコンポーネントの docs](https://gitlab.com/explore/catalog/nagyv/gitlab-opencode) をチェックしてください。
  30. ---
  31. ## GitLab デュオ
  32. OpenCode は GitLab ワークフローと統合します。
  33. コメントで `@opencode` に言及すると、OpenCode が GitLab CI パイプライン内でタスクを実行します。
  34. ---
  35. ### 特徴
  36. - **問題のトリアージ**: OpenCode に問題を調べて説明してもらいます。
  37. - **修正と実装**: OpenCode に問題の修正または機能の実装を依頼します。
  38. 新しいブランチを作成し、変更を加えたマージリクエストを発行します。
  39. - **安全**: OpenCode は GitLab ランナー上で実行されます。
  40. ---
  41. ### 設定
  42. OpenCode は GitLab CI/CD パイプラインで実行されます。セットアップするには次のものが必要です。
  43. :::tip
  44. 最新の手順については、[**GitLab ドキュメント**](https://docs.gitlab.com/user/duo_agent_platform/agent_assistant/) を参照してください。
  45. :::
  46. 1. GitLab 環境を構成する
  47. 2. CI/CD のセットアップ
  48. 3. AI モデル プロバイダー API キーを取得する
  49. 4. サービスアカウントを作成する
  50. 5. CI/CD変数を構成する
  51. 6. フロー構成ファイルを作成します。例を次に示します。
  52. <details>
  53. <summary>Flow configuration</summary>
  54. ```yaml
  55. image: node:22-slim
  56. commands:
  57. - echo "Installing opencode"
  58. - npm install --global opencode-ai
  59. - echo "Installing glab"
  60. - export GITLAB_TOKEN=$GITLAB_TOKEN_OPENCODE
  61. - apt-get update --quiet && apt-get install --yes curl wget gpg git && rm --recursive --force /var/lib/apt/lists/*
  62. - curl --silent --show-error --location "https://raw.githubusercontent.com/upciti/wakemeops/main/assets/install_repository" | bash
  63. - apt-get install --yes glab
  64. - echo "Configuring glab"
  65. - echo $GITLAB_HOST
  66. - echo "Creating OpenCode auth configuration"
  67. - mkdir --parents ~/.local/share/opencode
  68. - |
  69. cat > ~/.local/share/opencode/auth.json << EOF
  70. {
  71. "anthropic": {
  72. "type": "api",
  73. "key": "$ANTHROPIC_API_KEY"
  74. }
  75. }
  76. EOF
  77. - echo "Configuring git"
  78. - git config --global user.email "[email protected]"
  79. - git config --global user.name "OpenCode"
  80. - echo "Testing glab"
  81. - glab issue list
  82. - echo "Running OpenCode"
  83. - |
  84. opencode run "
  85. You are an AI assistant helping with GitLab operations.
  86. Context: $AI_FLOW_CONTEXT
  87. Task: $AI_FLOW_INPUT
  88. Event: $AI_FLOW_EVENT
  89. Please execute the requested task using the available GitLab tools.
  90. Be thorough in your analysis and provide clear explanations.
  91. <important>
  92. Please use the glab CLI to access data from GitLab. The glab CLI has already been authenticated. You can run the corresponding commands.
  93. 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.
  94. You don't need to commit or push up changes, those will be done automatically based on the file changes you make.
  95. </important>
  96. "
  97. - git checkout --branch $CI_WORKLOAD_REF origin/$CI_WORKLOAD_REF
  98. - echo "Checking for git changes and pushing if any exist"
  99. - |
  100. if ! git diff --quiet || ! git diff --cached --quiet || [ --not --zero "$(git ls-files --others --exclude-standard)" ]; then
  101. echo "Git changes detected, adding and pushing..."
  102. git add .
  103. if git diff --cached --quiet; then
  104. echo "No staged changes to commit"
  105. else
  106. echo "Committing changes to branch: $CI_WORKLOAD_REF"
  107. git commit --message "Codex changes"
  108. echo "Pushing changes up to $CI_WORKLOAD_REF"
  109. git push https://gitlab-ci-token:$GITLAB_TOKEN@$GITLAB_HOST/gl-demo-ultimate-dev-ai-epic-17570/test-java-project.git $CI_WORKLOAD_REF
  110. echo "Changes successfully pushed"
  111. fi
  112. else
  113. echo "No git changes detected, skipping push"
  114. fi
  115. variables:
  116. - ANTHROPIC_API_KEY
  117. - GITLAB_TOKEN_OPENCODE
  118. - GITLAB_HOST
  119. ```
  120. </details>
  121. 詳細な手順については、「GitLab CLI エージェント docs](https://docs.gitlab.com/user/duo_agent_platform/agent_assistant/)」を参照してください。
  122. ---
  123. ### 例
  124. GitLab で OpenCode を使用する方法の例をいくつか示します。
  125. :::tip
  126. `@opencode` とは異なるトリガー フレーズを使用するように設定できます。
  127. :::
  128. - **問題の説明**
  129. このコメントを GitLab の問題に追加します。
  130. ```
  131. @opencode explain this issue
  132. ```
  133. OpenCode は問題を読み、明確な説明を返信します。
  134. - **問題を修正**
  135. GitLab の問題では、次のように言います。
  136. ```
  137. @opencode fix this
  138. ```
  139. OpenCode は新しいブランチを作成し、変更を実装し、変更を含むマージ リクエストを開きます。
  140. - **マージリクエストを確認する**
  141. GitLab マージ リクエストに次のコメントを残してください。
  142. ```
  143. @opencode review this merge request
  144. ```
  145. OpenCode はマージ リクエストをレビューし、フィードバックを提供します。