关于 gitlab
通过官方 `glab` CLI 操作 GitLab 的技能,并用 Python 封装脚本将读取结果整理为 Markdown。适用于需要处理仓库、议题、合并请求、CI/CD 和发布的 Agent。
主要功能
- 01读取结果格式化为 Markdown
- 02议题与合并请求操作
- 03CI/CD 流水线监控
- 04仓库与发布管理
适用场景
- 01审查并批准合并请求
- 02查看流水线状态与日志
- 03创建关联合并请求的议题
MCP 相关
该技能未说明 MCP 集成。
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ odyssey4me/ agent-skills --skill gitlab安装后在 Claude Code 中输入/gitlab确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/common-workflows.mdpermissions.mdscripts/gitlab.py详细介绍
GitLab 技能
此技能通过官方 glab CLI 工具集成 GitLab。Python 包装脚本会将读取/查看操作的输出转换为 Markdown 格式。执行操作的命令(创建、合并、关闭、评论)应直接使用 glab。
网络访问
GitLab 命令(glab 和 Python 包装脚本)需要通过出站 HTTPS 访问 GitLab API 和身份验证端点,或已配置的自托管 GitLab 主机。Git fetch/push 需要通过 HTTPS 或 SSH 连接到仓库主机。远程操作需要出站网络访问。如果 Agent 环境对此有限制,请在执行第一条远程命令前,通过该环境的审批或网络控制获取访问权限,并重复使用已授予的授权。本地帮助和文件处理不需要网络访问。技能说明不会授予网络权限。将 DNS、连接和超时故障报告为网络错误;不要通过重置凭据来解决。如果已获批准的访问仍然失败,请停止并报告。身份验证和权限错误需要用户处理。
解析脚本路径
示例中的 SKILL_DIR 是当前加载的 SKILL.md 所在目录。
运行命令前,将其设为该目录的绝对路径;不要假定 Agent 会
设置此 Shell 变量。如果脚本路径包含空格,请将其加引号。
先决条件
安装 glab CLI:安装指南
身份验证
# Authenticate with GitLab
glab auth login
# Verify authentication
glab auth status
支持 GitLab.com、GitLab Dedicated 和 GitLab Self-Managed 实例。 详情请参阅 GitLab CLI 身份验证。
脚本用法
包装脚本(scripts/gitlab.py)会将输出格式化为 Markdown。读取/查看操作请使用此脚本,以获得适合 Agent 使用的输出。执行操作的命令(创建、合并、关闭、评论)请直接使用 glab。各命令的读写分类请参阅 permissions.md。
# Check glab CLI is installed and authenticated
$SKILL_DIR/scripts/gitlab.py check
# Issues
$SKILL_DIR/scripts/gitlab.py issues list --repo GROUP/REPO
$SKILL_DIR/scripts/gitlab.py issues view 123 --repo GROUP/REPO
# Merge Requests
$SKILL_DIR/scripts/gitlab.py mrs list --repo GROUP/REPO
$SKILL_DIR/scripts/gitlab.py mrs view 456 --repo GROUP/REPO
# Pipelines
$SKILL_DIR/scripts/gitlab.py pipelines list --repo GROUP/REPO
$SKILL_DIR/scripts/gitlab.py pipelines view 123456 --repo GROUP/REPO
# Repositories
$SKILL_DIR/scripts/gitlab.py repos list
$SKILL_DIR/scripts/gitlab.py repos view GROUP/REPO
所有列表命令都支持 --limit N(默认值为 30)。
命令(直接使用 glab)
执行操作的命令请直接使用 glab:
Issues
glab issue list # List issues
glab issue view 123 # View issue details
glab issue create # Create new issue
glab issue note 123 # Add comment
glab issue close 123 # Close issue
glab issue update 123 --label bug # Edit issue
完整参考:glab issue
Merge Requests
glab mr list # List merge requests
glab mr view 456 # View MR details
glab mr create # Create new MR
glab mr approve 456 # Approve MR
glab mr merge 456 # Merge MR
glab mr checkout 456 # Checkout MR branch
glab mr diff 456 # View MR diff
glab mr note 456 # Add comment to MR
完整参考:glab mr
流水线与 CI/CD
glab ci list # List pipelines
glab ci view 123456 # View pipeline details
glab ci run # Trigger pipeline
glab ci trace # Watch pipeline logs
glab ci retry 123456 # Retry failed pipeline
glab ci status # Show pipeline status
完整参考:
仓库
glab repo list # List repositories
glab repo view GROUP/REPO # View repository
glab repo create # Create repository
glab repo clone GROUP/REPO # Clone repository
glab repo fork GROUP/REPO # Fork repository
完整参考:glab repo
发布
glab release list # List releases
glab release view v1.0.0 # View release details
glab release create v1.0.0 # Create release
glab release delete v1.0.0 # Delete release
完整参考:glab release
示例
每日 MR 审查
# List MRs assigned to you
glab mr list --assignee=@me
# Review a specific MR
$SKILL_DIR/scripts/gitlab.py mrs view 456
glab mr diff 456
glab mr approve 456
# Verify approval was recorded
$SKILL_DIR/scripts/gitlab.py mrs view 456 # check approval status
创建 Issue 并关联 MR
# Create issue
glab issue create --title "Bug: Login fails" --description "Description" --label bug
# Verify: note the issue number from output
# Create MR that closes it (use issue number from above)
glab mr create --title "Fix login bug" --description "Closes #123"
# Verify MR was created and linked
$SKILL_DIR/scripts/gitlab.py mrs view <number>
监控 CI 流水线
# Check current pipeline status
glab ci status
# Watch pipeline logs in real-time
glab ci trace
# Retry failed jobs
glab ci retry
# Verify pipeline restarted
$SKILL_DIR/scripts/gitlab.py pipelines list
更多示例请参阅 common-workflows.md。
高级用法
用于脚本编写的 JSON 输出
# Get JSON output
glab issue list --output json
# Process with jq
glab mr list --output json | jq '.[] | "\(.iid): \(.title)"'
GitLab API 访问
对于 glab 命令未涵盖的操作:
# Make authenticated API request
glab api projects/:id/issues
# POST request
glab api projects/:id/issues -X POST -f title="Issue" -f description="Text"
# Process response
glab api projects/:id | jq '.star_count'
完整参考:glab api
常用操作的别名
# Create shortcuts
glab alias set mrs 'mr list --assignee=@me'
glab alias set issues 'issue list --assignee=@me'
glab alias set pipelines 'ci list'
# Use them
glab mrs
glab issues
glab pipelines
配置
# View configuration
glab config get
# Set default editor
glab config set editor vim
# Set default Git protocol
glab config set git_protocol ssh
配置存储在 ~/.config/glab-cli/config.yml 中
模型建议
此技能封装了官方 CLI。快速、轻量的模型就足够了。
故障排除
# Check authentication
glab auth status
# Re-authenticate
glab auth login
# Enable debug logging
DEBUG=1 glab issue list
# Check glab version
glab version
官方文档
- GitLab CLI 手册:https://docs.gitlab.com/cli/
- GitLab CLI 仓库:https://gitlab.com/gitlab-org/cli
- GitLab API 文档:https://docs.gitlab.com/ee/api/
- GitLab CI/CD:https://docs.gitlab.com/ee/ci/