# Analytics reference: Workflow Part of the `analytics` skill. Read this only when the task reaches these sections. ## Workflow ### Step 1: Identify User & Scope 1. Call #tool:mcp_github_github_get_me for the authenticated username. 2. Load preferences from `.github/accessibility-agents/preferences.md` (the user creates it from `docs/reference/preferences.example.md`): - If that file does not exist, read `.github/agents/preferences.md` (the older location) and suggest moving it: VS Code loads every `.md` file in `.github/agents/` as a custom agent. - Read `repos.discovery` for the search scope (default: `all` -- search every repo the user can access). - Read `repos.include` for pinned repos, `repos.exclude` for muted repos. - Read `repos.overrides` for per-repo tracking settings and label/path filters. - Read `team` roster and `schedule` for time-aware metrics. - Read `search.default_window` for the default time range (default: 30 days). 3. Detect workspace repos from the current directory. 4. Determine analytics scope: - **"team dashboard"** / no qualifier --> team-wide metrics for last 30 days, all repos - **"my stats"** --> personal metrics for the authenticated user, all repos - **"review turnaround"** --> PR review cycle metrics, all repos - **"velocity"** --> throughput and cycle time trends, all repos - **"bottlenecks"** --> items stuck or overdue, all repos - **"code hotspots"** / **"churn"** --> file-level change frequency - **Specific repo** --> scope to that repo - **"org:orgname"** --> scope to an entire organization - **Date range** --> "last week", "this month", "Q1" 5. When no repo is specified, analytics span ALL repos the user has access to. Use GitHub Search API queries without repo qualifiers to get cross-repo metrics. Group results by repo in the output. ### Step 2: Collect Data ### Progress Announcements Before each data collection step, announce what's happening. After each step, report how much was found. This mirrors the pattern established in the web and document accessibility wizards - always narrate long operations. **Before data collection begins:** ```text Collecting analytics for {scope} ({date range})... ``` **Before each sub-step:** ```text Step 1/5 - Pulling PR metrics for {N} repos... Step 1/5 - 15 merged PRs found, 3 open >7 days Step 2/5 - Pulling issue resolution data... Step 2/5 - 42 issues analyzed Step 3/5 - Building contribution activity table... Step 3/5 - 5 contributors tracked Step 4/5 - Detecting code churn hotspots... Step 4/5 - 8 files changed 5+ times (hotspot threshold) Step 5/5 - Running bottleneck detection... Step 5/5 - 3 bottlenecks found ``` **Before report generation:** ```text Generating analytics document (markdown + HTML)... Analytics complete - report saved. ``` #### 2a: PR Review Metrics - #tool:mcp_github_github_search_pull_requests -- `is:merged` with date range for the target repos. - For each merged PR, note: created date, first review date, approval date, merge date, author, reviewers, number of review rounds. - #tool:mcp_github_github_search_pull_requests -- `is:open` to count current WIP. - Calculate: - **Time to first review** -- PR created --> first review comment or approval - **Time to approval** -- PR created --> final approval - **Time to merge** -- PR created --> merged - **Review rounds** -- number of review/update cycles before merge - **Review load** -- reviews per reviewer per week #### 2b: Issue Resolution Metrics - #tool:mcp_github_github_search_issues -- `is:closed` with date range for target repos. - For each closed issue, note: created date, closed date, comment count, labels, whether it was reopened. - #tool:mcp_github_github_search_issues -- `is:open` for current open count. - Calculate: - **Time to close** -- issue created --> closed - **Comments to resolution** -- average comments before close - **Reopen rate** -- percentage of issues that were reopened - **Label distribution** -- bugs vs features vs tasks - **Response time** -- time to first comment from a maintainer #### 2c: Contribution Activity - #tool:mcp_github_github_search_pull_requests -- `author:USERNAME is:merged` for PRs authored - #tool:mcp_github_github_search_pull_requests -- `reviewed-by:USERNAME` for PRs reviewed - #tool:mcp_github_github_search_issues -- `author:USERNAME is:closed` for issues closed - #tool:mcp_github_github_list_commits -- for commit counts per author - If team roster is available in preferences, collect for each team member. #### 2d: Code Churn - #tool:mcp_github_github_search_pull_requests -- recently merged PRs, then #tool:mcp_github_github_pull_request_read (method: `get_files`) for each. - Count how many times each file was changed across PRs. - Identify hotspots: files changed in 5+ PRs in the period. - Note change coupling: files that are frequently changed together. #### 2e: Bottleneck Detection - #tool:mcp_github_github_search_pull_requests -- `is:open created:<{7-days-ago}` -- PRs open >7 days. - #tool:mcp_github_github_search_issues -- `is:open comments:0 created:<{7-days-ago}` -- issues with no response. - Check review load per person from team roster. - Flag: - PRs waiting >7 days for any review - PRs with review requested but no response in 3+ days - Issues with no maintainer response in 7+ days - Reviewers with >5 pending review requests (overloaded) - Items stuck in project board columns for 7+ days **Confidence levels for bottleneck findings:** Tag every bottleneck with a confidence level. This is a core lesson from accessibility auditing - every finding needs a signal about how certain it is: - **high** - Confirmed by API data (PR open date, zero review comments, zero maintainer responses) - **medium** - Inferred from activity patterns (reviewer load estimate based on last 30 days, stuck board items) - **low** - Possible issue based on heuristics (change coupling suggesting hidden dependency, extrapolated load) Include a `Confidence` column in all bottleneck tables. High-confidence items can be acted on immediately; medium/low items warrant a quick check first. ### Step 3: Calculate & Compare #### Period Comparison When data is available, calculate: - **Week-over-week** -- this week vs. last week - **Month-over-month** -- this month vs. last month - **Vs. team average** -- individual metrics vs. team median #### Delta Tracking Against Previous Reports When a previous analytics report exists in `.github/reviews/analytics/`, automatically compare: 1. **Detect previous report:** Check for `analytics-{previous-date}.md` in `.github/reviews/analytics/`. 2. **Classify changes** (mirrors the accessibility wizard remediation tracking pattern): - **Resolved** - bottleneck existed in previous report but is gone now (PR merged, issue answered) - **New** - bottleneck not in previous report but present now - **Persistent** - bottleneck carried over from previous report (needs escalation signal) - **Improved** - metric trending better than previous period - **Degraded** - metric trending worse than previous period 3. **Progress summary** in the report: ```text Since last report ({previous date}): Resolved: 4 bottlenecks cleared New: 2 new bottlenecks detected Persistent: 1 bottleneck now in its 3rd consecutive report (escalate?) Review Health: 72 -> 85 (+13 points, Improving) ``` 4. **Escalation signal:** If a bottleneck has appeared in 3+ consecutive reports, flag it as `Persistent - escalation recommended`. This delta tracking was one of the most valuable lessons from the accessibility wizard work - a single snapshot is far less useful than trend data across runs. Use directional signals: - Improving -- metric getting better - Stable -- within 10% of previous period - Declining -- metric getting worse #### Health Scores Generate composite health scores (0-100) for: - **Review Health** -- based on turnaround time, review coverage, and bottlenecks - **Issue Health** -- based on resolution time, response time, and backlog size - **Velocity Health** -- based on throughput trends and WIP limits - **Team Balance** -- based on load distribution across team members ### Step 4: Generate Analytics Documents Create BOTH files: - **Markdown:** `.github/reviews/analytics/analytics-{YYYY-MM-DD}.md` - **HTML:** `.github/reviews/analytics/analytics-{YYYY-MM-DD}.html` #### Team Dashboard -- Markdown Template ````markdown # Team Analytics Dashboard -- {Period} > Generated on {date} by Analytics & Insights Agent > Covering: {scope description} > Team: {N members} | Repos: {repo list} --- ## Health Overview | Metric | Score | Trend | Summary | |--------|-------|-------|---------| | Review Health | {0-100} | {Improving/Stable/Declining} | {one-line} | | Issue Health | {0-100} | {Improving/Stable/Declining} | {one-line} | | Velocity | {0-100} | {Improving/Stable/Declining} | {one-line} | | Team Balance | {0-100} | {Improving/Stable/Declining} | {one-line} | --- ## PR Review Turnaround ({count} PRs merged) | Metric | This Period | Last Period | Trend | |--------|------------|-------------|-------| | Time to first review | {hours/days} | {hours/days} | {direction} | | Time to approval | {hours/days} | {hours/days} | {direction} | | Time to merge | {hours/days} | {hours/days} | {direction} | | Review rounds (avg) | {N} | {N} | {direction} | | PRs merged | {count} | {count} | {direction} | ### Review Load Distribution | Reviewer | Reviews Done | Avg Turnaround | Pending | Load Signal | |----------|-------------|----------------|---------|-------------| | @{user} | {count} | {hours/days} | {count} | {Balanced/Heavy/Light} | --- ## Issue Resolution ({count} issues closed) | Metric | This Period | Last Period | Trend | |--------|------------|-------------|-------| | Time to close (avg) | {days} | {days} | {direction} | | Time to first response | {hours} | {hours} | {direction} | | Comments to resolution | {avg} | {avg} | {direction} | | Reopen rate | {%} | {%} | {direction} | | Issues opened | {count} | {count} | {direction} | | Issues closed | {count} | {count} | {direction} | | Net change | {+/-N} | {+/-N} | {direction} | ### Label Distribution | Label | Count | % of Total | |-------|-------|-----------| | bug | {count} | {%} | | feature | {count} | {%} | | enhancement | {count} | {%} | --- ## Contribution Activity | Team Member | PRs Authored | PRs Reviewed | Issues Closed | Commits | Activity | |-------------|-------------|-------------|---------------|---------|----------| | @{user} | {count} | {count} | {count} | {count} | {High/Medium/Low} | --- ## Bottlenecks & Attention Needed ({count} items) ### PRs Waiting for Review ({count} items) | PR | Repo | Author | Waiting | Reviewers Assigned | Signal | |-----|------|--------|---------|-------------------|--------| | [PR #N: Title](url) | repo | @author | {days} | @reviewer | Overdue -- no review in 7+ days | ### Issues Without Response ({count} items) | Issue | Repo | Author | Waiting | Labels | Signal | |-------|------|--------|---------|--------|--------| | [Issue #N: Title](url) | repo | @author | {days} | `bug` | No maintainer response | ### Overloaded Reviewers | Reviewer | Pending Reviews | Avg Turnaround | Recommendation | |----------|----------------|----------------|----------------| | @{user} | {count} | {days} | Redistribute {N} reviews to @{other} | --- ## Code Churn & Hotspots ({count} files analyzed) ### Most Changed Files | File | Times Changed | PRs | Total Lines | Risk | |------|--------------|-----|-------------|------| | [`path/to/file.ts`](url) | {count} | {PR list} | +{add}/-{del} | High churn -- consider refactoring | ### Change Coupling Files frequently changed together (may indicate hidden dependencies): | File A | File B | Co-changed | Times | |--------|--------|-----------|-------| | `auth.ts` | `auth.test.ts` | Expected | {N} | | `api.ts` | `utils.ts` | Investigate | {N} | --- ## Trends & Insights ### What's Going Well - {e.g., "Review turnaround improved 20% this month"} - {e.g., "Issue backlog shrinking -- 5 fewer open issues than last month"} ### Areas for Improvement - {e.g., "3 PRs have been waiting for review >7 days"} - {e.g., "@charlie has 8 pending reviews -- consider redistributing"} ### Recommendations 1. {Specific actionable recommendation} 2. {Second recommendation} 3. {Third recommendation} --- ## My Notes ```` #### Personal Stats -- Markdown Template ````markdown # My GitHub Stats -- {Period} > Generated on {date} for @{username} > Covering: {scope description} --- ## Summary | Metric | This Period | Last Period | Trend | |--------|------------|-------------|-------| | PRs authored | {count} | {count} | {direction} | | PRs merged | {count} | {count} | {direction} | | PRs reviewed | {count} | {count} | {direction} | | Issues opened | {count} | {count} | {direction} | | Issues closed | {count} | {count} | {direction} | | Commits | {count} | {count} | {direction} | | Avg review turnaround | {hours} | {hours} | {direction} | | Avg PR merge time | {days} | {days} | {direction} | --- ## Your PRs -- Performance | PR | Repo | Created | First Review | Merged | Cycle Time | |-----|------|---------|-------------|--------|-----------| | [PR #N: Title](url) | repo | {date} | {date} | {date} | {days} | **Average cycle time:** {days} ({better/worse} than team avg of {days}) --- ## Your Reviews -- Impact | PR | Repo | Author | Review Date | Turnaround | Result | |-----|------|--------|------------|------------|--------| | [PR #N: Title](url) | repo | @author | {date} | {hours} | Approved/Changes Requested | **Average review turnaround:** {hours} (team avg: {hours}) --- ## Your Issues -- Resolution | Issue | Repo | Opened | Closed | Time | Comments | |-------|------|--------|--------|------|----------| | [Issue #N: Title](url) | repo | {date} | {date} | {days} | {count} | --- ## Comparison vs. Team | Metric | You | Team Avg | Team Median | Percentile | |--------|-----|----------|-------------|-----------| | PRs merged/week | {N} | {N} | {N} | {Nth percentile} | | Review turnaround | {hours} | {hours} | {hours} | {Nth percentile} | | Issue resolution | {days} | {days} | {days} | {Nth percentile} | --- ## Insights - {e.g., "You're in the top 25% for review turnaround -- keep it up"} - {e.g., "Your PR merge time increased 15% -- 2 PRs waited for reviewer assignment"} - {e.g., "Consider reviewing more in frontend/ -- the team needs help there"} ```` #### HTML Template Generate the HTML version following the shared HTML standards from shared-instructions.md. The HTML template MUST include: - Skip link, header with generation metadata, nav with section links - `
` landmarks with `aria-labelledby` for each analytics category - Tables with ``, ``, and `` where applicable - Trend indicators using text labels (not just arrows or colors): "Improving", "Stable", "Declining" - Health scores with color and text: `85 -- Healthy` - Bottleneck items with action-level styling - `