Merge pull request #382: feat(repo): add +activity for project trends
# Conflicts: # internal/i18n/locales/en-US.json # internal/i18n/locales/zh-CN.json # shortcuts/repo/repo_test.go
This commit is contained in:
commit
0771d4658f
|
|
@ -236,6 +236,9 @@ gitlink-cli repo +languages --owner Gitlink --repo forgeplus
|
|||
# List contributors
|
||||
gitlink-cli repo +contributors --owner Gitlink --repo forgeplus
|
||||
|
||||
# Repository activity feed, filterable by type/action/time window
|
||||
gitlink-cli repo +activity --owner Gitlink --repo forgeplus -t Issue -s close --time 30
|
||||
|
||||
# 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
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@
|
|||
"cmd.dataset.view.short": "View a repository's dataset",
|
||||
"cmd.doctor.long": "Run local diagnostics for gitlink-cli configuration, authentication, repository context and API connectivity.",
|
||||
"cmd.doctor.short": "Diagnose gitlink-cli environment problems",
|
||||
"cmd.ignore.short": "Ignore-file template operations",
|
||||
"cmd.issue.batch_close.long": "Close filtered issues in bulk.\n\nThis command defaults to dry-run mode and only prints matching issues.\nPass --yes to execute remote close operations. Use restrictive filters and a small limit.\n\nExamples:\n gitlink-cli issue +batch-close --owner Gitlink --repo gitlink-cli --older-than-days 60 --limit 20\n gitlink-cli issue +batch-close --owner Gitlink --repo gitlink-cli --older-than-days 60 --limit 20 --yes",
|
||||
"cmd.issue.batch_close.short": "Close filtered issues in bulk. Defaults to dry-run; pass --yes to execute.",
|
||||
"cmd.issue.batch_label.long": "Add a label to filtered issues in bulk.\n\nThis command defaults to dry-run mode and only prints matching issues.\nPass --yes to execute remote label operations. The current implementation does not fake label writes when the API endpoint is unavailable.\n\nExamples:\n gitlink-cli issue +batch-label --owner Gitlink --repo gitlink-cli --add-label stale --older-than-days 30 --limit 50\n gitlink-cli issue +batch-label --owner Gitlink --repo gitlink-cli --add-label stale --older-than-days 30 --limit 50 --yes",
|
||||
|
|
@ -82,16 +81,13 @@
|
|||
"cmd.release.list.short": "List releases",
|
||||
"cmd.release.short": "Release operations",
|
||||
"cmd.release.view.short": "View release details",
|
||||
"cmd.repo.blame.short": "Show line-by-line blame for a file",
|
||||
"cmd.repo.activity.short": "List repository activity feed (project trends)",
|
||||
"cmd.repo.create.short": "Create a new repository",
|
||||
"cmd.repo.delete.short": "Delete a repository",
|
||||
"cmd.repo.fork.short": "Fork a 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.topic_add.short": "Attach a topic to the repository",
|
||||
"cmd.repo.topic_remove.short": "Detach a topic from the repository",
|
||||
"cmd.repo.topics.short": "List project topics (searchable)",
|
||||
"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",
|
||||
|
|
@ -213,15 +209,13 @@
|
|||
"flag.release.tag": "Tag name",
|
||||
"flag.release.target": "Target branch",
|
||||
"flag.repo": "Repository name (auto-detected from git remote)",
|
||||
"flag.repo.blame.path": "File path to blame",
|
||||
"flag.repo.activity.status": "Action filter: create, close, journal",
|
||||
"flag.repo.activity.time": "Only include events from the past N days",
|
||||
"flag.repo.activity.type": "Trend type filter: Issue, PullRequest, Version",
|
||||
"flag.repo.category": "Filter: manage/mirror/sync/fork/all (default: manage)",
|
||||
"flag.repo.description": "Repository description",
|
||||
"flag.repo.name": "Repository name",
|
||||
"flag.repo.private": "Make repository private (true/false)",
|
||||
"flag.repo.project_id": "GitLink project ID. If omitted, resolved from --owner/--repo.",
|
||||
"flag.repo.topic.id": "Topic ID from repo +topics",
|
||||
"flag.repo.topic.name": "Topic name",
|
||||
"flag.repo.topics.keyword": "Filter topics by name keyword",
|
||||
"flag.repo.tree.path": "Directory path to list (default: repository root)",
|
||||
"flag.repo.tree.ref": "Branch, tag, or commit ref",
|
||||
"flag.search.keyword": "Search keyword",
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@
|
|||
"cmd.dataset.view.short": "查看仓库数据集",
|
||||
"cmd.doctor.long": "诊断 gitlink-cli 的配置、认证、仓库上下文和 API 连通性问题。",
|
||||
"cmd.doctor.short": "诊断 gitlink-cli 环境问题",
|
||||
"cmd.ignore.short": "忽略文件模板操作",
|
||||
"cmd.issue.batch_close.long": "批量关闭筛选后的议题。\n\n该命令默认处于 dry-run 模式,只打印匹配的议题。\n传入 --yes 后执行远端关闭操作。请使用严格筛选条件和较小 limit。\n\n示例:\n gitlink-cli issue +batch-close --owner Gitlink --repo gitlink-cli --older-than-days 60 --limit 20\n gitlink-cli issue +batch-close --owner Gitlink --repo gitlink-cli --older-than-days 60 --limit 20 --yes",
|
||||
"cmd.issue.batch_close.short": "批量关闭筛选后的议题。默认 dry-run;传入 --yes 后执行。",
|
||||
"cmd.issue.batch_label.long": "给筛选后的议题批量添加标签。\n\n该命令默认处于 dry-run 模式,只打印匹配的议题。\n传入 --yes 后执行远端标签操作。当前实现不会在 API 端点不可用时伪造写入结果。\n\n示例:\n gitlink-cli issue +batch-label --owner Gitlink --repo gitlink-cli --add-label stale --older-than-days 30 --limit 50\n gitlink-cli issue +batch-label --owner Gitlink --repo gitlink-cli --add-label stale --older-than-days 30 --limit 50 --yes",
|
||||
|
|
@ -82,16 +81,13 @@
|
|||
"cmd.release.list.short": "列出发布",
|
||||
"cmd.release.short": "发布操作",
|
||||
"cmd.release.view.short": "查看发布详情",
|
||||
"cmd.repo.blame.short": "逐行显示文件的 blame 信息",
|
||||
"cmd.repo.activity.short": "列出仓库动态(project trends)",
|
||||
"cmd.repo.create.short": "创建新仓库",
|
||||
"cmd.repo.delete.short": "删除仓库",
|
||||
"cmd.repo.fork.short": "Fork 仓库",
|
||||
"cmd.repo.info.short": "显示仓库详情",
|
||||
"cmd.repo.list.short": "列出用户或组织的仓库",
|
||||
"cmd.repo.short": "仓库操作",
|
||||
"cmd.repo.topic_add.short": "为仓库添加主题标签",
|
||||
"cmd.repo.topic_remove.short": "移除仓库的主题标签",
|
||||
"cmd.repo.topics.short": "列出项目主题标签(可搜索)",
|
||||
"cmd.repo.tree.short": "列出仓库文件和目录",
|
||||
"cmd.root.long": "用于管理 GitLink 上的仓库、议题、拉取请求、发布、CI 和工作流。",
|
||||
"cmd.root.short": "GitLink CLI - GitLink 命令行工具",
|
||||
|
|
@ -213,15 +209,13 @@
|
|||
"flag.release.tag": "标签名称",
|
||||
"flag.release.target": "目标分支",
|
||||
"flag.repo": "仓库名称(自动从 git remote 检测)",
|
||||
"flag.repo.blame.path": "要 blame 的文件路径",
|
||||
"flag.repo.activity.status": "动作过滤:create、close、journal",
|
||||
"flag.repo.activity.time": "仅包含最近 N 天的动态",
|
||||
"flag.repo.activity.type": "动态类型过滤:Issue、PullRequest、Version",
|
||||
"flag.repo.category": "筛选:manage/mirror/sync/fork/all(默认:manage)",
|
||||
"flag.repo.description": "仓库描述",
|
||||
"flag.repo.name": "仓库名称",
|
||||
"flag.repo.private": "设为私有仓库(true/false)",
|
||||
"flag.repo.project_id": "GitLink 项目 ID;省略时自动从 --owner/--repo 解析",
|
||||
"flag.repo.topic.id": "主题 ID(来自 repo +topics)",
|
||||
"flag.repo.topic.name": "主题名称",
|
||||
"flag.repo.topics.keyword": "按名称关键字过滤主题",
|
||||
"flag.repo.tree.path": "要列出的目录路径(默认:仓库根目录)",
|
||||
"flag.repo.tree.ref": "分支、标签或提交引用",
|
||||
"flag.search.keyword": "搜索关键词",
|
||||
|
|
|
|||
|
|
@ -147,6 +147,42 @@ func Shortcuts(translators ...*i18n.Translator) []*common.Shortcut {
|
|||
Description: "List repository contributors",
|
||||
Run: runContributors,
|
||||
},
|
||||
{
|
||||
Name: "activity",
|
||||
Description: tr.T("cmd.repo.activity.short"),
|
||||
Flags: []common.Flag{
|
||||
{Name: "type", Short: "t", Usage: tr.T("flag.repo.activity.type")},
|
||||
{Name: "status", Short: "s", Usage: tr.T("flag.repo.activity.status")},
|
||||
{Name: "time", Usage: tr.T("flag.repo.activity.time")},
|
||||
{Name: "page", Short: "p", Usage: tr.T("flag.page"), Default: "1"},
|
||||
{Name: "limit", Short: "l", Usage: tr.T("flag.limit"), Default: "20"},
|
||||
},
|
||||
Run: func(ctx *common.RuntimeContext) error {
|
||||
if err := ctx.ResolveOwnerRepo(); err != nil {
|
||||
return err
|
||||
}
|
||||
q := url.Values{}
|
||||
q.Set("page", ctx.Arg("page"))
|
||||
q.Set("limit", ctx.Arg("limit"))
|
||||
if trendType := ctx.Arg("type"); trendType != "" {
|
||||
q.Set("type", trendType)
|
||||
}
|
||||
if status := ctx.Arg("status"); status != "" {
|
||||
q.Set("status", status)
|
||||
}
|
||||
if timeDays := ctx.Arg("time"); timeDays != "" {
|
||||
if _, err := strconv.Atoi(timeDays); err != nil {
|
||||
return fmt.Errorf("--time must be an integer number of days, got %q", timeDays)
|
||||
}
|
||||
q.Set("time", timeDays)
|
||||
}
|
||||
env, err := ctx.CallAPIWithQuery("GET", ctx.RepoPath()+"/activity", q)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ctx.Output(env)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "contributor-stats",
|
||||
Description: "List contributor statistics with code line counts",
|
||||
|
|
|
|||
|
|
@ -636,34 +636,28 @@ func assertEqual(t *testing.T, got interface{}, want interface{}) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRepoBlameUsesBlameEndpoint(t *testing.T) {
|
||||
func TestRepoActivityForwardsFilters(t *testing.T) {
|
||||
var query string
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "GET" || r.URL.Path != "/v1/owner/repo/blame.json" {
|
||||
if r.Method != "GET" || r.URL.Path != "/owner/repo/activity.json" {
|
||||
t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
query = r.URL.RawQuery
|
||||
writeJSON(t, w, map[string]interface{}{"file_name": "README.md", "blame_parts": []interface{}{}})
|
||||
writeJSON(t, w, map[string]interface{}{"project_trends": []interface{}{}})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
err := runShortcut(t, server, "blame", map[string]string{"path": "README.md", "ref": "develop"})
|
||||
if err != nil {
|
||||
t.Fatalf("blame failed: %v", err)
|
||||
args := map[string]string{"type": "Issue", "status": "create", "time": "30", "page": "1", "limit": "20"}
|
||||
if err := runShortcut(t, server, "activity", args); err != nil {
|
||||
t.Fatalf("activity failed: %v", err)
|
||||
}
|
||||
if !strings.Contains(query, "filepath=README.md") || !strings.Contains(query, "sha=develop") {
|
||||
t.Fatalf("unexpected query: %q", query)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepoBlameRequiresPath(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
err := runShortcut(t, server, "blame", map[string]string{})
|
||||
if err == nil {
|
||||
t.Fatal("expected error when --path missing")
|
||||
for _, want := range []string{"type=Issue", "status=create", "time=30"} {
|
||||
if !strings.Contains(query, want) {
|
||||
t.Fatalf("expected %q in query, got %q", want, query)
|
||||
}
|
||||
}
|
||||
|
||||
if err := runShortcut(t, server, "activity", map[string]string{"time": "abc", "page": "1", "limit": "20"}); err == nil {
|
||||
t.Fatal("expected error for non-integer --time")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue