feat(repo): 增加 repo +file 读取仓库任意文件能力 #302
Loading…
Reference in New Issue
No description provided.
Delete Branch "Mengz/gitlink-cli:mengz/repo-file-shortcut"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
合并请求描述
当前
gitlink-cli repo已经支持+readme和+tree,但用户想直接读取go.mod、.gitignore、配置文件、脚本或许可证内容时,仍然只能退回 Raw API。open issue #17 里也反映了这个真实使用缺口:用户需要读取仓库内文件做分析,但现有方式不够直接,raw路径还容易返回无意义的 HTML 壳页面。这次新增
repo +file,把“读取仓库任意文件内容”补成高层 Shortcut,基于GET /{owner}/{repo}/sub_entries的文件模式实现,不依赖不稳定的raw路径。命令支持--path指定仓库文件路径,支持--ref读取指定分支、标签或提交,也支持--content-only只输出文件正文,方便脚本和 Agent 直接消费。为了让这个命令在真实使用里更顺手,这次还补了两个边界处理:一是把
--path设为必填,并对空路径或只有/的输入直接报错;二是当用户误把目录传进来时,明确提示改用repo +tree,避免得到难以理解的 API 返回。变更内容
gitlink-cli repo +file--path/-p指定仓库文件路径--ref/-r指定分支、标签或提交,默认master--content-only只输出文件正文--path缺失或无效时直接报错repo +tree--content-only场景下若接口未返回内容,直接报错而不是静默返回空值README.md/README.zh-CN.mdskills/gitlink-repo/SKILL.mdskills/gitlink-repo/references/gitlink-repo-file.mddoc/changes/repo-file-shortcut.md测试与验证
已新增单元测试覆盖默认分支、显式
--ref、路径归一化、帮助参数注册、目录误传报错、--content-only缺少内容报错以及结果扁平化等关键分支。本地验证通过:
另外做了真实命令验证:
能够直接返回
gitlink-cli仓库go.mod的实际内容;当传入目录路径shortcuts时,也会按预期提示改用repo +tree。