gitlab

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitLab API

GitLab API

Use the GitLab REST API via direct
curl
calls to manage projects, issues, merge requests, and pipelines.
Official docs:
https://docs.gitlab.com/ee/api/

通过直接调用
curl
来使用GitLab REST API,以管理项目、议题、合并请求和流水线
官方文档:
https://docs.gitlab.com/ee/api/

When to Use

适用场景

Use this skill when you need to:
  • Manage projects - list, create, get project details
  • Handle issues - create, update, close, list issues
  • Work with merge requests - create, list, merge MRs
  • Check pipelines - list jobs, view pipeline status
  • Manage users - search users, get user info

当你需要以下操作时,可以使用本技能:
  • 管理项目 - 列出、创建、获取项目详情
  • 处理议题 - 创建、更新、关闭、列出议题
  • 操作合并请求 - 创建、列出、合并MR
  • 查看流水线 - 列出任务、查看流水线状态
  • 管理用户 - 搜索用户、获取用户信息

Prerequisites

前置条件

  1. Go to GitLab → User Settings → Access Tokens
  2. Create a personal access token with
    api
    scope
  3. Copy the generated token
bash
export GITLAB_HOST="gitlab.com" # Or your self-hosted GitLab domain
export GITLAB_TOKEN="glpat-xxxxxxxxxxxx" # Personal access token with api scope
  1. 进入GitLab → 用户设置 → 访问令牌
  2. 创建一个拥有
    api
    权限范围的个人访问令牌
  3. 复制生成的令牌
bash
export GITLAB_HOST="gitlab.com" # 或者你的自托管GitLab域名
export GITLAB_TOKEN="glpat-xxxxxxxxxxxx" # 拥有api权限范围的个人访问令牌

Rate Limits

请求速率限制

GitLab.com has rate limits of ~2000 requests per minute for authenticated users. Self-hosted instances may vary.

Important: When using
$VAR
in a command that pipes to another command, wrap the command containing
$VAR
in
bash -c '...'
. Due to a Claude Code bug, environment variables are silently cleared when pipes are used directly.
bash
bash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"' | jq .
GitLab.com对已认证用户的请求速率限制为每分钟约2000次。自托管实例的限制可能有所不同。

重要提示: 当在包含管道的命令中使用
$VAR
时,请将包含
$VAR
的命令用
bash -c '...'
包裹。由于Claude Code的一个bug,直接使用管道时环境变量会被静默清除。
bash
bash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"' | jq .

How to Use

使用方法

All examples below assume
GITLAB_HOST
and
GITLAB_TOKEN
are set.
Base URL:
https://${GITLAB_HOST}/api/v4
Note: Project IDs can be numeric (e.g.,
123
) or URL-encoded paths (e.g.,
mygroup%2Fmyproject
).

以下所有示例均假设已设置
GITLAB_HOST
GITLAB_TOKEN
环境变量。
基础URL:
https://${GITLAB_HOST}/api/v4
注意:项目ID可以是数字(例如:
123
),也可以是URL编码的路径(例如:
mygroup%2Fmyproject
)。

1. Get Current User

1. 获取当前用户

Verify your authentication:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/user" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '{id, username, name, email, state}'

验证你的身份认证:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/user" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '{id, username, name, email, state}'

2. List Projects

2. 列出项目

Get projects accessible to you:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects?membership=true&per_page=20" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '.[] | {id, path_with_namespace, visibility, default_branch}'
Filter options:
  • membership=true
    - Only projects you're a member of
  • owned=true
    - Only projects you own
  • search=keyword
    - Search by name
  • visibility=public|internal|private
    - Filter by visibility

获取你有权访问的项目:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects?membership=true&per_page=20" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '.[] | {id, path_with_namespace, visibility, default_branch}'
过滤选项:
  • membership=true
    - 仅显示你作为成员的项目
  • owned=true
    - 仅显示你拥有的项目
  • search=keyword
    - 按名称搜索
  • visibility=public|internal|private
    - 按可见性过滤

3. Get Project Details

3. 获取项目详情

Get details for a specific project. Replace
<project-id>
with the numeric project ID or URL-encoded path (e.g.,
mygroup%2Fmyproject
):
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '{id, name, path_with_namespace, default_branch, visibility, web_url}

获取特定项目的详情。将
<project-id>
替换为数字项目ID或URL编码的路径(例如:
mygroup%2Fmyproject
):
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '{id, name, path_with_namespace, default_branch, visibility, web_url}

4. List Project Issues

4. 列出项目议题

Get issues for a project. Replace
<project-id>
with the numeric project ID or URL-encoded path:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues?state=opened&per_page=20" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '.[] | {iid, title, state, author: .author.username, labels, web_url}'
Filter options:
  • state=opened|closed|all
    - Filter by state
  • labels=bug,urgent
    - Filter by labels
  • assignee_id=123
    - Filter by assignee
  • search=keyword
    - Search in title/description

