GitLab API Skill
Node.js client for the GitLab REST API (v4). Reads config from ./.env.
Security Rules
- - NEVER read, cat, print, grep, or expose the
GITLAB_TOKEN value. - NEVER use
curl, wget, or any tool to call GitLab API directly. All access MUST go through gitlab-client. - AI may read/write
.env to manage GITLAB_URL, but GITLAB_TOKEN must be set by the user manually.
Setup
Requires ./.env with:
CODEBLOCK0
If token is missing, prompt the user to edit ./.env and create a token at <GITLAB_URL>/-/profile/personal_access_tokens (scope: api).
Install (first time): INLINECODE11
Quick Start
CODEBLOCK1
Commands Reference
Format: INLINECODE12
All list actions support --page N --per-page N (default 20, max 100).
Projects
| Action | Usage | Options |
|---|
| list | INLINECODE14 | INLINECODE15 |
| get |
projects get <id> | |
| search |
projects search "term" | |
| create |
projects create --name "name" |
--description --visibility --namespace-id --initialize-with-readme |
| edit |
projects edit <id> |
--name --description --visibility |
| delete |
projects delete <id> | |
| fork |
projects fork <id> |
--namespace |
| members |
projects members <id> | |
| hooks |
projects hooks <id> | |
Issues
| Action | Usage | Options |
|---|
| list | INLINECODE27 | INLINECODE28 |
| get |
issues get --project <id> --iid <iid> | |
| create |
issues create --project <id> --title "T" |
--description --labels --assignee-ids --milestone-id --due-date --confidential |
| edit |
issues edit --project <id> --iid <iid> |
--title --description --state-event --labels --assignee-ids |
| close |
issues close --project <id> --iid <iid> | |
| reopen |
issues reopen --project <id> --iid <iid> | |
| delete |
issues delete --project <id> --iid <iid> | |
| notes |
issues notes --project <id> --iid <iid> | |
| add-note |
issues add-note --project <id> --iid <iid> --body "text" | |
Merge Requests
| Action | Usage | Options |
|---|
| list | INLINECODE39 | INLINECODE40 |
| get |
mrs get --project <id> --iid <iid> | |
| create |
mrs create --project <id> --source-branch "src" --target-branch "tgt" --title "T" |
--description --assignee-id --reviewer-ids --labels --milestone-id --remove-source-branch --squash |
| edit |
mrs edit --project <id> --iid <iid> |
--title --description --state-event --labels --assignee-id |
| merge |
mrs merge --project <id> --iid <iid> |
--merge-commit-message --squash --should-remove-source-branch |
| changes |
mrs changes --project <id> --iid <iid> | |
| commits |
mrs commits --project <id> --iid <iid> | |
| notes |
mrs notes --project <id> --iid <iid> | |
| add-note |
mrs add-note --project <id> --iid <iid> --body "text" | |
| approve |
mrs approve --project <id> --iid <iid> | |
| pipelines |
mrs pipelines --project <id> --iid <iid> | |
Branches
| Action | Usage | Options |
|---|
| list | INLINECODE54 | INLINECODE55 |
| get |
branches get --project <id> --branch "name" | |
| create |
branches create --project <id> --branch "name" --ref "main" | |
| delete |
branches delete --project <id> --branch "name" | |
| delete-merged |
branches delete-merged --project <id> | |
Commits
| Action | Usage | Options |
|---|
| list | INLINECODE60 | INLINECODE61 |
| get |
commits get --project <id> --sha "abc123" | |
| diff |
commits diff --project <id> --sha "abc123" | |
| comments |
commits comments --project <id> --sha "abc123" | |
| add-comment |
commits add-comment --project <id> --sha "abc123" --note "text" | |
Repository / Files
| Action | Usage | Options |
|---|
| tree | INLINECODE66 | INLINECODE67 |
| file |
repo file --project <id> --file-path "path" |
--ref |
| raw |
repo raw --project <id> --file-path "path" |
--ref |
| create-file |
repo create-file --project <id> --file-path "p" --branch "b" --content "c" --commit-message "m" | |
| update-file |
repo update-file --project <id> --file-path "p" --branch "b" --content "c" --commit-message "m" | |
| delete-file |
repo delete-file --project <id> --file-path "p" --branch "b" --commit-message "m" | |
| compare |
repo compare --project <id> --from "main" --to "feat" | |
Pipelines
| Action | Usage | Options |
|---|
| list | INLINECODE76 | INLINECODE77 |
| get |
pipelines get --project <id> --pipeline-id <pid> | |
| jobs |
pipelines jobs --project <id> --pipeline-id <pid> | |
| job-log |
pipelines job-log --project <id> --job-id <jid> | |
| retry |
pipelines retry --project <id> --pipeline-id <pid> | |
| cancel |
pipelines cancel --project <id> --pipeline-id <pid> | |
| create |
pipelines create --project <id> --ref "main" |
--variables "K1=v1,K2=v2" |
Groups
| Action | Usage | Options |
|---|
| list | INLINECODE85 | INLINECODE86 |
| get |
groups get <id> | |
| projects |
groups projects <id> |
--search |
| members |
groups members <id> | |
| issues |
groups issues <id> |
--state |
| mrs |
groups mrs <id> |
--state |
Users
| Action | Usage |
|---|
| me | INLINECODE95 |
| list |
users list [--search "john"] |
| get |
users get <id> |
| projects |
users projects <id> |
Labels
| Action | Usage | Options |
|---|
| list | INLINECODE99 | |
| create |
labels create --project <id> --name "bug" --color "#FF0000" |
--description |
| edit |
labels edit --project <id> --name "bug" |
--new-name --color |
| delete |
labels delete --project <id> --name "bug" | |
Milestones
| Action | Usage | Options |
|---|
| list | INLINECODE105 | INLINECODE106 |
| get |
milestones get --project <id> --milestone-id <mid> | |
| create |
milestones create --project <id> --title "v1.0" |
--description --due-date --start-date |
| edit |
milestones edit --project <id> --milestone-id <mid> |
--title --state-event |
| delete |
milestones delete --project <id> --milestone-id <mid> | |
Tags & Releases
| Action | Usage | Options |
|---|
| tags list | INLINECODE113 | INLINECODE114 |
| tags create |
tags create --project <id> --tag-name "v1.0" --ref "main" |
--message |
| tags delete |
tags delete --project <id> --tag-name "v1.0" | |
| releases list |
releases list --project <id> | |
| releases create |
releases create --project <id> --tag-name "v1.0" --name "R1" |
--description |
Snippets
| Action | Usage | Options |
|---|
| list | INLINECODE121 | |
| get |
snippets get --project <id> --snippet-id <sid> | |
| create |
snippets create --project <id> --title "T" --file-name "f" --content "c" |
--visibility |
Search
| Action | Usage |
|---|
| global | INLINECODE125 |
| project |
search project --project <id> --scope <scope> --search "query" |
| group |
search group --group <id> --scope <scope> --search "query" |
Scopes — global: projects|issues|merge_requests|milestones|snippet_titles|users. Project: issues|merge_requests|milestones|notes|wiki_blobs|commits|blobs. Group: projects|issues|merge_requests|milestones.
Runners
| Action | Usage | Options |
|---|
| list | INLINECODE131 | |
| all |
runners all |
--type --status |
Webhooks
| Action | Usage | Options |
|---|
| list | INLINECODE134 | |
| create |
hooks create --project <id> --url "url" |
--push-events --merge-requests-events --issues-events --token |
| delete |
hooks delete --project <id> --hook-id <hid> | |
Usage Notes
- - Auth: Uses
PRIVATE-TOKEN header. Scopes: api (full), read_api (read-only), read_user, read_repository. - Project ID: Use numeric ID or URL-encoded path (
my-group%2Fmy-project). - Output: JSON. Pipe to
jq for filtering: INLINECODE145 - Dates: ISO 8601 format (
YYYY-MM-DDTHH:MM:SSZ). - Labels: Comma-separated:
--labels "bug,feature,urgent". - Errors:
401 unauthorized, 403 forbidden, 404 not found, 422 validation, 429 rate limited.
GitLab API 技能
用于 GitLab REST API (v4) 的 Node.js 客户端。从 ./.env 读取配置。
安全规则
- - 切勿读取、输出、打印、grep 或暴露 GITLABTOKEN 值。
- 切勿使用 curl、wget 或任何工具直接调用 GitLab API。所有访问必须通过 gitlab-client。
- AI 可以读取/写入 .env 来管理 GITLABURL,但 GITLAB_TOKEN 必须由用户手动设置。
设置
需要包含以下内容的 ./.env 文件:
GITLAB_URL=https://gitlab.fullnine.com.cn
GITLAB_TOKEN=<您的个人访问令牌>
如果缺少令牌,提示用户编辑 ./.env 并在 URL>/-/profile/personalaccess_tokens 创建令牌(作用域:api)。
安装(首次):source ~/.nvm/nvm.sh && npm install
快速开始
bash
gitlab-client users me # 当前用户
gitlab-client projects list --owned # 我的项目
gitlab-client issues list --project 42 --state opened # 项目问题
gitlab-client mrs create --project 42 --source-branch feat --target-branch main --title 我的合并请求
命令参考
格式:gitlab-client <资源> <操作> [ID] [--键 值 ...]
所有列表操作支持 --page N --per-page N(默认 20,最大 100)。
项目
| 操作 | 用法 | 选项 |
|---|
| list | projects list | --search --owned --membership --visibility |
| get |
projects get
| |
| search | projects search 术语 | |
| create | projects create --name 名称 | --description --visibility --namespace-id --initialize-with-readme |
| edit | projects edit | --name --description --visibility |
| delete | projects delete | |
| fork | projects fork | --namespace |
| members | projects members | |
| hooks | projects hooks | |
问题
| 操作 | 用法 | 选项 |
|---|
| list | issues list --project <id> | --state --labels --milestone --assignee-id --search |
| get |
issues get --project --iid | |
| create | issues create --project --title T | --description --labels --assignee-ids --milestone-id --due-date --confidential |
| edit | issues edit --project --iid | --title --description --state-event --labels --assignee-ids |
| close | issues close --project --iid | |
| reopen | issues reopen --project --iid | |
| delete | issues delete --project --iid | |
| notes | issues notes --project --iid | |
| add-note | issues add-note --project --iid --body 文本 | |
合并请求
| 操作 | 用法 | 选项 |
|---|
| list | mrs list --project <id> | --state --labels --milestone --source-branch --target-branch --search |
| get |
mrs get --project --iid | |
| create | mrs create --project --source-branch src --target-branch tgt --title T | --description --assignee-id --reviewer-ids --labels --milestone-id --remove-source-branch --squash |
| edit | mrs edit --project --iid | --title --description --state-event --labels --assignee-id |
| merge | mrs merge --project --iid | --merge-commit-message --squash --should-remove-source-branch |
| changes | mrs changes --project --iid | |
| commits | mrs commits --project --iid | |
| notes | mrs notes --project --iid | |
| add-note | mrs add-note --project --iid --body 文本 | |
| approve | mrs approve --project --iid | |
| pipelines | mrs pipelines --project --iid | |
分支
| 操作 | 用法 | 选项 |
|---|
| list | branches list --project <id> | --search |
| get |
branches get --project --branch 名称 | |
| create | branches create --project --branch 名称 --ref main | |
| delete | branches delete --project --branch 名称 | |
| delete-merged | branches delete-merged --project | |
提交
| 操作 | 用法 | 选项 |
|---|
| list | commits list --project <id> | --ref-name --since --until --path |
| get |
commits get --project --sha abc123 | |
| diff | commits diff --project --sha abc123 | |
| comments | commits comments --project --sha abc123 | |
| add-comment | commits add-comment --project --sha abc123 --note 文本 | |
仓库/文件
| 操作 | 用法 | 选项 |
|---|
| tree | repo tree --project <id> | --path --ref --recursive |
| file |
repo file --project --file-path 路径 | --ref |
| raw | repo raw --project --file-path 路径 | --ref |
| create-file | repo create-file --project --file-path p --branch b --content c --commit-message m | |
| update-file | repo update-file --project --file-path p --branch b --content c --commit-message m | |
| delete-file | repo delete-file --project --file-path p --branch b --commit-message m | |
| compare | repo compare --project --from main --to feat | |
流水线
| 操作 | 用法 | 选项 |
|---|
| list | pipelines list --project <id> | --status --ref |
| get |
pipelines get --project --pipeline-id | |
| jobs | pipelines jobs --project --pipeline-id | |
| job-log | pipelines job-log --project --job-id | |
| retry | pipelines retry --project --pipeline-id | |
| cancel | pipelines cancel --project --pipeline-id | |
| create | pipelines create --project --ref main | --variables K1=v1,K2=v2 |
组
| 操作 | 用法 | 选项 |
|---|
| list | groups list | --search --owned |
| get |
groups get | |
| projects | groups projects | --search |
| members | groups members | |
| issues | groups issues | --state |
| mrs | groups mrs | --state |
用户
users list [--search john] |
| get | users get |
| projects | users projects |
标签
| 操作 | 用法 | 选项 |
|---|
| list | labels list --project <id> | |
| create |
labels create --project