GitLab
Utilisez OpenCode dans les problèmes GitLab et les demandes de fusion.
OpenCode s’intègre à votre flux de travail GitLab via votre pipeline CI/CD GitLab ou avec GitLab Duo.
Dans les deux cas, OpenCode fonctionnera sur vos runners GitLab.
GitLab CI
OpenCode fonctionne dans un pipeline GitLab régulier. Vous pouvez l’intégrer dans un pipeline en tant que composant CI
Ici, nous utilisons un composant CI/CD créé par la communauté pour OpenCode — nagyv/gitlab-opencode.
Caractéristiques
- Utiliser une configuration personnalisée par tâche : configurez OpenCode avec un répertoire de configuration personnalisé, par exemple
./config/#custom-directorypour activer ou désactiver la fonctionnalité par appel OpenCode. - Configuration minimale : le composant CI configure OpenCode en arrière-plan, il vous suffit de créer la configuration OpenCode et l’invite initiale.
- Flexible : le composant CI prend en charge plusieurs entrées pour personnaliser son comportement
Installation
-
Stockez votre authentification OpenCode JSON en tant que variables d’environnement CI de type fichier sous Paramètres > CI/CD > Variables. Assurez-vous de les marquer comme « Masqués et cachés ».
-
Ajoutez ce qui suit à votre fichier
.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"
Pour plus d’entrées et de cas d’utilisation consultez la docs pour ce composant.
GitLab Duo
OpenCode s’intègre à votre flux de travail GitLab.
Mentionnez @opencode dans un commentaire et OpenCode exécutera les tâches au sein de votre pipeline CI GitLab.
Caractéristiques
- Problèmes de triage : demandez à OpenCode d’examiner un problème et de vous l’expliquer.
- Réparer et implémenter : demandez à OpenCode de résoudre un problème ou d’implémenter une fonctionnalité. Cela créera une nouvelle branche et déclenchera une demande de fusion avec les modifications.
- Sécurisé : OpenCode fonctionne sur vos runners GitLab.
Installation
OpenCode s’exécute dans votre pipeline CI/CD GitLab. Voici ce dont vous aurez besoin pour le configurer :
-
Configurez votre environnement GitLab
-
Configurer CI/CD
-
Obtenez la clé API d’un fournisseur de modèles d’IA
-
Créer un compte de service
-
Configurer les variables CI/CD
-
Créez un fichier de configuration de flux, voici un exemple :
Configuration du flux
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
Vous pouvez vous référer aux GitLab CLI agents docs pour des instructions détaillées.
Exemples
Voici quelques exemples de la façon dont vous pouvez utiliser OpenCode dans GitLab.
- Expliquez un problème
Ajoutez ce commentaire dans un numéro GitLab.
@opencode explain this issueOpenCode lira le problème et répondra avec une explication claire.
- Résoudre un problème
Dans un numéro GitLab, dites :
@opencode fix thisOpenCode créera une nouvelle branche, mettra en œuvre les modifications et ouvrira une demande de fusion avec les modifications.
- Examiner les demandes de fusion
Laissez le commentaire suivant sur une demande de fusion GitLab.
@opencode review this merge requestOpenCode examinera la demande de fusion et fournira des commentaires.