获取项目的议题。将
<project-id>
替换为数字项目ID或URL编码的路径:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues?state=opened&per_page=20" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '.[] | {iid, title, state, author: .author.username, labels, web_url}'
过滤选项:
  • state=opened|closed|all
    - 按状态过滤
  • labels=bug,urgent
    - 按标签过滤
  • assignee_id=123
    - 按经办人过滤
  • search=keyword
    - 在标题/描述中搜索

5. Get Issue Details

5. 获取议题详情

Get a specific issue. Replace
<project-id>
and
<issue-iid>
with actual values:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues/<issue-iid>" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '{iid, title, description, state, author: .author.username, assignees: [.assignees[].username], labels, created_at, web_url}'

获取特定议题的详情。将
<project-id>
<issue-iid>
替换为实际值:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues/<issue-iid>" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '{iid, title, description, state, author: .author.username, assignees: [.assignees[].username], labels, created_at, web_url}'

6. Create Issue

6. 创建议题

Create a new issue in a project. Replace
<project-id>
with the actual project ID:
Write to
/tmp/gitlab_request.json
:
json
{
  "title": "Bug: Login page not loading",
  "description": "The login page shows a blank screen on mobile devices.",
  "labels": "bug,frontend"
}
Then run:
bash
bash -c 'curl -s -X POST "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{iid, title, web_url}'

在项目中创建新议题。将
<project-id>
替换为实际项目ID:
写入
/tmp/gitlab_request.json
json
{
  "title": "Bug: 登录页面无法加载",
  "description": "移动端设备上登录页面显示空白屏幕。",
  "labels": "bug,frontend"
}
然后运行:
bash
bash -c 'curl -s -X POST "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{iid, title, web_url}'

7. Create Issue with Assignee and Milestone

7. 创建带经办人和里程碑的议题

Create issue with additional fields. Replace
<project-id>
,
<assignee-id>
, and
<milestone-id>
with actual IDs:
Write to
/tmp/gitlab_request.json
:
json
{
  "title": "Implement user profile page",
  "description": "Create a user profile page with avatar and bio.",
  "assignee_ids": [<assignee-id>],
  "milestone_id": <milestone-id>,
  "labels": "feature,frontend"
}
Then run:
bash
bash -c 'curl -s -X POST "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{iid, title, web_url}'

创建包含额外字段的议题。将
<project-id>
<assignee-id>
<milestone-id>
替换为实际ID:
写入
/tmp/gitlab_request.json
json
{
  "title": "实现用户个人资料页面",
  "description": "创建包含头像和个人简介的用户个人资料页面。",
  "assignee_ids": [<assignee-id>],
  "milestone_id": <milestone-id>,
  "labels": "feature,frontend"
}
然后运行:
bash
bash -c 'curl -s -X POST "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{iid, title, web_url}'

8. Update Issue

8. 更新议题

Update an existing issue. Replace
<project-id>
and
<issue-iid>
with actual values:
Write to
/tmp/gitlab_request.json
:
json
{
  "title": "Updated: Bug fix for login page",
  "labels": "bug,frontend,in-progress"
}
Then run:
bash
bash -c 'curl -s -X PUT "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues/<issue-iid>" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{iid, title, labels, updated_at}'

更新现有议题。将
<project-id>
<issue-iid>
替换为实际值:
写入
/tmp/gitlab_request.json
json
{
  "title": "更新:修复登录页面Bug",
  "labels": "bug,frontend,in-progress"
}
然后运行:
bash
bash -c 'curl -s -X PUT "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues/<issue-iid>" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{iid, title, labels, updated_at}'

9. Close Issue

9. 关闭议题

Close an issue. Replace
<project-id>
and
<issue-iid>
with actual values:
Write to
/tmp/gitlab_request.json
:
json
{
  "state_event": "close"
}
Then run:
bash
bash -c 'curl -s -X PUT "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues/<issue-iid>" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{iid, title, state}'
Use
"state_event": "reopen"
to reopen a closed issue.

关闭议题。将
<project-id>
<issue-iid>
替换为实际值:
写入
/tmp/gitlab_request.json
json
{
  "state_event": "close"
}
然后运行:
bash
bash -c 'curl -s -X PUT "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues/<issue-iid>" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{iid, title, state}'
使用
"state_event": "reopen"
可以重新打开已关闭的议题。

10. Add Comment to Issue

10. 为议题添加评论

Add a note/comment to an issue. Replace
<project-id>
and
<issue-iid>
with actual values:
Write to
/tmp/gitlab_request.json
:
json
{
  "body": "Investigating this issue. Will update soon."
}
Then run:
bash
bash -c 'curl -s -X POST "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues/<issue-iid>/notes" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{id, body, author: .author.username, created_at}'

