github-activity
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub 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.jsonInvocation
调用方式
/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 --reuseContract
契约
- Idempotent: same input produces same output, safe to re-run
- Day-cached: one JSON file per user per day
- : skip fetch if cache exists and is marked complete
--reuse - Rate-limit aware: uses with built-in backoff
gh api --paginate
- 幂等: 相同输入产生相同输出,可安全重复运行
- 按日缓存: 每个用户每天对应一个 JSON 文件
- : 如果缓存存在并标记为已完成,则跳过获取
--reuse - 感知速率限制: 使用带有内置退避机制的
gh api --paginate
Quick Run
快速运行
bash
undefinedbash
undefined1. 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 contains:
activity.jsonjson
{
"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
since GitHub's
GraphQL API returns them as a period summary, not per-day.
~/.cache/recap/github/{user}/commits-{since}-{until}.json每个 包含:
activity.jsonjson
{
"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 }
}
}提交贡献会单独以聚合形式缓存至
,因为 GitHub 的
GraphQL API 返回的是时间范围内的汇总结果,而不是按日结果。
~/.cache/recap/github/{user}/commits-{since}-{until}.jsonArguments
参数
| Argument | Required | Description |
|---|---|---|
| Yes | Start date (YYYY-MM-DD) |
| No | End date (default: today) |
| No | GitHub username (default: authenticated user) |
| No | Filter to a specific GitHub org |
| No | Skip fetch if cache exists and is complete |
| 参数 | 必填 | 说明 |
|---|---|---|
| 是 | 起始日期(YYYY-MM-DD) |
| 否 | 结束日期(默认:今天) |
| 否 | GitHub 用户名(默认:当前已认证用户) |
| 否 | 筛选特定的 GitHub 组织 |
| 否 | 如果缓存存在且已完成,则跳过获取 |
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.jsonPrerequisites
前置条件
- CLI installed and authenticated (
gh)gh auth login - for JSON parsing
jq
- 已安装并认证 CLI(
gh)gh auth login - 使用 解析 JSON
jq
Failure Modes
失败模式
| Symptom | Cause | Fix |
|---|---|---|
| "gh: not logged in" | Token expired | |
| Empty results | No activity in range | Expected — empty days cached as complete |
| Rate limit (403) | Too many API calls | Wait ~1hr and retry |
| >1000 PRs | Search API limit | Narrow date range or add |
| 症状 | 原因 | 修复方式 |
|---|---|---|
| 令牌已过期 | |
| 结果为空 | 范围内没有活动 | 属于预期情况——空日期也会缓存为已完成 |
| 速率限制(403) | API 调用次数过多 | 等待约 1 小时后重试 |
| 超过 1000 个 PR | Search API 限制 | 缩小日期范围或添加 |