Skip to content

Commit 93a2ead

Browse files
committed
feat(cli): add weekly PR report generation capability
Add comprehensive weekly PR report generation for HyperShift project with automated Jira hierarchy enrichment and markdown link generation. Features: - Fast async PR fetching using GitHub GraphQL API - Automatic Jira ticket extraction from PR titles and bodies - Complete Jira hierarchy (Ticket → Epic → OCPSTRAT) with parallel queries - PR grouping by OCPSTRAT strategic initiatives - Timing metrics (draft→ready, ready→merge) and review activity analysis - Clickable markdown links for all PRs and Jira tickets - Claude Code slash command: /weekly-pr-report [since-date] Files added: - contrib/repo_metrics/weekly_pr_report.py: Report generator with async API calls - .claude/commands/weekly-pr-report.md: Slash command for Claude Code - contrib/repo_metrics/README.md: Documentation updated Signed-off-by: Antoni Segura Puimedon <[email protected]> Commit-Message-Assisted-by: Claude (via Claude Code)
1 parent 67d57cf commit 93a2ead

File tree

3 files changed

+850
-0
lines changed

3 files changed

+850
-0
lines changed
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
---
2+
arguments: <since-date>
3+
---
4+
5+
# Weekly PR Report Generator
6+
7+
Generate a comprehensive weekly PR report for openshift/hypershift and openshift-eng/ai-helpers repositories.
8+
9+
## Usage
10+
11+
```
12+
/weekly-pr-report [since-date]
13+
```
14+
15+
**Parameters:**
16+
17+
- `since-date` (optional): Starting date in YYYY-MM-DD format. Defaults to 7 days ago.
18+
19+
## What This Command Does
20+
21+
1. **Fetch repository contributors** from openshift/hypershift (all 194 contributors)
22+
2. **Fetch merged PRs** from both repositories since the specified date using GitHub GraphQL API
23+
3. **Filter openshift/ai-helpers PRs** to only include those authored by HyperShift contributors
24+
4. **Query Jira** for each ticket to find Epic and Parent links to OCPSTRAT issues
25+
5. **Gather detailed PR metadata**:
26+
- Author, reviewers, and approvers
27+
- Draft status and timeline (when moved from draft to ready)
28+
- Time from creation to ready
29+
- Time from ready to merge
30+
6. **Generate comprehensive report** including:
31+
- PR topic and summary
32+
- Jira ticket hierarchy (ticket → Epic → OCPSTRAT)
33+
- Review and approval activity
34+
- Timing metrics
35+
- OCPSTRAT groupings
36+
- Auto-generated impact statements
37+
38+
## Output
39+
40+
The command creates:
41+
42+
- `/tmp/weekly_pr_report_fast.md` - Comprehensive markdown report
43+
- `/tmp/hypershift_pr_details_fast.json` - Raw PR data in JSON format
44+
45+
## Example Usage
46+
47+
```bash
48+
# Report for last week (default)
49+
/weekly-pr-report
50+
51+
# Report since specific date
52+
/weekly-pr-report 2025-11-06
53+
```
54+
55+
## Expected Output Format
56+
57+
The generated markdown report (`/tmp/weekly_pr_report_fast.md`) should follow this structure:
58+
59+
```markdown
60+
# Weekly PR Report: YYYY-MM-DD to YYYY-MM-DD
61+
62+
## Summary
63+
64+
- **Total PRs merged**: X
65+
- **Total contributors**: Y
66+
- **Repositories**: openshift/hypershift (X PRs), openshift-eng/ai-helpers (Y PRs)
67+
68+
## PRs by OCPSTRAT Initiative
69+
70+
### OCPSTRAT-XXXX: [OCPSTRAT Summary]
71+
72+
**Related Epics:**
73+
- EPIC-XXX: [Epic Summary]
74+
75+
#### PR: [PR Title] (#XXXX)
76+
- **Repository**: openshift/hypershift
77+
- **Author**: @username
78+
- **Jira**: TICKET-XXX → EPIC-XXX → OCPSTRAT-XXXX
79+
- **Merged**: YYYY-MM-DD
80+
- **Reviewers**: @user1, @user2
81+
- **Approvers**: @user3
82+
- **Draft Timeline**:
83+
- Created as draft: YYYY-MM-DD HH:MM
84+
- Ready for review: YYYY-MM-DD HH:MM
85+
- Time in draft: X days
86+
- **Review Timeline**:
87+
- Time to merge after ready: X days
88+
- **Topic**: [Auto-generated topic classification]
89+
- **Summary**: [Brief description of what the PR does]
90+
- **Impact**: [Generated impact statement using Jira context and OCPSTRAT hierarchy]
91+
92+
---
93+
94+
### Uncategorized PRs (No OCPSTRAT Link)
95+
96+
#### PR: [PR Title] (#XXXX)
97+
[Same format as above, but without OCPSTRAT hierarchy]
98+
99+
---
100+
101+
## Metrics
102+
103+
### Time to Merge Distribution
104+
- **Average time from creation to ready**: X.Y days
105+
- **Average time from ready to merge**: X.Y days
106+
- **Fastest PR**: #XXXX (X.Y days)
107+
- **Slowest PR**: #XXXX (X.Y days)
108+
109+
### Top Contributors
110+
1. @username - X PRs
111+
2. @username - Y PRs
112+
113+
### Cross-Repository Contributions
114+
- Contributors working on both repos: X
115+
```
116+
117+
**Key Requirements for Generated Report:**
118+
119+
1. **PRs must be grouped by OCPSTRAT** parent initiative when available
120+
2. **Complete hierarchy** must be shown: Ticket → Epic → OCPSTRAT
121+
3. **Draft timeline** must include creation time, ready time, and duration in draft
122+
4. **Impact statements** should leverage:
123+
- Ticket summary and description
124+
- Epic summary for context
125+
- OCPSTRAT summary for strategic alignment
126+
5. **Topics** should be auto-classified (e.g., "Bug Fix", "Feature Enhancement", "Test Improvement", "Documentation")
127+
6. **Metrics section** must include timing analysis and contributor statistics
128+
129+
## Implementation
130+
131+
This command uses an optimized Python script for fast PR fetching, then enriches the data with Jira hierarchy information.
132+
133+
### Step 1: Run the Python script to fetch PRs
134+
135+
Parse the date argument and run the script:
136+
137+
```bash
138+
SINCE_DATE="$ARGUMENTS"
139+
if [ -z "$SINCE_DATE" ]; then
140+
SINCE_DATE=$(date -d '7 days ago' +%Y-%m-%d)
141+
fi
142+
143+
echo "Generating PR report since: $SINCE_DATE"
144+
python3 contrib/repo_metrics/weekly_pr_report.py "$SINCE_DATE"
145+
```
146+
147+
### Step 2: Query Jira for ticket hierarchy (in parallel)
148+
149+
Extract all unique Jira ticket IDs from the generated PR data and query Jira for each ticket to build hierarchy and enhance impact statements.
150+
151+
First, extract the unique tickets:
152+
153+
```bash
154+
TICKETS=$(jq -r '.[].jiraTickets[]' /tmp/hypershift_pr_details_fast.json | sort -u)
155+
echo "Found tickets: $TICKETS"
156+
```
157+
158+
Now, for EACH ticket in the list, use `mcp__atlassian-mcp__jira_get_issue` to fetch:
159+
160+
**Fields to request:** `summary,description,parent,customfield_12311140,customfield_12313140,issuelinks,labels,priority,status`
161+
162+
**Key custom fields:**
163+
- `customfield_12311140` = Epic Link field
164+
- `customfield_12313140` = OCPSTRAT Parent (simple string like "OCPSTRAT-2426")
165+
166+
**Build the hierarchy for each ticket:**
167+
168+
1. Query the ticket itself to get summary, description, Epic Link
169+
2. If Epic Link exists (customfield_12311140), query that Epic ticket to get its summary and OCPSTRAT parent
170+
3. Build a JSON structure like:
171+
```json
172+
{
173+
"TICKET-123": {
174+
"summary": "Ticket summary text",
175+
"description": "Full ticket description",
176+
"epic": "EPIC-456",
177+
"epicSummary": "Epic summary text",
178+
"ocpstrat": "OCPSTRAT-789",
179+
"ocpstratSummary": "OCPSTRAT summary text"
180+
}
181+
}
182+
```
183+
184+
4. Save ALL ticket hierarchies to `/tmp/jira_hierarchy.json`
185+
186+
**IMPORTANT:** Query all Epics and tickets in PARALLEL using multiple concurrent `mcp__atlassian-mcp__jira_get_issue` calls for maximum performance.
187+
188+
### Step 3: Regenerate report with Jira enrichment
189+
190+
Once Jira hierarchy is saved, re-run the Python script to regenerate the report with enriched impact statements:
191+
192+
```bash
193+
python3 contrib/repo_metrics/weekly_pr_report.py "$SINCE_DATE"
194+
```
195+
196+
The script will now use the Jira data to:
197+
- Show complete ticket → Epic → OCPSTRAT hierarchy
198+
- Generate better impact statements using ticket summaries and OCPSTRAT context
199+
- Group PRs by their OCPSTRAT parent initiatives
200+
201+
## Script Features
202+
203+
The Python script uses:
204+
- **GitHub Contributors API** to fetch all 194 HyperShift contributors
205+
- **GitHub GraphQL API** with search queries for efficient PR fetching (`merged:>=$DATE`)
206+
- **Parallel async API calls** with aiohttp for maximum performance
207+
- **Jira hierarchy caching** (loads from previous run if available)
208+
209+
## Notes
210+
211+
- Requires `aiohttp` Python package: `pip install aiohttp`
212+
- Falls back to synchronous mode if aiohttp is not available (slower but functional)
213+
- Jira hierarchy is loaded from cache (`/tmp/jira_hierarchy.json`) if available
214+
- For full Jira integration, ensure Jira MCP tools are configured