为议题添加备注/评论。将
<project-id>
<issue-iid>
替换为实际值:
写入
/tmp/gitlab_request.json
json
{
  "body": "正在调查该议题,稍后更新。"
}
然后运行:
bash
bash -c 'curl -s -X POST "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues/<issue-iid>/notes" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{id, body, author: .author.username, created_at}'

11. List Merge Requests

11. 列出合并请求

Get merge requests for a project. Replace
<project-id>
with the actual project ID:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>/merge_requests?state=opened&per_page=20" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '.[] | {iid, title, state, source_branch, target_branch, author: .author.username, web_url}'
Filter options:
  • state=opened|closed|merged|all
    - Filter by state
  • scope=created_by_me|assigned_to_me|all
    - Filter by involvement
  • labels=review-needed
    - Filter by labels

获取项目的合并请求。将
<project-id>
替换为实际项目ID:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>/merge_requests?state=opened&per_page=20" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '.[] | {iid, title, state, source_branch, target_branch, author: .author.username, web_url}'
过滤选项:
  • state=opened|closed|merged|all
    - 按状态过滤
  • scope=created_by_me|assigned_to_me|all
    - 按参与角色过滤
  • labels=review-needed
    - 按标签过滤

12. Get Merge Request Details

12. 获取合并请求详情

Get a specific merge request. Replace
<project-id>
and
<mr-iid>
with actual values:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>/merge_requests/<mr-iid>" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '{iid, title, state, source_branch, target_branch, author: .author.username, merge_status, has_conflicts, web_url}'

获取特定合并请求的详情。将
<project-id>
<mr-iid>
替换为实际值:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>/merge_requests/<mr-iid>" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '{iid, title, state, source_branch, target_branch, author: .author.username, merge_status, has_conflicts, web_url}'

13. Create Merge Request

13. 创建合并请求

Create a new merge request. Replace
<project-id>
with the actual project ID:
Write to
/tmp/gitlab_request.json
:
json
{
  "source_branch": "feature/user-profile",
  "target_branch": "main",
  "title": "Add user profile page",
  "description": "This MR adds a new user profile page with avatar support."
}
Then run:
bash
bash -c 'curl -s -X POST "https://${GITLAB_HOST}/api/v4/projects/<project-id>/merge_requests" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{iid, title, web_url}'

创建新的合并请求。将
<project-id>
替换为实际项目ID:
写入
/tmp/gitlab_request.json
json
{
  "source_branch": "feature/user-profile",
  "target_branch": "main",
  "title": "添加用户个人资料页面",
  "description": "该MR添加了一个支持头像的新用户个人资料页面。"
}
然后运行:
bash
bash -c 'curl -s -X POST "https://${GITLAB_HOST}/api/v4/projects/<project-id>/merge_requests" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{iid, title, web_url}'

14. Merge a Merge Request

14. 合并合并请求

