skills/platform-eaglelab.tcl.com/gitlab-remote-search

gitlab-remote-search

SKILL.md

GitLab Remote Code Search Skill

通过 GitLab API 远程搜索代码仓库,无需克隆到本地。支持搜索关键字、文件类型过滤、多仓库批量搜索。

使用场景

  • 搜索某个接口在哪些服务中有调用
  • 查找某个模板/URL 是否在代码中使用
  • 快速定位代码位置,无需下载整个仓库

前置条件

1. GitLab Token

需要 GitLab Personal Access Token,权限要求:

  • read_api - 读取 API
  • read_repository - 读取仓库

获取方式:

  1. 访问 GitLab → Settings → Access Tokens
  2. 创建新 token,勾选上述权限
  3. 保存 token(只显示一次)

2. 配置 Token

TOOLS.md 中添加:

### GitLab

- Token: `glpat-xxxxxxxxxxxx`
- Base URL: `https://eaglelab-gitlab.tcljd.com`

或在执行时通过环境变量传入:

export GITLAB_TOKEN="glpat-xxxxxxxxxxxx"

使用方法

基本搜索

cd ~/.openclaw/workspace/skills/gitlab-remote-search
python gitlab-search.py --search "keyword" --repos "repo1,repo2,repo3"

完整参数

python gitlab-search.py \
  --search "statis-operation-calc" \
  --repos "iot3.1/ac-common-service,iot3.1/iot-device-service" \
  --extension ".java" \
  --ref "release" \
  --output "results.txt"

参数说明

参数 必填 说明
--search 搜索关键字
--repos 仓库列表(逗号分隔,格式:group/project)
--extension 文件扩展名过滤(如 .java, .py, .js
--ref 分支/标签名,默认 release
--output 输出文件路径,默认打印到终端
--token GitLab Token(也可用环境变量 GITLAB_TOKEN
--base-url GitLab 基础 URL,默认 https://eaglelab-gitlab.tcljd.com

输出格式

========================================
Repository: cloudplatform/business/official/iot3.1/ac-common-service
File: src/main/java/com/tcl/iot/service/ExampleService.java
Line: 45
URL: https://eaglelab-gitlab.tcljd.com/cloudplatform/business/official/iot3.1/ac-common-service/-/blob/release/src/main/java/...#L45
----------------------------------------
[代码片段预览]
========================================

示例

搜索 Java 代码中的关键字

python gitlab-search.py \
  --search "getUserInfo" \
  --repos "iot3.1/ac-common-service,iot3.1/iot-user-service" \
  --extension ".java" \
  --ref "release"

搜索所有文件类型

python gitlab-search.py \
  --search "TODO" \
  --repos "iot3.1/*" \
  --ref "main"

导出结果到文件

python gitlab-search.py \
  --search "statis-operation-calc" \
  --repos "iot3.1/*" \
  --output "search-results.txt"

注意事项

  1. API 速率限制:GitLab API 有速率限制,大量搜索时注意间隔
  2. Token 安全:不要将 token 提交到代码仓库
  3. 仓库路径格式:使用 group/subgroup/project 格式,不需要 .git 后缀
  4. 通配符支持:可以用 * 匹配多个仓库(需要额外处理)

故障排查

401 Unauthorized

  • Token 无效或过期
  • Token 权限不足

404 Not Found

  • 仓库路径错误
  • Token 没有该仓库的访问权限

搜索结果为空

  • 关键字拼写错误
  • 分支名称错误
  • 文件类型过滤太严格

文件结构

gitlab-remote-search/
├── SKILL.md              # 技能说明文档
├── gitlab-search.py      # 主搜索脚本
├── repos.txt             # 仓库列表文件(可选)
└── requirements.txt      # Python 依赖
Installs
4
First Seen
Mar 30, 2026