GitLab
CodeTutor ทำงานร่วมกับเวิร์กโฟลว์ GitLab ของคุณผ่านไปป์ไลน์ GitLab CI/CD หรือกับ GitLab Duo
ในทั้งสองกรณี CodeTutor จะทำงานบน GitLab runners ของคุณ
GitLab CI
CodeTutor ทำงานในไปป์ไลน์ GitLab ปกติ คุณสามารถสร้างมันลงในไปป์ไลน์เป็น องค์ประกอบ CI
ที่นี่เรากำลังใช้คอมโพเนนต์ CI/CD ที่สร้างโดยชุมชนสำหรับ CodeTutor — nagyv/gitlab-opencode
คุณสมบัติ
- ใช้การกำหนดค่าแบบกำหนดเองต่องาน: กำหนดค่า CodeTutor ด้วยไดเร็กทอรีการกำหนดค่าแบบกำหนดเอง เช่น
./config/#custom-directoryเพื่อเปิดหรือปิดฟังก์ชันการทำงานต่อการเรียกใช้ CodeTutor - การตั้งค่าขั้นต่ำ: องค์ประกอบ CI จะตั้งค่า CodeTutor ในเบื้องหลัง คุณเพียงแค่ต้องสร้างการกำหนดค่า CodeTutor และข้อความแจ้งเริ่มต้นเท่านั้น
- ยืดหยุ่น: ส่วนประกอบ CI รองรับอินพุตหลายอินพุตเพื่อปรับแต่งลักษณะการทำงาน
ตั้งค่า
-
จัดเก็บการรับรองความถูกต้อง CodeTutor ของคุณ 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: $CODETUTOR_AUTH_JSON # The variable name for your CodeTutor authentication JSONcommand: optional-custom-commandmessage: "Your prompt here"
หากต้องการข้อมูลเพิ่มเติมและกรณีการใช้งาน ตรวจสอบเอกสาร สำหรับส่วนประกอบนี้
GitLab Duo
CodeTutor ทำงานร่วมกับเวิร์กโฟลว์ GitLab ของคุณ
พูดถึง @opencode ในความคิดเห็น แล้ว CodeTutor จะดำเนินการงานภายในไปป์ไลน์ GitLab CI ของคุณ
คุณสมบัติ
- Issue Triage: ขอให้ CodeTutor ตรวจสอบปัญหาและอธิบายให้คุณทราบ
- แก้ไขและนำไปใช้: ขอให้ CodeTutor แก้ไขปัญหาหรือใช้ฟีเจอร์ มันจะสร้างสาขาใหม่และขอรวมการเปลี่ยนแปลง
- ปลอดภัย: CodeTutor ทำงานบนนักวิ่ง GitLab ของคุณ
ตั้งค่า
CodeTutor ทำงานในไปป์ไลน์ 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 CodeTutor 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 "CodeTutor"- echo "Testing glab"- glab issue list- echo "Running CodeTutor"- |codetutor 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 agent docs
ตัวอย่าง
นี่คือตัวอย่างบางส่วนของวิธีที่คุณสามารถใช้ CodeTutor ใน GitLab
-
อธิบายปัญหา
เพิ่มความคิดเห็นนี้ในปัญหา GitLab
@codetutor explain this issueCodeTutor จะอ่านปัญหาและตอบกลับพร้อมคำอธิบายที่ชัดเจน
-
แก้ไขปัญหา
ในปัญหา GitLab ให้พูดว่า:
@codetutor fix thisCodeTutor จะสร้างสาขาใหม่ ดำเนินการเปลี่ยนแปลง และเปิดคำขอรวมที่มีการเปลี่ยนแปลง
-
ตรวจสอบคำขอรวม
แสดงความคิดเห็นต่อไปนี้ในคำขอรวม GitLab
@codetutor review this merge requestCodeTutor จะตรวจสอบคำขอรวมและให้ข้อเสนอแนะ