AGENT SKILL

github-activity-report

Use when the user asks for GitHub activity stats (PRs authored, commits, top contributors, top repos) across an organization or their personal account over a time window. Iterates per-repo to avoid the search API's 1,000-result cap.

使用场景后端与接口
License 许可
Apache-2.0
最近更新
2026-11-15
Stars
★ 0
Forks
1

01 前言 Front Matter

name
github-activity-report
requires
[ { "cli": "gh", "reason": "GitHub CLI for API operations" } ]
description
Use when the user asks for GitHub activity stats (PRs authored, commits, top contributors, top repos) across an organization or their personal account over a time window. Iterates per-repo to avoid the search API's 1,000-result cap.
user-invocable
true
disable-model-invocation
true

02 资源文件 1

03 SKILL.md 正文

GitHub Activity Report

Codex: Read ../_shared/codex-tools.md before following this skill. Apply its tool, root and dispatch mappings throughout.

Pulls accurate per-org or per-user GitHub activity stats over a chosen time window. Avoids the GitHub search API's 1,000-result pagination cap by iterating each repo's pulls and commits endpoints directly.

Follow ../_shared/orchestration-guide.md §1 for native session allocation and exact-owner cleanup. The repo list, raw JSONL crawl, progress log, and rollup intermediates stay in <scratch>. The finished report defaults to <artifacts>/<scope>-activity-<since>_to_<until>.md; a user-requested external copy is an explicit export that keeps the canonical report and records its actual result in the current session's private receipt. Missing/conflicting/unverified native identity or ordinary-permission denial stops persistence without cwd, operation-ID, Downloads, or OS-temp fallback. The crawl script always requires caller-supplied OUT; pass the exact allocated scratch path.

Reference: crawl.sh — the per-repo crawl script. Run the bundled script from this skill's own directory, never a copy.


What this produces

