From b19d45fc6f65e721fdd27c12e396eaf5a8e0383f Mon Sep 17 00:00:00 2001 From: 1os21ka23r9navae6mrro <1os21ka23r9navae6mrro@gmail.com> Date: Wed, 8 Jul 2026 14:24:59 +0000 Subject: [PATCH] feat(repo): add +forks and +top-counts - repo +forks: list users who forked the repository (GET /forks, same community time-range flags as +watchers/+stargazers) - repo +top-counts: repository top-line counts (tags, branches, commits, releases, size) via GET /top_counts Production-verified on gitlink.org.cn (77 forks on a large repo; counts payload matches web overview). 2 unit tests, README examples, and bilingual i18n keys. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- README.md | 6 ++++++ internal/i18n/locales/en-US.json | 2 ++ internal/i18n/locales/zh-CN.json | 2 ++ shortcuts/repo/repo.go | 22 ++++++++++++++++++++++ shortcuts/repo/repo_test.go | 28 ++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+) diff --git a/README.md b/README.md index e5e4318..60107af 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,12 @@ gitlink-cli repo +languages --owner Gitlink --repo forgeplus # List contributors gitlink-cli repo +contributors --owner Gitlink --repo forgeplus +# List users who forked the repository +gitlink-cli repo +forks --owner Gitlink --repo forgeplus + +# Top-line counts (tags, branches, commits, releases, size) +gitlink-cli repo +top-counts --owner Gitlink --repo forgeplus + # Show contributor code-line stats for a branch, tag, or commit gitlink-cli repo +contributor-stats --owner Gitlink --repo forgeplus --ref master --pass-year 1 diff --git a/internal/i18n/locales/en-US.json b/internal/i18n/locales/en-US.json index 0739395..a9240ef 100644 --- a/internal/i18n/locales/en-US.json +++ b/internal/i18n/locales/en-US.json @@ -84,9 +84,11 @@ "cmd.repo.create.short": "Create a new repository", "cmd.repo.delete.short": "Delete a repository", "cmd.repo.fork.short": "Fork a repository", + "cmd.repo.forks.short": "List users who forked the repository", "cmd.repo.info.short": "Show repository details", "cmd.repo.list.short": "List repositories for a user or organization", "cmd.repo.short": "Repository operations", + "cmd.repo.top_counts.short": "Show repository top-line counts (tags, branches, commits, releases, size)", "cmd.repo.tree.short": "List repository files and directories", "cmd.root.long": "Manage repositories, issues, pull requests, releases, CI and workflows on GitLink.", "cmd.root.short": "GitLink CLI - command-line tool for GitLink", diff --git a/internal/i18n/locales/zh-CN.json b/internal/i18n/locales/zh-CN.json index 2e6fc4d..cee191e 100644 --- a/internal/i18n/locales/zh-CN.json +++ b/internal/i18n/locales/zh-CN.json @@ -84,9 +84,11 @@ "cmd.repo.create.short": "创建新仓库", "cmd.repo.delete.short": "删除仓库", "cmd.repo.fork.short": "Fork 仓库", + "cmd.repo.forks.short": "列出 fork 该仓库的用户", "cmd.repo.info.short": "显示仓库详情", "cmd.repo.list.short": "列出用户或组织的仓库", "cmd.repo.short": "仓库操作", + "cmd.repo.top_counts.short": "显示仓库概览计数(标签/分支/提交/发行版/体积)", "cmd.repo.tree.short": "列出仓库文件和目录", "cmd.root.long": "用于管理 GitLink 上的仓库、议题、拉取请求、发布、CI 和工作流。", "cmd.root.short": "GitLink CLI - GitLink 命令行工具", diff --git a/shortcuts/repo/repo.go b/shortcuts/repo/repo.go index 06774a6..53f0b39 100644 --- a/shortcuts/repo/repo.go +++ b/shortcuts/repo/repo.go @@ -151,6 +151,28 @@ func Shortcuts(translators ...*i18n.Translator) []*common.Shortcut { return runCommunityList(ctx, "stargazers") }, }, + { + Name: "forks", + Description: tr.T("cmd.repo.forks.short"), + Flags: communityListFlags(), + Run: func(ctx *common.RuntimeContext) error { + return runCommunityList(ctx, "forks") + }, + }, + { + Name: "top-counts", + Description: tr.T("cmd.repo.top_counts.short"), + Run: func(ctx *common.RuntimeContext) error { + if err := ctx.ResolveOwnerRepo(); err != nil { + return err + } + env, err := ctx.CallAPI("GET", ctx.RepoPath()+"/top_counts", nil) + if err != nil { + return err + } + return ctx.Output(env) + }, + }, { Name: "follow", Description: "Follow a repository", diff --git a/shortcuts/repo/repo_test.go b/shortcuts/repo/repo_test.go index 5c5f34b..5bef25c 100644 --- a/shortcuts/repo/repo_test.go +++ b/shortcuts/repo/repo_test.go @@ -634,3 +634,31 @@ func assertEqual(t *testing.T, got interface{}, want interface{}) { t.Fatalf("got %v (%T), want %v (%T)", got, got, want, want) } } + +func TestRepoForksListsForkUsers(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" || r.URL.Path != "/owner/repo/forks.json" { + t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path) + } + writeJSON(t, w, map[string]interface{}{"count": 0, "users": []interface{}{}}) + })) + defer server.Close() + + if err := runShortcut(t, server, "forks", map[string]string{}); err != nil { + t.Fatalf("forks failed: %v", err) + } +} + +func TestRepoTopCountsUsesTopCountsEndpoint(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" || r.URL.Path != "/owner/repo/top_counts.json" { + t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path) + } + writeJSON(t, w, map[string]interface{}{"tags_count": float64(1)}) + })) + defer server.Close() + + if err := runShortcut(t, server, "top-counts", map[string]string{}); err != nil { + t.Fatalf("top-counts failed: %v", err) + } +}