contrib/repo_metrics/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,66 @@ uv sync --dev
1616

1717
## Tools
1818

19+
### Weekly PR Report Generator
20+
21+
Generates comprehensive weekly PR reports for openshift/hypershift and openshift-eng/ai-helpers repositories.
22+
23+
**Features:**
24+
- Fetches all repository contributors (194 total)
25+
- Uses GitHub GraphQL API for efficient PR fetching
26+
- Parallel async API calls with aiohttp
27+
- Filters PRs by merge date
28+
- Extracts complete PR timeline (draft→ready→merge)
29+
- Identifies reviewers and approvers
30+
- Groups PRs by OCPSTRAT parent
31+
- Generates timing metrics and statistics
32+
- Auto-generates OCPSTRAT impact statements
33+
34+
**Performance:** ~2 seconds (90-180x faster than previous agent-based approach)
35+
36+
**Usage:**
37+
38+
```bash
39+
# Install aiohttp dependency
40+
pip install aiohttp
41+
42+
# Run with default (7 days ago)
43+
python3 weekly_pr_report.py
44+
45+
# Generate report since specific date
46+
python3 weekly_pr_report.py 2025-11-13
47+
```
48+
49+
**Via Claude slash command:**
50+
51+
```bash
52+
# From repository root
53+
/weekly-pr-report 2025-11-13
54+
```
55+
56+
**Output:**
57+
58+
```text
59+
Generating PR report since: 2025-11-13
60+
Using async (aiohttp) mode
61+
62+
Fetching HyperShift contributors...
63+
Found 194 HyperShift contributors
64+
Fetching PRs from repositories...
65+
Found 27 PRs (24 hypershift, 3 ai-helpers)
66+
Fetching Jira hierarchy...
67+
Found 2 unique Jira tickets
68+
Generating report...
69+
Report written to /tmp/weekly_pr_report_fast.md
70+
Raw data saved to /tmp/hypershift_pr_details_fast.json
71+
72+
Done in 2.02 seconds!
73+
```
74+
75+
**Files generated:**
76+
- `/tmp/weekly_pr_report_fast.md` - Comprehensive markdown report
77+
- `/tmp/hypershift_pr_details_fast.json` - Raw PR data in JSON format
78+
1979
### AI-Assisted Commits Analyzer
2080

2181
Analyzes git commits to identify those assisted by AI tools (Claude, GPT, etc.).

0 commit comments

Comments
 (0)