github-activity

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub Activity Fetcher

GitHub 活动获取器

Fetch GitHub activity — PRs authored, PRs reviewed, issues created, commit contributions — into per-day cached JSON atoms at
~/.cache/recap/github/{user}/{YYYY-MM-DD}/activity.json
.
将 GitHub 活动——创建的 PR、评审的 PR、创建的 Issue、提交贡献——获取到按日缓存的 JSON 数据单元中,存储路径为
~/.cache/recap/github/{user}/{YYYY-MM-DD}/activity.json
。

Invocation

调用方式

/recap:github-activity --since 2026-03-23
/recap:github-activity --since 2026-03-23 --until 2026-03-30
/recap:github-activity --user jeremy --org basecamp --since 2026-03-23 --reuse
/recap:github-activity --since 2026-03-23
/recap:github-activity --since 2026-03-23 --until 2026-03-30
/recap:github-activity --user jeremy --org basecamp --since 2026-03-23 --reuse

Contract

契约

  • Idempotent: same input produces same output, safe to re-run
  • Day-cached: one JSON file per user per day
  • --reuse
    :
    skip fetch if cache exists and is marked complete
  • Rate-limit aware: uses
    gh api --paginate
    with built-in backoff
  • 幂等: 相同输入产生相同输出,可安全重复运行
  • 按日缓存: 每个用户每天对应一个 JSON 文件
  • --reuse
    :
    如果缓存存在并标记为已完成,则跳过获取
  • 感知速率限制: 使用带有内置退避机制的
    gh api --paginate

Quick Run

快速运行

bash
undefined
bash
undefined

1. Validate auth

1. Validate auth

gh auth status || { echo "Run: gh auth login"; exit 1; }
gh auth status || { echo "Run: gh auth login"; exit 1; }

2. Determine date range

2. Determine date range

SINCE=$(date -d "7 days ago" +%Y-%m-%d) UNTIL=$(date +%Y-%m-%d)
SINCE=$(date -d "7 days ago" +%Y-%m-%d) UNTIL=$(date +%Y-%m-%d)

3. Run the fetcher

3. Run the fetcher

"$SKILL_DIR/scripts/github-activity.sh" --since "$SINCE" --until "$UNTIL"
"$SKILL_DIR/scripts/github-activity.sh" --since "$SINCE" --until "$UNTIL"

4. Verify cache

4. Verify cache

USER=$(gh api user --jq '.login') ls ~/.cache/recap/github/$USER/ cat ~/.cache/recap/github/$USER/$SINCE/activity.json | jq '.metadata'

Where `$SKILL_DIR` = directory containing this SKILL.md.
USER=$(gh api user --jq '.login') ls ~/.cache/recap/github/$USER/ cat ~/.cache/recap/github/$USER/$SINCE/activity.json | jq '.metadata'

其中,`$SKILL_DIR` 是包含此 SKILL.md 的目录。

Output Format

输出格式

Each
activity.json
contains:
json
{
  "user": "jeremy",
  "date": "2026-03-24",
  "prs_authored": [
    {
      "title": "Add weekly digest skill",
      "html_url": "https://github.com/basecamp/coworker/pull/99",
      "created_at": "2026-03-24T14:30:00Z",
      "repository_url": "https://api.github.com/repos/basecamp/coworker",
      "state": "closed",
      "pull_request": { "merged_at": "2026-03-24T15:00:00Z" }
    }
  ],
  "prs_reviewed": [],
  "issues": [],
  "metadata": {
    "complete": true,
    "counts": { "prs_authored": 1, "prs_reviewed": 0, "issues": 0 }
  }
}
Commit contributions are cached separately as an aggregate at
~/.cache/recap/github/{user}/commits-{since}-{until}.json
since GitHub's GraphQL API returns them as a period summary, not per-day.
每个
activity.json
包含:
json
{
  "user": "jeremy",
  "date": "2026-03-24",
  "prs_authored": [
    {
      "title": "Add weekly digest skill",
      "html_url": "https://github.com/basecamp/coworker/pull/99",
      "created_at": "2026-03-24T14:30:00Z",
      "repository_url": "https://api.github.com/repos/basecamp/coworker",
      "state": "closed",
      "pull_request": { "merged_at": "2026-03-24T15:00:00Z" }
    }
  ],
  "prs_reviewed": [],
  "issues": [],
  "metadata": {
    "complete": true,
    "counts": { "prs_authored": 1, "prs_reviewed": 0, "issues": 0 }
  }
}
提交贡献会单独以聚合形式缓存至
~/.cache/recap/github/{user}/commits-{since}-{until}.json
,因为 GitHub 的 GraphQL API 返回的是时间范围内的汇总结果,而不是按日结果。

Arguments

参数

ArgumentRequiredDescription
--since
YesStart date (YYYY-MM-DD)
--until
NoEnd date (default: today)
--user
NoGitHub username (default: authenticated user)
--org
NoFilter to a specific GitHub org
--reuse
NoSkip fetch if cache exists and is complete
参数必填说明
--since
是起始日期(YYYY-MM-DD)
--until
否结束日期(默认:今天)
--user
否GitHub 用户名(默认:当前已认证用户)
--org
否筛选特定的 GitHub 组织
--reuse
否如果缓存存在且已完成,则跳过获取

Cache Structure

缓存结构

~/.cache/recap/github/
  jeremy/
    2026-03-24/activity.json
    2026-03-25/activity.json
    commits-2026-03-23-2026-03-30.json
~/.cache/recap/github/
  jeremy/
    2026-03-24/activity.json
    2026-03-25/activity.json
    commits-2026-03-23-2026-03-30.json

Prerequisites

前置条件

  • gh
    CLI installed and authenticated (
    gh auth login
    )
  • jq
    for JSON parsing
  • 已安装并认证
    gh
    CLI(
    gh auth login
    )
  • 使用
    jq
    解析 JSON

Failure Modes

失败模式

SymptomCauseFix
"gh: not logged in"Token expired
gh auth login
Empty resultsNo activity in rangeExpected — empty days cached as complete
Rate limit (403)Too many API callsWait ~1hr and retry
>1000 PRsSearch API limitNarrow date range or add
--org
filter
症状原因修复方式
"gh: not logged in"
令牌已过期
gh auth login
结果为空范围内没有活动属于预期情况——空日期也会缓存为已完成
速率限制(403)API 调用次数过多等待约 1 小时后重试
超过 1000 个 PRSearch API 限制缩小日期范围或添加
--org
过滤器