关于 gitlab-search
gitlab-search 是用于 GitLab 搜索的技能,通过 glab api 调用接口,适合查找项目、代码及协作记录。支持全局、项目和群组范围,并可分页获取结果。
主要功能
- 01搜索项目、问题和合并请求
- 02搜索代码、提交与用户
- 03支持全局、项目及群组范围
- 04分页获取搜索结果
- 05使用 glab api 调用接口
适用场景
- 01在可访问项目中查找代码片段
- 02跨项目定位相关问题或合并请求
- 03检索提交记录和 wiki 内容
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ grandcamel/ gitlab-assistant-skills --skill gitlab-search安装后在 Claude Code 中输入/gitlab-search确认已加载。
详细介绍
搜索技能
使用 glab api 原始端点调用执行 GitLab 搜索操作。
快速参考
| 操作 | 命令模式 | 风险 |
|---|---|---|
| 搜索项目 | glab api "search?scope=projects&search=..." | - |
| 搜索议题 | glab api "search?scope=issues&search=..." | - |
| 搜索 MR | glab api "search?scope=merge_requests&search=..." | - |
| 搜索代码 | glab api "search?scope=blobs&search=..." | - |
| 搜索提交 | glab api "search?scope=commits&search=..." | - |
| 搜索用户 | glab api "search?scope=users&search=..." | - |
| 搜索 Wiki | glab api "search?scope=wiki_blobs&search=..." | - |
| 项目搜索 | glab api "projects/:id/search?scope=...&search=..." | - |
| 群组搜索 | glab api "groups/:id/search?scope=...&search=..." | - |
风险说明:- 安全 | ⚠️ 谨慎 | ⚠️⚠️ 警告 | ⚠️⚠️⚠️ 危险
何时使用此技能
始终在以下情况使用:
- 用户想要在 GitLab 中搜索或查找内容
- 用户提到“搜索”“查找”“查询”
- 用户询问“在哪里”“哪个项目有”“查找所有”
- 用户想要搜索代码、议题、MR、提交或 Wiki
以下情况切勿使用:
- 用户想要列出所有条目(使用特定技能:gitlab-issue、gitlab-mr 等)
- 用户知道确切的项目、议题或 MR ID
- 用户想要搜索本地文件(在本地使用 grep/find)
API 前置条件
必需的令牌作用域: read_api 或 api
注意: 搜索结果仅包含已认证用户有权访问的资源。
搜索作用域
| 作用域 | 说明 | 可用范围 |
|---|---|---|
projects | 搜索项目名称/描述 | 全局、群组 |
issues | 搜索议题标题/描述 | 全局、群组、项目 |
merge_requests | 搜索 MR 标题/描述 | 全局、群组、项目 |
milestones | 搜索里程碑标题 | 全局、群组、项目 |
snippet_titles | 搜索代码片段标题 | 全局 |
wiki_blobs | 搜索 Wiki 内容 | 全局、群组、项目 |
commits | 搜索提交消息 | 全局、群组、项目 |
blobs | 搜索代码/文件内容 | 全局、群组、项目 |
notes | 搜索评论 | 全局、群组、项目 |
users | 搜索用户名/姓名 | 全局 |
可用命令
全局搜索
# Search projects by name
glab api "search?scope=projects&search=api+gateway" --method GET
# Search issues globally
glab api "search?scope=issues&search=authentication+bug" --method GET
# Search merge requests
glab api "search?scope=merge_requests&search=refactor" --method GET
# Search code (blobs)
glab api "search?scope=blobs&search=TODO+fixme" --method GET
# Search commits
glab api "search?scope=commits&search=fix+security" --method GET
# Search wiki content
glab api "search?scope=wiki_blobs&search=installation" --method GET
# Search users
glab api "search?scope=users&search=john" --method GET
# Search milestones
glab api "search?scope=milestones&search=v2.0" --method GET
# Search comments/notes
glab api "search?scope=notes&search=approved" --method GET
项目范围搜索
# Search issues in specific project
glab api "projects/123/search?scope=issues&search=bug" --method GET
# Search code in project
glab api "projects/123/search?scope=blobs&search=function+authenticate" --method GET
# Search commits in project
glab api "projects/123/search?scope=commits&search=fix" --method GET
# Search wiki in project
glab api "projects/123/search?scope=wiki_blobs&search=setup" --method GET
# Search MRs in project
glab api "projects/123/search?scope=merge_requests&search=feature" --method GET
# Search notes in project
glab api "projects/123/search?scope=notes&search=LGTM" --method GET
# Search milestones in project
glab api "projects/123/search?scope=milestones&search=sprint" --method GET
# Using project path (URL-encoded)
glab api "projects/$(echo 'mygroup/myproject' | jq -Rr @uri)/search?scope=blobs&search=TODO"
群组范围搜索
# Search issues in group
glab api "groups/456/search?scope=issues&search=urgent" --method GET
# Search code across group
glab api "groups/456/search?scope=blobs&search=api+key" --method GET
# Search projects in group
glab api "groups/456/search?scope=projects&search=backend" --method GET
# Search MRs in group
glab api "groups/456/search?scope=merge_requests&search=hotfix" --method GET
# Using group path (URL-encoded)
glab api "groups/$(echo 'mygroup' | jq -Rr @uri)/search?scope=issues&search=bug"
分页
# Get more results per page
glab api "search?scope=issues&search=bug&per_page=50" --method GET
# Get specific page
glab api "search?scope=issues&search=bug&per_page=50&page=2" --method GET
# Auto-paginate all results
glab api "search?scope=projects&search=api" --paginate
高级搜索语法
# Exact phrase search (use quotes, URL-encoded)
glab api "search?scope=blobs&search=%22exact+phrase%22" --method GET
# Filename filter in code search
glab api "search?scope=blobs&search=authenticate+filename:auth.py" --method GET
# Extension filter
glab api "search?scope=blobs&search=class+extension:java" --method GET
# Path filter
glab api "search?scope=blobs&search=config+path:src/main" --method GET
输出处理
提取关键字段
# Get issue IDs and titles
glab api "search?scope=issues&search=bug" | \
jq -r '.[] | "\(.project_id)#\(.iid): \(.title)"'
# Get project names and URLs
glab api "search?scope=projects&search=api" | \
jq -r '.[] | "\(.path_with_namespace): \(.web_url)"'
# Get code matches with file paths
glab api "search?scope=blobs&search=TODO" | \
jq -r '.[] | "\(.project_id):\(.path):\(.startline) \(.data)"'
# Get commit info
glab api "search?scope=commits&search=fix" | \
jq -r '.[] | "\(.short_id): \(.title)"'
统计结果数量
# Count matching issues
glab api "search?scope=issues&search=bug" --paginate | jq 'length'
# Count by project
glab api "search?scope=issues&search=bug" --paginate | \
jq 'group_by(.project_id) | map({project: .[0].project_id, count: length})'
常见工作流
工作流 1:查找代码库中的所有 TODO
# Search for TODO comments across all accessible projects
glab api "search?scope=blobs&search=TODO" --paginate | \
jq -r '.[] | "\(.project_id):\(.path):\(.startline)"'
工作流 2:跨团队项目查找议题
# Get group ID
group_id=$(glab api "groups/$(echo 'myteam' | jq -Rr @uri)" | jq -r '.id')
# Search for critical issues in group
glab api "groups/$group_id/search?scope=issues&search=critical" --paginate | \
jq -r '.[] | "\(.references.full): \(.title)"'
工作流 3:查找参与某项功能开发的人员
# Search commits mentioning feature
glab api "projects/123/search?scope=commits&search=authentication" | \
jq -r '.[] | "\(.author_name): \(.title)"'
工作流 4:查找与安全相关的代码
# Search for potential security patterns
for term in "password" "secret" "api_key" "token"; do
echo "=== Searching for: $term ==="
glab api "projects/123/search?scope=blobs&search=$term" | \
jq -r '.[] | "\(.path):\(.startline)"'
done
工作流 5:查找相关 MR
# Search MRs by feature name
glab api "search?scope=merge_requests&search=oauth+integration" | \
jq -r '.[] | "!\(.iid) [\(.state)]: \(.title)"'
搜索技巧
有效的搜索词
| 用途 | 搜索示例 |
|---|---|
| Bug 修复 | fix bug、resolve issue、patch |
| 功能 | add feature、implement、new |
| 重构 | refactor、cleanup、improve |
| 安全 | security、vulnerability、CVE |
| 性能 | performance、optimize、speed |
| 文档 | docs、readme、documentation |
对特殊字符进行 URL 编码
# Space -> +
glab api "search?scope=issues&search=fix+bug"
# Quotes (for exact match) -> %22
glab api "search?scope=blobs&search=%22exact+phrase%22"
# Hash -> %23
glab api "search?scope=issues&search=issue%231234"
故障排查
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 结果为空 | 没有匹配项或无访问权限 | 核实搜索词并检查权限 |
| 结果不完整 | 需要分页 | 使用 --paginate 标志 |
| 400 Bad Request | 作用域无效 | 检查作用域是否适用于该端点 |
| 搜索缓慢 | 结果集较大 | 添加筛选条件或缩小范围 |
| 没有代码搜索结果 | 基础搜索已停用 | 联系管理员启用高级搜索 |
搜索限制
- 基础搜索仅搜索标题/描述
- 代码搜索需要高级搜索(Elasticsearch)
- 结果仅限于可访问的资源
- 大规模搜索会受到速率限制
Related Documentation
评论
支持 Markdown