196 lines
6.8 KiB
Markdown
196 lines
6.8 KiB
Markdown
---
|
|
title: GitLab
|
|
description: GitLab 이슈와 merge request에서 OpenCode를 사용하세요.
|
|
---
|
|
|
|
OpenCode는 GitLab CI/CD 파이프라인 또는 GitLab Duo를 통해 GitLab 워크플로에 통합됩니다.
|
|
|
|
두 경우 모두 OpenCode는 GitLab runner에서 실행됩니다.
|
|
|
|
---
|
|
|
|
## GitLab CI
|
|
|
|
OpenCode는 일반 GitLab 파이프라인에서 작동합니다. [CI component](https://docs.gitlab.com/ee/ci/components/)로 파이프라인에 통합할 수 있습니다.
|
|
|
|
여기서는 OpenCode용 커뮤니티 제작 CI/CD component인 [nagyv/gitlab-opencode](https://gitlab.com/nagyv/gitlab-opencode)를 사용합니다.
|
|
|
|
---
|
|
|
|
### 기능
|
|
|
|
- **job별 custom config 사용**: custom config 디렉터리(예: `./config/#custom-directory`)를 사용해 OpenCode를 각 실행 단위로 설정하고 기능을 켜거나 끌 수 있습니다.
|
|
- **최소 설정**: CI component가 백그라운드에서 OpenCode를 설정하므로 OpenCode config와 초기 prompt만 만들면 됩니다.
|
|
- **유연함**: CI component는 동작을 사용자화할 수 있도록 여러 입력값을 지원합니다.
|
|
|
|
---
|
|
|
|
### Setup
|
|
|
|
1. OpenCode 인증 JSON을 **Settings** > **CI/CD** > **Variables** 아래의 File 타입 CI 환경 변수로 저장하세요. 반드시 "Masked and hidden"으로 표시하세요.
|
|
2. 아래 내용을 `.gitlab-ci.yml` 파일에 추가하세요.
|
|
|
|
```yaml title=".gitlab-ci.yml"
|
|
include:
|
|
- component: $CI_SERVER_FQDN/nagyv/gitlab-opencode/opencode@2
|
|
inputs:
|
|
config_dir: ${CI_PROJECT_DIR}/opencode-config
|
|
auth_json: $OPENCODE_AUTH_JSON # The variable name for your OpenCode authentication JSON
|
|
command: optional-custom-command
|
|
message: "Your prompt here"
|
|
```
|
|
|
|
더 많은 입력값과 사용 사례는 이 component의 [docs](https://gitlab.com/explore/catalog/nagyv/gitlab-opencode)에서 확인하세요.
|
|
|
|
---
|
|
|
|
## GitLab Duo
|
|
|
|
OpenCode는 GitLab 워크플로에 통합됩니다.
|
|
댓글에서 `@opencode`를 멘션하면 OpenCode가 GitLab CI 파이프라인 안에서 작업을 실행합니다.
|
|
|
|
---
|
|
|
|
### 기능
|
|
|
|
- **이슈 분류**: OpenCode에 이슈를 살펴보고 설명해 달라고 요청할 수 있습니다.
|
|
- **수정 및 구현**: OpenCode에 이슈를 수정하거나 기능을 구현해 달라고 요청할 수 있습니다.
|
|
OpenCode는 새 브랜치를 만들고 변경 사항이 담긴 merge request를 생성합니다.
|
|
- **보안**: OpenCode는 GitLab runner에서 실행됩니다.
|
|
|
|
---
|
|
|
|
### Setup
|
|
|
|
OpenCode는 GitLab CI/CD 파이프라인에서 실행되며, 설정에 필요한 항목은 다음과 같습니다.
|
|
|
|
:::tip
|
|
[최신 안내는 **GitLab docs**](https://docs.gitlab.com/user/duo_agent_platform/agent_assistant/)를 확인하세요.
|
|
:::
|
|
|
|
1. GitLab 환경을 설정합니다.
|
|
2. CI/CD를 설정합니다.
|
|
3. AI model provider API 키를 준비합니다.
|
|
4. 서비스 계정을 생성합니다.
|
|
5. CI/CD 변수를 설정합니다.
|
|
6. flow config 파일을 생성합니다. 예시는 다음과 같습니다.
|
|
|
|
<details>
|
|
|
|
<summary>Flow configuration</summary>
|
|
|
|
```yaml
|
|
image: node:22-slim
|
|
commands:
|
|
- 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_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.
|
|
|
|
<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)" ]; 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 "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_REF
|
|
echo "Changes successfully pushed"
|
|
fi
|
|
else
|
|
echo "No git changes detected, skipping push"
|
|
fi
|
|
variables:
|
|
- ANTHROPIC_API_KEY
|
|
- GITLAB_TOKEN_OPENCODE
|
|
- GITLAB_HOST
|
|
```
|
|
|
|
</details>
|
|
|
|
[GitLab CLI agents docs](https://docs.gitlab.com/user/duo_agent_platform/agent_assistant/)에서 자세한 안내를 확인할 수 있습니다.
|
|
|
|
---
|
|
|
|
### 예제
|
|
|
|
다음은 GitLab에서 OpenCode를 사용하는 몇 가지 예시입니다.
|
|
|
|
:::tip
|
|
`@opencode` 대신 다른 trigger phrase를 사용하도록 설정할 수 있습니다.
|
|
:::
|
|
|
|
- **이슈 설명**
|
|
|
|
GitLab 이슈에 아래 댓글을 남기세요.
|
|
|
|
```
|
|
@opencode explain this issue
|
|
```
|
|
|
|
OpenCode가 이슈를 읽고 명확한 설명으로 답변합니다.
|
|
|
|
- **이슈 해결**
|
|
|
|
GitLab 이슈에서 다음과 같이 요청하세요.
|
|
|
|
```
|
|
@opencode fix this
|
|
```
|
|
|
|
OpenCode가 새 브랜치를 만들고 변경 사항을 구현한 뒤, 해당 변경 사항으로 merge request를 엽니다.
|
|
|
|
- **머지 리퀘스트 검토**
|
|
|
|
GitLab merge request에 아래 댓글을 남기세요.
|
|
|
|
```
|
|
@opencode review this merge request
|
|
```
|
|
|
|
OpenCode가 merge request를 검토하고 피드백을 제공합니다.
|