GitLab
GitLab issues और merge requests में OpenCode का उपयोग करें।
OpenCode आपके GitLab CI/CD पाइपलाइन या GitLab Duo के माध्यम से आपके GitLab वर्कफ़्लो के साथ इंटीग्रेट होता है।
दोनों मामलों में, OpenCode आपके GitLab runners पर चलेगा।
GitLab CI
OpenCode एक सामान्य GitLab पाइपलाइन में काम करता है। आप इसे CI component के रूप में पाइपलाइन में बना सकते हैं।
यहाँ हम OpenCode के लिए एक समुदाय-निर्मित CI/CD component का उपयोग कर रहे हैं — nagyv/gitlab-opencode (opens in a new tab)।
विशेषताएँ
- प्रति जॉब कस्टम कॉन्फ़िगरेशन का उपयोग करें: OpenCode को एक कस्टम कॉन्फ़िगरेशन डायरेक्टरी के साथ कॉन्फ़िगर करें, उदाहरण के लिए
./config/#custom-directoryताकि प्रति OpenCode इनवोकेशन कार्यक्षमता को सक्षम या अक्षम किया जा सके। - न्यूनतम सेटअप: CI component बैकग्राउंड में OpenCode को सेट अप करता है, आपको केवल OpenCode कॉन्फ़िगरेशन और प्रारंभिक प्रॉम्प्ट बनाना होगा।
- लचीला: CI component अपने व्यवहार को कस्टमाइज़ करने के लिए कई इनपुट का समर्थन करता है।
सेटअप
- अपने OpenCode authentication JSON को Settings > CI/CD > Variables के तहत File type CI environment variables के रूप में स्टोर करें। उन्हें "Masked and hidden" के रूप में चिह्नित करना सुनिश्चित करें।
- अपनी
.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 के दस्तावेज़ (opens in a new tab) देखें।
GitLab Duo
OpenCode आपके GitLab वर्कफ़्लो के साथ इंटीग्रेट होता है।
किसी कमेंट में @opencode का उल्लेख करें, और OpenCode आपके GitLab CI पाइपलाइन के भीतर कार्य निष्पादित करेगा।
विशेषताएँ
- Issues की जाँच करें: OpenCode से किसी issue को देखने और समझाने के लिए कहें।
- ठीक करें और लागू करें: OpenCode से किसी issue को ठीक करने या फ़ीचर लागू करने के लिए कहें। यह एक नई branch बनाएगा और बदलावों के साथ merge request खोलेगा।
- सुरक्षित: OpenCode आपके GitLab runners पर चलता है।
सेटअप
OpenCode आपके GitLab CI/CD पाइपलाइन में चलता है, इसे सेट अप करने के लिए आपको निम्नलिखित की आवश्यकता होगी:
सुझाव: अद्यतन निर्देशों के लिए GitLab दस्तावेज़ (opens in a new tab) देखें।
- अपना GitLab environment कॉन्फ़िगर करें
- CI/CD सेट अप करें
- AI मॉडल प्रदाता API key प्राप्त करें
- एक service account बनाएँ
- CI/CD variables कॉन्फ़िगर करें
- एक flow config फ़ाइल बनाएँ, यहाँ एक उदाहरण है:
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 "[email protected]"
- 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विस्तृत निर्देशों के लिए GitLab CLI agents दस्तावेज़ (opens in a new tab) देखें।
उदाहरण
यहाँ कुछ उदाहरण हैं कि आप GitLab में OpenCode का उपयोग कैसे कर सकते हैं।
सुझाव: आप
@opencodeके अलावा किसी अन्य ट्रिगर वाक्यांश का उपयोग करने के लिए कॉन्फ़िगर कर सकते हैं।
-
Issue समझाएँ
GitLab issue में यह कमेंट जोड़ें। OpenCode issue को पढ़ेगा और एक स्पष्ट व्याख्या के साथ उत्तर देगा।
@opencode explain this issue -
Issue ठीक करें
GitLab issue में कहें: OpenCode एक नई branch बनाएगा, बदलाव लागू करेगा, और बदलावों के साथ merge request खोलेगा।
@opencode fix this -
Merge requests की समीक्षा करें
GitLab merge request पर निम्नलिखित कमेंट छोड़ें। OpenCode merge request की समीक्षा करेगा और फ़ीडबैक प्रदान करेगा।
@opencode review this merge request