A markdown report with:

  • Headline totals: PRs authored (open/merged/closed), commits, repos crawled
  • Top PR authors (ranked)
  • Top commit authors (ranked)
  • All repos by PR volume (full long-tail list, not just top 20)
  • All repos by commit volume
  • PRs by repository × top authors (top-N repos cross-tabbed with their #1–#4 authors and share %)
  • Concentration insight: who is #1 in which repos, dominant share (>80%), and which repo patterns exist (solo-driven vs lead-with-team vs multi-contributor)
  • Caveats (search-API cap, identity-string fallback for unattributed commits, bot traffic)

Saved to <artifacts>/<scope>-activity-<since>_to_<until>.md by default. Raw JSONL data remains private in <scratch> while the crawl and requested analysis are active; do not copy it into the durable report or external exports unless the user explicitly requests and approves that data. Before terminal completion, finalize the exact scratch after the crawl exits and report the observed cleanup. An explicit active handoff may retain it only with the exact path and named next owner; unknown/running writers retain it without a cleanup-complete claim.


Procedure

Follow these steps exactly in order.

Step 1: Pick the scope

Check gh auth status first — confirm the user is logged in. Then list the orgs they belong to:

gh api user/orgs --jq '.[].login'
gh api user --jq '.login'

Present an interactive menu with all the user's orgs plus their personal account:

Pick a scope:
  1. <org-1>
  2. <org-2>
  ...
  N. <username> (personal repos)

Wait for the user's pick. Save the chosen scope as SCOPE (the org login or the personal username) and remember whether it's org or user — the API endpoints differ slightly.

Step 2: Pick the window

Default to 6 months back from today (SINCE = today - 6mo, UNTIL = today, both as YYYY-MM-DD). Offer the user a chance to override (e.g., "last 30 days", "2025-01-01 to 2025-06-30", "1 year").

Confirm the resolved dates back to the user before crawling.

Step 3: List repos

For an org:

gh api graphql --paginate -f query='
query($endCursor: String) {
  organization(login: "<SCOPE>") {
    repositories(first: 100, after: $endCursor) {
      pageInfo { hasNextPage endCursor }
      nodes { name isArchived }
    }
  }
}' --jq '.data.organization.repositories.nodes[] | select(.isArchived == false) | .name'

For a personal account (include private repos the user owns, exclude forks unless they ask):

gh api graphql --paginate -f query='
query($endCursor: String) {
  viewer {
    repositories(first: 100, after: $endCursor, ownerAffiliations: OWNER, isFork: false) {
      pageInfo { hasNextPage endCursor }
      nodes { name isArchived }
    }
  }
}' --jq '.data.viewer.repositories.nodes[] | select(.isArchived == false) | .name'

Resolve <scratch> through orchestration-guide §1 and save the repo list to <scratch>/repos.txt. Show the count and ask the user to confirm before crawling (active repos × 2 endpoints × paged calls = potentially hundreds of API calls).

Step 4: Run the crawl

Run the bundled crawl.sh from this skill's own directory, never a copy (<claudna-root> per ../_shared/claudna-root.md). Pass the scratch directory, scope, since and until via env vars:

OUT=<scratch> SCOPE=<scope> SINCE_DATE=<YYYY-MM-DD> UNTIL_DATE=<YYYY-MM-DD> "<claudna-root>/skills/github-activity-report/crawl.sh"

The script writes:

  • <scratch>/prs.jsonl — one PR per line, with repo/user/created/merged/state/number
  • <scratch>/commits.jsonl — one commit per line, with repo/sha/author/date
  • <scratch>/per_repo.tsv — counts per repo
  • <scratch>/crawl.log — progress log

Run it in the background with run_in_background: true and use Monitor to watch progress (see "Monitoring" below). Crawls can take 5–20 minutes depending on org size.

Step 5: Roll up stats

Once the crawl finishes, compute aggregates with jq:

cd <scratch>
echo "PRs total:    $(wc -l < prs.jsonl)"
echo "Commits total: $(wc -l < commits.jsonl)"
echo "Merged PRs:   $(jq -c 'select(.merged != null)' prs.jsonl | wc -l)"
echo "Open PRs:     $(jq -c 'select(.state == "open")' prs.jsonl | wc -l)"

# Top PR authors
jq -r '.user' prs.jsonl | sort | uniq -c | sort -rn | head -25

# Top commit authors
jq -r '.author' commits.jsonl | sort | uniq -c | sort -rn | head -25

# All repos by PRs (full list, not capped — the long tail is informative)
jq -r '.repo' prs.jsonl | sort | uniq -c | sort -rn

# All repos by commits
jq -r '.repo' commits.jsonl | sort | uniq -c | sort -rn

# PRs by repository × top authors (cross-tab for the top 10 repos)
top_repos=$(jq -r '.repo' prs.jsonl | sort | uniq -c | sort -rn | head -10 | awk '{print $2}')
for repo in $top_repos; do
  echo ""
  echo "=== $repo (top 10 authors) ==="
  jq -r --arg r "$repo" 'select(.repo==$r) | .user' prs.jsonl | sort | uniq -c | sort -rn | head -10
done

Step 6: Write the report

Generate <artifacts>/<scope>-activity-<since>_to_<until>.md with:

  • Title, window, generation date, scope, method line
  • Headline totals table
  • Top 25 PR authors table
  • Top 25 commit authors table
  • All repos by PR volume (full list — bold the top 10)
  • All repos by commit volume (full list)
  • PRs by repository × top authors — for the top 10 repos by PR count, show a row per repo with its #1–#4 authors and each author's share of that repo's PRs as a percent. Bold any repo where one author owns >80% of PRs (solo-driven), and bold the dominant author's row for repos where they're #1.
  • Concentration insight — narrative section that names:
    • Which user is #1 by PRs in which repos (count of "#1 spots")
    • Which repos are >80% owned by a single author ("solo-driven")
    • The split between solo-driven, lead-with-team, and multi-contributor repos
    • Where the top user is absent from the top 10 (often equally informative)
  • Caveats section (always include — see template below)

Step 7: Confirm

Tell the user the canonical report path. Offer further slicing before finalizing scratch (e.g., "Show me <user>'s breakdown by repo" or "Strip bots and re-rank"). If an external export was explicitly requested, report its actual path separately; never imply a private raw-data export. On terminal completion report verified scratch cleanup; do not report a deleted raw-data path as a retained deliverable.


Caveats template (always include in the report)

Always include these four caveats verbatim — they're the gotchas that surprised the user the first time and will surprise them again:

## Caveats

- **GitHub search API 1,000-result cap**: A naive `gh api search/issues` query returns accurate `total_count` but only paginates through the first 1,000 hits, so author/repo splits derived from search are biased toward whichever sort order GitHub picked. This report iterates each repo's `pulls` and `commits` endpoints, which have no such cap.
- **Commit authorship attribution**: When a commit's GitHub user can't be resolved (no linked account), we fall back to the raw `commit.author.name` string. That's why the same human can appear under multiple identity strings.
- **Bot traffic**: `dependabot[bot]`, CI bots, and similar automated accounts can dominate the rankings. Strip them if you want a "humans only" view.
- **Non-merge commits**: All commits on default branches (including merge commits) are counted. PR review activity (comments, reviews) is not included.

Monitoring

The crawl prints [N/total] <repo> to stderr per repo. Use Monitor with an until DONE loop to get progress pings every 30s without polling:

until grep -q "^DONE" <scratch>/crawl.log; do
  rows=$(wc -l < <scratch>/per_repo.tsv 2>/dev/null)
  prs=$(wc -l < <scratch>/prs.jsonl 2>/dev/null)
  cms=$(wc -l < <scratch>/commits.jsonl 2>/dev/null)
  last=$(tail -1 <scratch>/crawl.log)
  echo "progress: repos_done=$((rows-1)) prs=$prs commits=$cms last=$last"
  sleep 30
done
echo "DONE"

Anti-patterns

  • Don't trust gh api search/issues author/repo splits. Totals from total_count are correct, but per-author and per-repo breakdowns truncate at 1,000 results. The user has been burned by this — always crawl per-repo for splits.
  • Don't add LOC stats by default. Lines-of-code requires fetching each commit's stats.additions/deletions, which is one API call per commit. For an active org over 6 months that's thousands of requests and hits secondary rate limits. Only attempt if the user explicitly asks and accepts the runtime.
  • Don't forget the --paginate flag on the org-repo listing — orgs with >100 repos will silently truncate without it.
  • Don't hard-code any specific org or user. This skill is generic. Always start with the scope-picker menu.

04 同仓库更多 Skills