Merge an MR (if it's ready). Replace
<project-id>
and
<mr-iid>
with actual values:
Write to
/tmp/gitlab_request.json
:
json
{
  "merge_when_pipeline_succeeds": true
}
Then run:
bash
bash -c 'curl -s -X PUT "https://${GITLAB_HOST}/api/v4/projects/<project-id>/merge_requests/<mr-iid>/merge" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{iid, title, state, merged_by: .merged_by.username}'
Options:
  • merge_when_pipeline_succeeds=true
    - Auto-merge when pipeline passes
  • squash=true
    - Squash commits before merging
  • should_remove_source_branch=true
    - Delete source branch after merge

合并MR(如果已准备好)。将
<project-id>
<mr-iid>
替换为实际值:
写入
/tmp/gitlab_request.json
json
{
  "merge_when_pipeline_succeeds": true
}
然后运行:
bash
bash -c 'curl -s -X PUT "https://${GITLAB_HOST}/api/v4/projects/<project-id>/merge_requests/<mr-iid>/merge" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{iid, title, state, merged_by: .merged_by.username}'
可选参数:
  • merge_when_pipeline_succeeds=true
    - 流水线通过后自动合并
  • squash=true
    - 合并前压缩提交
  • should_remove_source_branch=true
    - 合并后删除源分支

15. List Pipelines

15. 列出流水线

Get pipelines for a project. Replace
<project-id>
with the actual project ID:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>/pipelines?per_page=10" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '.[] | {id, status, ref, sha: .sha[0:8], created_at, web_url}'

获取项目的流水线。将
<project-id>
替换为实际项目ID:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>/pipelines?per_page=10" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '.[] | {id, status, ref, sha: .sha[0:8], created_at, web_url}'

16. Get Pipeline Details

16. 获取流水线详情

Get details of a specific pipeline. Replace
<project-id>
and
<pipeline-id>
with actual values:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>/pipelines/<pipeline-id>" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '{id, status, ref, duration, finished_at, web_url}'

获取特定流水线的详情。将
<project-id>
<pipeline-id>
替换为实际值:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>/pipelines/<pipeline-id>" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '{id, status, ref, duration, finished_at, web_url}'

17. List Pipeline Jobs

17. 列出流水线任务

Get jobs in a pipeline. Replace
<project-id>
and
<pipeline-id>
with actual values:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>/pipelines/<pipeline-id>/jobs" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '.[] | {id, name, stage, status, duration}'

获取流水线中的任务。将
<project-id>
<pipeline-id>
替换为实际值:
bash
bash -c 'curl -s "https://${GITLAB_HOST}/api/v4/projects/<project-id>/pipelines/<pipeline-id>/jobs" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}"' | jq '.[] | {id, name, stage, status, duration}'

18. Search Users

18. 搜索用户

Search for users:
Write to
/tmp/gitlab_search.txt
:
john
bash
bash -c 'curl -s -G "https://${GITLAB_HOST}/api/v4/users" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --data-urlencode "search@/tmp/gitlab_search.txt"' | jq '.[] | {id, username, name, state}'

搜索用户:
写入
/tmp/gitlab_search.txt
john
bash
bash -c 'curl -s -G "https://${GITLAB_HOST}/api/v4/users" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --data-urlencode "search@/tmp/gitlab_search.txt"' | jq '.[] | {id, username, name, state}'

19. Create Project

19. 创建项目

Create a new project:
Write to
/tmp/gitlab_request.json
:
json
{
  "name": "my-new-project",
  "visibility": "private",
  "initialize_with_readme": true
}
Then run:
bash
bash -c 'curl -s -X POST "https://${GITLAB_HOST}/api/v4/projects" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{id, path_with_namespace, web_url}'

创建新项目:
写入
/tmp/gitlab_request.json
json
{
  "name": "my-new-project",
  "visibility": "private",
  "initialize_with_readme": true
}
然后运行:
bash
bash -c 'curl -s -X POST "https://${GITLAB_HOST}/api/v4/projects" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" -d @/tmp/gitlab_request.json' | jq '{id, path_with_namespace, web_url}'

20. Delete Issue

20. 删除议题

Delete an issue (requires admin or owner permissions). Replace
<project-id>
and
<issue-iid>
with actual values:
bash
bash -c 'curl -s -X DELETE "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues/<issue-iid>" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" -w "\nHTTP Status: %{http_code}"'
Returns 204 No Content on success.

删除议题(需要管理员或所有者权限)。将
<project-id>
<issue-iid>
替换为实际值:
bash
bash -c 'curl -s -X DELETE "https://${GITLAB_HOST}/api/v4/projects/<project-id>/issues/<issue-iid>" --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" -w "\nHTTP状态码: %{http_code}"'
成功时返回204 No Content。

Project ID Encoding

项目ID编码

When using project paths instead of numeric IDs, URL-encode the path:
  • mygroup/myproject
    mygroup%2Fmyproject
  • mygroup/subgroup/myproject
    mygroup%2Fsubgroup%2Fmyproject
bash
undefined
当使用项目路径而非数字ID时,需要对路径进行URL编码:
  • mygroup/myproject
    mygroup%2Fmyproject
  • mygroup/subgroup/myproject
    mygroup%2Fsubgroup%2Fmyproject
bash
undefined

Using numeric ID

使用数字ID

PROJECT_ID="123"
PROJECT_ID="123"

Using encoded path

使用编码后的路径

PROJECT_ID="mygroup%2Fmyproject"

---
PROJECT_ID="mygroup%2Fmyproject"

---

Guidelines

注意事项

  1. Use IID for issues/MRs: Within a project, use
    iid
    (internal ID like #1, #2) not the global
    id
  2. URL-encode project paths: If using paths instead of numeric IDs, encode slashes as
    %2F
  3. Handle pagination: Use
    per_page
    and
    page
    params for large result sets
  4. Check merge status: Before merging, verify
    merge_status
    is
    can_be_merged
  5. Rate limiting: Implement backoff if you receive 429 responses
  6. Self-hosted GitLab: Set
    GITLAB_HOST
    to your instance domain (without https://)
  1. 使用IID操作议题/MR:在项目内,使用
    iid
    (如#1、#2这样的内部ID)而非全局
    id
  2. URL编码项目路径:如果使用路径而非数字ID,需将斜杠编码为
    %2F
  3. 处理分页:对于大量结果集,使用
    per_page
    page
    参数
  4. 检查合并状态:合并前需验证
    merge_status
    can_be_merged
  5. 速率限制处理:如果收到429响应,需实现重试机制
  6. 自托管GitLab:将
    GITLAB_HOST
    设置为你的实例域名(无需https://)