gitlab

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitLab Skill

GitLab 技能

This skill provides GitLab integration using the official
glab
CLI tool. A Python wrapper script produces markdown-formatted output for read/view operations. Action commands (create, merge, close, comment) should use
glab
directly.
本技能通过官方
glab
CLI工具实现GitLab集成。针对读取/查看操作,我们提供了一个Python封装脚本来生成markdown格式的输出。操作类命令(创建、合并、关闭、评论)应直接使用
glab

Prerequisites

前置要求

Install glab CLI: installation guide
安装glab CLI: 安装指南

Authentication

身份认证

bash
undefined
bash
undefined

Authenticate with GitLab

与GitLab进行身份认证

glab auth login
glab auth login

Verify authentication

验证认证状态

glab auth status

Supports GitLab.com, GitLab Dedicated, and GitLab Self-Managed instances.
See [GitLab CLI Authentication](https://docs.gitlab.com/cli/#authentication) for details.
glab auth status

支持GitLab.com、GitLab专属实例以及GitLab自建实例。
详情请查看[GitLab CLI身份认证](https://docs.gitlab.com/cli/#authentication)。

Script Usage

脚本使用方式

The wrapper script (
scripts/gitlab.py
) formats output as markdown. Use it for read/view operations to get agent-consumable output. Use
glab
directly for action commands (create, merge, close, comment).
bash
undefined
封装脚本(
scripts/gitlab.py
)会将输出格式化为markdown格式。读取/查看操作可以使用该脚本来获取可被Agent消费的输出,操作类命令(创建、合并、关闭、评论)请直接使用
glab
bash
undefined

Check glab CLI is installed and authenticated

检查glab CLI是否已安装并完成认证

$SKILL_DIR/scripts/gitlab.py check
$SKILL_DIR/scripts/gitlab.py check

Issues

Issues相关操作

$SKILL_DIR/scripts/gitlab.py issues list --repo GROUP/REPO $SKILL_DIR/scripts/gitlab.py issues view 123 --repo GROUP/REPO
$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
$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
$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

All commands support `--limit N` for list commands (default 30).
$SKILL_DIR/scripts/gitlab.py repos list $SKILL_DIR/scripts/gitlab.py repos view GROUP/REPO

所有列表类命令都支持`--limit N`参数指定返回数量(默认30条)。

Commands (Direct glab Usage)

命令(直接使用glab)

For action commands, use
glab
directly:
操作类命令请直接使用
glab

Issues

Issues

bash
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
Full reference: glab issue
bash
glab issue list                    # 列出issue
glab issue view 123                # 查看issue详情
glab issue create                  # 创建新issue
glab issue note 123                # 添加评论
glab issue close 123               # 关闭issue
glab issue update 123 --label bug  # 编辑issue
完整参考文档:glab issue

Merge Requests

合并请求

bash
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
Full reference: glab mr
bash
glab mr list                       # 列出合并请求
glab mr view 456                   # 查看MR详情
glab mr create                     # 创建新MR
glab mr approve 456                # 审批MR
glab mr merge 456                  # 合并MR
glab mr checkout 456               # 切换到MR对应的分支
glab mr diff 456                   # 查看MR变更内容
glab mr note 456                   # 给MR添加评论
完整参考文档:glab mr

Pipelines & CI/CD

流水线与CI/CD

bash
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
Full references:
bash
glab ci list                       # 列出流水线
glab ci view 123456                # 查看流水线详情
glab ci run                        # 触发流水线
glab ci trace                      # 查看流水线实时日志
glab ci retry 123456               # 重试失败的流水线
glab ci status                     # 显示流水线状态
完整参考文档:

Repositories

代码仓库

bash
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
Full reference: glab repo
bash
glab repo list                     # 列出代码仓库
glab repo view GROUP/REPO          # 查看仓库信息
glab repo create                   # 创建代码仓库
glab repo clone GROUP/REPO         # 克隆代码仓库
glab repo fork GROUP/REPO          # Fork代码仓库
完整参考文档:glab repo

Releases

版本发布

bash
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
Full reference: glab release
bash
glab release list                  # 列出版本发布
glab release view v1.0.0           # 查看版本发布详情
glab release create v1.0.0         # 创建版本发布
glab release delete v1.0.0         # 删除版本发布
完整参考文档:glab release

Examples

使用示例

Daily MR Review

日常MR评审

bash
undefined
bash
undefined

List MRs assigned to you

列出分配给你的MR

glab mr list --assignee=@me
glab mr list --assignee=@me

Review a specific MR

评审指定MR

$SKILL_DIR/scripts/gitlab.py mrs view 456 glab mr diff 456 glab mr approve 456
$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
undefined
$SKILL_DIR/scripts/gitlab.py mrs view 456 # 检查审批状态
undefined

Create Issue and Link MR

创建Issue并关联MR

bash
undefined
bash
undefined

Create issue

创建issue

glab issue create --title "Bug: Login fails" --description "Description" --label bug
glab issue create --title "Bug: 登录失败" --description "问题描述" --label bug

Verify: note the issue number from output

确认创建成功:记录输出的issue编号

Create MR that closes it (use issue number from above)

创建关联该issue的MR(使用上面得到的issue编号)

glab mr create --title "Fix login bug" --description "Closes #123"
glab mr create --title "修复登录bug" --description "Closes #123"

Verify MR was created and linked

确认MR已创建并完成关联

$SKILL_DIR/scripts/gitlab.py mrs view <number>
undefined
$SKILL_DIR/scripts/gitlab.py mrs view <number>
undefined

Monitor CI Pipeline

监控CI流水线

bash
undefined
bash
undefined

Check current pipeline status

查看当前流水线状态

glab ci status
glab ci status

Watch pipeline logs in real-time

实时查看流水线日志

glab ci trace
glab ci trace

Retry failed jobs

重试失败的任务

glab ci retry
glab ci retry

Verify pipeline restarted

确认流水线已重启

$SKILL_DIR/scripts/gitlab.py pipelines list

See [common-workflows.md](references/common-workflows.md) for more examples.
$SKILL_DIR/scripts/gitlab.py pipelines list

更多示例请查看[common-workflows.md](references/common-workflows.md)。

Advanced Usage

高级用法

JSON Output for Scripting

适用于脚本编写的JSON输出

bash
undefined
bash
undefined

Get JSON output

获取JSON格式输出

glab issue list --output json
glab issue list --output json

Process with jq

使用jq处理输出

glab mr list --output json | jq '.[] | "(.iid): (.title)"'
undefined
glab mr list --output json | jq '.[] | "(.iid): (.title)"'
undefined

GitLab API Access

GitLab API访问

For operations not covered by glab commands:
bash
undefined
如果glab命令没有覆盖你需要的操作,可以直接调用API:
bash
undefined

Make authenticated API request

发起已认证的API请求

glab api projects/:id/issues
glab api projects/:id/issues

POST request

POST请求

glab api projects/:id/issues -X POST -f title="Issue" -f description="Text"
glab api projects/:id/issues -X POST -f title="Issue" -f description="Text"

Process response

处理响应

glab api projects/:id | jq '.star_count'

Full reference: [glab api](https://docs.gitlab.com/cli/commands/glab_api.html)
glab api projects/:id | jq '.star_count'

完整参考文档:[glab api](https://docs.gitlab.com/cli/commands/glab_api.html)

Aliases for Frequent Operations

高频操作别名设置

bash
undefined
bash
undefined

Create shortcuts

创建快捷命令

glab alias set mrs 'mr list --assignee=@me' glab alias set issues 'issue list --assignee=@me' glab alias set pipelines 'ci list'
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
undefined
glab mrs glab issues glab pipelines
undefined

Configuration

配置

bash
undefined
bash
undefined

View configuration

查看配置

glab config get
glab config get

Set default editor

设置默认编辑器

glab config set editor vim
glab config set editor vim

Set default Git protocol

设置默认Git协议

glab config set git_protocol ssh

Configuration stored in `~/.config/glab-cli/config.yml`
glab config set git_protocol ssh

配置存储在`~/.config/glab-cli/config.yml`中

Model Guidance

模型使用建议

This skill wraps an official CLI. A fast, lightweight model is sufficient.
本技能封装的是官方CLI工具,使用轻量、快速的模型即可满足需求。

Troubleshooting

问题排查

bash
undefined
bash
undefined

Check authentication

检查认证状态

glab auth status
glab auth status

Re-authenticate

重新认证

glab auth login
glab auth login

Enable debug logging

启用debug日志

DEBUG=1 glab issue list
DEBUG=1 glab issue list

Check glab version

检查glab版本

glab version
undefined
glab version
undefined

Official Documentation

官方文档