commit-analyzer 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +12 -0
- package/README.md +243 -0
- package/csv-to-report-prompt.md +97 -0
- package/package.json +39 -0
- package/prompt.md +69 -0
- package/src/cli.ts +143 -0
- package/src/csv-reader.ts +180 -0
- package/src/csv.ts +40 -0
- package/src/errors.ts +49 -0
- package/src/git.ts +112 -0
- package/src/index.ts +283 -0
- package/src/llm.ts +283 -0
- package/src/progress.ts +77 -0
- package/src/report-generator.ts +286 -0
- package/src/types.ts +24 -0
- package/tsconfig.json +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# Git Commit Analyzer
|
|
2
|
+
|
|
3
|
+
A TypeScript/Node.js program that analyzes git commits and generates categorized summaries using Claude CLI.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Extract commit details (message, date, diff) from git repositories
|
|
8
|
+
- Categorize commits using LLM analysis into: `tweak`, `feature`, or `process`
|
|
9
|
+
- Generate CSV reports with year, category, summary, and description
|
|
10
|
+
- Generate condensed markdown reports from CSV data for stakeholder communication
|
|
11
|
+
- Support for multiple LLM models (Claude, Gemini, Codex) with automatic detection
|
|
12
|
+
- Support for batch processing multiple commits
|
|
13
|
+
- Automatically filters out merge commits for cleaner analysis
|
|
14
|
+
- Robust error handling and validation
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install
|
|
20
|
+
npm run build
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Default Behavior
|
|
26
|
+
|
|
27
|
+
When run without arguments, the program analyzes all commits authored by the current user:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Analyze all your commits in the current repository
|
|
31
|
+
npx commit-analyzer
|
|
32
|
+
|
|
33
|
+
# Analyze your last 10 commits
|
|
34
|
+
npx commit-analyzer --limit 10
|
|
35
|
+
|
|
36
|
+
# Analyze commits by a specific user
|
|
37
|
+
npx commit-analyzer --author user@example.com
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Command Line Arguments
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# Analyze specific commits
|
|
44
|
+
npx commit-analyzer abc123 def456 ghi789
|
|
45
|
+
|
|
46
|
+
# Read commits from file
|
|
47
|
+
npx commit-analyzer --file commits.txt
|
|
48
|
+
|
|
49
|
+
# Specify output file with default behavior
|
|
50
|
+
npx commit-analyzer --output analysis.csv --limit 20
|
|
51
|
+
|
|
52
|
+
# Generate markdown report from existing CSV
|
|
53
|
+
npx commit-analyzer --report --input-csv analysis.csv
|
|
54
|
+
|
|
55
|
+
# Analyze commits and generate both CSV and markdown report
|
|
56
|
+
npx commit-analyzer --report --limit 50
|
|
57
|
+
|
|
58
|
+
# Use specific LLM model
|
|
59
|
+
npx commit-analyzer --model claude --limit 10
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Options
|
|
63
|
+
|
|
64
|
+
- `-o, --output <file>`: Output file (default: `output.csv` for analysis, `summary-report.md` for reports)
|
|
65
|
+
- `-f, --file <file>`: Read commit hashes from file (one per line)
|
|
66
|
+
- `-a, --author <email>`: Filter commits by author email (defaults to current user)
|
|
67
|
+
- `-l, --limit <number>`: Limit number of commits to analyze
|
|
68
|
+
- `-m, --model <model>`: LLM model to use (claude, gemini, codex)
|
|
69
|
+
- `-r, --resume`: Resume from last checkpoint if available
|
|
70
|
+
- `-c, --clear`: Clear any existing progress checkpoint
|
|
71
|
+
- `--report`: Generate condensed markdown report from existing CSV
|
|
72
|
+
- `--input-csv <file>`: Input CSV file to read for report generation
|
|
73
|
+
- `-h, --help`: Display help
|
|
74
|
+
- `-V, --version`: Display version
|
|
75
|
+
|
|
76
|
+
### Input File Format
|
|
77
|
+
|
|
78
|
+
When using `--file`, create a text file with one commit hash per line:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
abc123def456
|
|
82
|
+
def456ghi789
|
|
83
|
+
ghi789jkl012
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Output Formats
|
|
87
|
+
|
|
88
|
+
### CSV Output
|
|
89
|
+
|
|
90
|
+
The program generates a CSV file with the following columns:
|
|
91
|
+
|
|
92
|
+
- `year`: Year of the commit
|
|
93
|
+
- `category`: One of `tweak`, `feature`, or `process`
|
|
94
|
+
- `summary`: One-line description (max 80 characters)
|
|
95
|
+
- `description`: Detailed explanation (2-3 sentences)
|
|
96
|
+
|
|
97
|
+
### Markdown Report Output
|
|
98
|
+
|
|
99
|
+
When using the `--report` option, the program generates a condensed markdown report that:
|
|
100
|
+
|
|
101
|
+
- Groups commits by year (most recent first)
|
|
102
|
+
- Organizes by categories: Features, Processes, Tweaks & Bug Fixes
|
|
103
|
+
- Consolidates similar items for stakeholder readability
|
|
104
|
+
- Includes commit count statistics
|
|
105
|
+
- Uses professional language suitable for both technical and non-technical audiences
|
|
106
|
+
|
|
107
|
+
## Requirements
|
|
108
|
+
|
|
109
|
+
- Node.js 18+ with TypeScript support
|
|
110
|
+
- Git repository (must be run within a git repository)
|
|
111
|
+
- At least one supported LLM CLI tool:
|
|
112
|
+
- Claude CLI (`claude`) - recommended, defaults to Sonnet model
|
|
113
|
+
- Gemini CLI (`gemini`)
|
|
114
|
+
- Codex CLI (`codex`)
|
|
115
|
+
- Valid git commit hashes (when specifying commits manually)
|
|
116
|
+
|
|
117
|
+
## Categories
|
|
118
|
+
|
|
119
|
+
- **tweak**: Minor adjustments, bug fixes, small improvements
|
|
120
|
+
- **feature**: New functionality, major additions
|
|
121
|
+
- **process**: Build system, CI/CD, tooling, configuration changes
|
|
122
|
+
|
|
123
|
+
## Error Handling
|
|
124
|
+
|
|
125
|
+
The program includes comprehensive error handling for:
|
|
126
|
+
|
|
127
|
+
- Invalid commit hashes
|
|
128
|
+
- Git repository validation
|
|
129
|
+
- LLM analysis failures with automatic retry
|
|
130
|
+
- File I/O errors
|
|
131
|
+
- Network connectivity issues
|
|
132
|
+
|
|
133
|
+
### Resume Capability
|
|
134
|
+
|
|
135
|
+
The tool automatically:
|
|
136
|
+
- Saves progress checkpoints every 10 commits
|
|
137
|
+
- Saves immediately when a failure occurs
|
|
138
|
+
- **Stops processing after a commit fails all retry attempts**
|
|
139
|
+
- Exports partial results to the CSV file before exiting
|
|
140
|
+
|
|
141
|
+
If the process stops (e.g., after 139 commits due to API failure), you can resume from where it left off:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
# Resume from last checkpoint
|
|
145
|
+
npx commit-analyzer --resume
|
|
146
|
+
|
|
147
|
+
# Clear checkpoint and start fresh
|
|
148
|
+
npx commit-analyzer --clear
|
|
149
|
+
|
|
150
|
+
# View checkpoint status (it will prompt you)
|
|
151
|
+
npx commit-analyzer --resume
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The checkpoint file (`.commit-analyzer-progress.json`) contains:
|
|
155
|
+
- List of all commits to process
|
|
156
|
+
- Successfully processed commits (including failed ones to skip on resume)
|
|
157
|
+
- Analyzed commit data (only successful ones)
|
|
158
|
+
- Output file location
|
|
159
|
+
|
|
160
|
+
**Important**: When a commit fails after all retries (default 3), the process stops immediately to prevent wasting API calls. The successfully analyzed commits up to that point are saved to the CSV file.
|
|
161
|
+
|
|
162
|
+
### Retry Logic
|
|
163
|
+
|
|
164
|
+
The tool includes automatic retry logic with exponential backoff for handling API failures when processing many commits. This is especially useful when analyzing large numbers of commits that might trigger rate limits.
|
|
165
|
+
|
|
166
|
+
#### Configuration
|
|
167
|
+
|
|
168
|
+
You can configure the retry behavior using environment variables:
|
|
169
|
+
|
|
170
|
+
- `LLM_MAX_RETRIES`: Maximum number of retry attempts (default: 3)
|
|
171
|
+
- `LLM_INITIAL_RETRY_DELAY`: Initial delay between retries in milliseconds (default: 5000)
|
|
172
|
+
- `LLM_MAX_RETRY_DELAY`: Maximum delay between retries in milliseconds (default: 30000)
|
|
173
|
+
- `LLM_RETRY_MULTIPLIER`: Multiplier for exponential backoff (default: 2)
|
|
174
|
+
|
|
175
|
+
#### Examples
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# More aggressive retries for large batches (e.g., 139+ commits)
|
|
179
|
+
LLM_MAX_RETRIES=5 LLM_INITIAL_RETRY_DELAY=10000 npx commit-analyzer --limit 200
|
|
180
|
+
|
|
181
|
+
# Faster retries for testing
|
|
182
|
+
LLM_MAX_RETRIES=2 LLM_INITIAL_RETRY_DELAY=2000 npx commit-analyzer
|
|
183
|
+
|
|
184
|
+
# Conservative approach for rate-limited APIs
|
|
185
|
+
LLM_MAX_RETRIES=4 LLM_INITIAL_RETRY_DELAY=15000 LLM_MAX_RETRY_DELAY=60000 npx commit-analyzer
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
The retry mechanism automatically:
|
|
189
|
+
- Retries failed API calls with increasing delays
|
|
190
|
+
- Shows progress and retry attempts in the console
|
|
191
|
+
- Continues processing remaining commits even if some fail
|
|
192
|
+
- Reports the total number of successful and failed commits at the end
|
|
193
|
+
|
|
194
|
+
## Development
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
# Install dependencies
|
|
198
|
+
npm install
|
|
199
|
+
|
|
200
|
+
# Run in development mode
|
|
201
|
+
npm run dev
|
|
202
|
+
|
|
203
|
+
# Build for production
|
|
204
|
+
npm run build
|
|
205
|
+
|
|
206
|
+
# Run linting
|
|
207
|
+
npm run lint
|
|
208
|
+
|
|
209
|
+
# Type checking
|
|
210
|
+
npm run typecheck
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Examples
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
# Analyze all your commits in the current repository
|
|
217
|
+
npx commit-analyzer
|
|
218
|
+
|
|
219
|
+
# Analyze your last 20 commits and save to custom file
|
|
220
|
+
npx commit-analyzer --limit 20 --output my_analysis.csv
|
|
221
|
+
|
|
222
|
+
# Analyze commits by a specific team member
|
|
223
|
+
npx commit-analyzer --author teammate@company.com --limit 50
|
|
224
|
+
|
|
225
|
+
# Analyze specific commits
|
|
226
|
+
git log --oneline -5 | cut -d' ' -f1 > recent_commits.txt
|
|
227
|
+
npx commit-analyzer --file recent_commits.txt --output recent_analysis.csv
|
|
228
|
+
|
|
229
|
+
# Quick analysis of your recent work
|
|
230
|
+
npx commit-analyzer --limit 10
|
|
231
|
+
|
|
232
|
+
# Generate both CSV and markdown report from analysis
|
|
233
|
+
npx commit-analyzer --report --limit 100 --output yearly_analysis.csv
|
|
234
|
+
|
|
235
|
+
# Generate only a markdown report from existing CSV
|
|
236
|
+
npx commit-analyzer --report --input-csv existing_analysis.csv --output team_report.md
|
|
237
|
+
|
|
238
|
+
# Use specific LLM model for analysis
|
|
239
|
+
npx commit-analyzer --model gemini --limit 25
|
|
240
|
+
|
|
241
|
+
# Resume interrupted analysis with progress tracking
|
|
242
|
+
npx commit-analyzer --resume
|
|
243
|
+
```
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# LLM Prompt Template: CSV to Markdown Report Generation
|
|
2
|
+
|
|
3
|
+
This is the prompt template to be used by the LLM service to generate condensed
|
|
4
|
+
markdown reports from CSV commit analysis data.
|
|
5
|
+
|
|
6
|
+
## Prompt Template
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
Analyze the following CSV data containing git commit analysis results and generate a condensed markdown development summary report.
|
|
10
|
+
|
|
11
|
+
CSV DATA:
|
|
12
|
+
{csv_content}
|
|
13
|
+
|
|
14
|
+
INSTRUCTIONS:
|
|
15
|
+
1. Group the data by year (descending order, most recent first)
|
|
16
|
+
2. Within each year, group by category: Features, Process Improvements, and Tweaks & Bug Fixes
|
|
17
|
+
3. Consolidate similar items within each category to create readable summaries
|
|
18
|
+
4. Focus on what was accomplished rather than individual commit details
|
|
19
|
+
5. Use clear, professional language appropriate for stakeholders
|
|
20
|
+
|
|
21
|
+
CATEGORY MAPPING:
|
|
22
|
+
- "feature" → "Features" section
|
|
23
|
+
- "process" → "Processes" section
|
|
24
|
+
- "tweak" → "Tweaks & Bug Fixes" section
|
|
25
|
+
|
|
26
|
+
CONSOLIDATION GUIDELINES:
|
|
27
|
+
- Group similar features together (e.g., "authentication system improvements")
|
|
28
|
+
- Combine related bug fixes (e.g., "resolved 8 authentication issues")
|
|
29
|
+
- Summarize process changes by theme (e.g., "CI/CD pipeline enhancements")
|
|
30
|
+
- Use bullet points for individual items within categories
|
|
31
|
+
- Aim for 3-7 bullet points per category per year
|
|
32
|
+
- Include specific numbers when relevant (e.g., "15 bug fixes", "3 new features")
|
|
33
|
+
|
|
34
|
+
OUTPUT FORMAT:
|
|
35
|
+
Generate a markdown report with this exact structure:
|
|
36
|
+
|
|
37
|
+
```markdown
|
|
38
|
+
# Development Summary Report
|
|
39
|
+
|
|
40
|
+
## Commit Analysis
|
|
41
|
+
- **Total Commits**: [X] commits across [YEAR_RANGE]
|
|
42
|
+
- **[MOST_RECENT_YEAR]**: [X] commits ([X] features, [X] process, [X] tweaks)
|
|
43
|
+
- **[PREVIOUS_YEAR]**: [X] commits ([X] features, [X] process, [X] tweaks)
|
|
44
|
+
- [Continue for each year in the data]
|
|
45
|
+
|
|
46
|
+
## [YEAR]
|
|
47
|
+
### Features
|
|
48
|
+
- [Consolidated feature summary 1]
|
|
49
|
+
- [Consolidated feature summary 2]
|
|
50
|
+
- [Additional features as needed]
|
|
51
|
+
|
|
52
|
+
### Processes
|
|
53
|
+
- [Consolidated process improvement 1]
|
|
54
|
+
- [Consolidated process improvement 2]
|
|
55
|
+
- [Additional process items as needed]
|
|
56
|
+
|
|
57
|
+
### Tweaks & Bug Fixes
|
|
58
|
+
- [Consolidated tweak/fix summary 1]
|
|
59
|
+
- [Consolidated tweak/fix summary 2]
|
|
60
|
+
- [Additional tweaks/fixes as needed]
|
|
61
|
+
|
|
62
|
+
## [PREVIOUS YEAR]
|
|
63
|
+
[Repeat structure for each year in the data]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
QUALITY REQUIREMENTS:
|
|
67
|
+
- Keep summaries concise but informative
|
|
68
|
+
- Use active voice and clear language
|
|
69
|
+
- Avoid technical jargon where possible
|
|
70
|
+
- Ensure each bullet point represents meaningful work
|
|
71
|
+
- Make the report valuable for both technical and non-technical readers
|
|
72
|
+
|
|
73
|
+
Generate the markdown report now:
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Implementation Notes
|
|
77
|
+
|
|
78
|
+
This prompt should be used in the `MarkdownReportGenerator` service with the following approach:
|
|
79
|
+
|
|
80
|
+
1. **Input Processing**: Replace `{csv_content}` with the actual CSV data read from the input file
|
|
81
|
+
2. **LLM Call**: Send this prompt to the configured LLM (Claude, Gemini, etc.)
|
|
82
|
+
3. **Response Parsing**: Extract the markdown content from the LLM response
|
|
83
|
+
4. **File Output**: Write the generated markdown to the specified output file
|
|
84
|
+
|
|
85
|
+
### Error Handling
|
|
86
|
+
- If LLM returns malformed response, retry up to MAX_RETRIES times
|
|
87
|
+
- Validate that the response contains properly formatted markdown
|
|
88
|
+
- Ensure all years from the CSV data are represented in the output
|
|
89
|
+
- Handle edge cases like empty categories or single-item categories
|
|
90
|
+
|
|
91
|
+
### Response Validation
|
|
92
|
+
The generated report should:
|
|
93
|
+
- Start with "# Development Summary Report"
|
|
94
|
+
- Have year sections in descending chronological order
|
|
95
|
+
- Include all three category sections for each year (even if empty)
|
|
96
|
+
- Use proper markdown formatting with ## for years and ### for categories
|
|
97
|
+
- Contain bullet points (-) for individual items
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "commit-analyzer",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Analyze git commits and generate categories, summaries, and descriptions for each commit. Optionally generate a yearly breakdown report of your commit history.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"commit-analyzer": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"prettier": {
|
|
10
|
+
"semi": false
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"start": "node dist/index.js",
|
|
15
|
+
"dev": "ts-node src/index.ts",
|
|
16
|
+
"lint": "eslint src/**/*.ts",
|
|
17
|
+
"typecheck": "tsc --noEmit"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"git",
|
|
21
|
+
"commit",
|
|
22
|
+
"analysis",
|
|
23
|
+
"llm",
|
|
24
|
+
"categorization"
|
|
25
|
+
],
|
|
26
|
+
"author": "steverodri",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^20.0.0",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
31
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
32
|
+
"eslint": "^8.0.0",
|
|
33
|
+
"ts-node": "^10.0.0",
|
|
34
|
+
"typescript": "^5.0.0"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"commander": "^11.0.0"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/prompt.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Prompt for Git Commit Analysis Program
|
|
2
|
+
|
|
3
|
+
Create a TypeScript/Node.js program that analyzes git commits and generates
|
|
4
|
+
categorized summaries.
|
|
5
|
+
|
|
6
|
+
The program should:
|
|
7
|
+
|
|
8
|
+
## Input Requirements
|
|
9
|
+
|
|
10
|
+
- Accept a list of git commit hashes as input (command line arguments or file)
|
|
11
|
+
- For each commit, extract the commit message, date, and diff
|
|
12
|
+
|
|
13
|
+
Core Functionality:
|
|
14
|
+
|
|
15
|
+
1. Git Integration:
|
|
16
|
+
Use git show and git diff to get commit details and changes
|
|
17
|
+
2. LLM Analysis:
|
|
18
|
+
Send commit message + diff to the claude cli for categorization.
|
|
19
|
+
3. CSV Export:
|
|
20
|
+
Generate output with columns:
|
|
21
|
+
year, category, summary, description
|
|
22
|
+
|
|
23
|
+
## LLM Prompt Template
|
|
24
|
+
|
|
25
|
+
Analyze this git commit and provide a categorization:
|
|
26
|
+
|
|
27
|
+
- COMMIT MESSAGE:
|
|
28
|
+
{commit_message}
|
|
29
|
+
- COMMIT DIFF:
|
|
30
|
+
{diff_content}
|
|
31
|
+
|
|
32
|
+
Based on the commit message and code changes, categorize this commit as one
|
|
33
|
+
of:
|
|
34
|
+
- "tweak":
|
|
35
|
+
Minor adjustments, bug fixes, small improvements
|
|
36
|
+
- "feature":
|
|
37
|
+
New functionality, major additions
|
|
38
|
+
- "process":
|
|
39
|
+
Build system, CI/CD, tooling, configuration changes
|
|
40
|
+
|
|
41
|
+
Provide:
|
|
42
|
+
1. Category:
|
|
43
|
+
[tweak|feature|process]
|
|
44
|
+
2. Summary:
|
|
45
|
+
One-line description (max 80 chars)
|
|
46
|
+
3. Description:
|
|
47
|
+
Detailed explanation (2-3 sentences)
|
|
48
|
+
|
|
49
|
+
Format as JSON:
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"category": "...",
|
|
53
|
+
"summary": "...",
|
|
54
|
+
"description": "..."
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Technical Implementation
|
|
59
|
+
|
|
60
|
+
- Use Node.js with TypeScript
|
|
61
|
+
- Extract year from git commit timestamp
|
|
62
|
+
|
|
63
|
+
Output Format:
|
|
64
|
+
|
|
65
|
+
CSV with headers:
|
|
66
|
+
year,category,summary,description
|
|
67
|
+
|
|
68
|
+
The program should be robust, handle edge cases, and provide clear error
|
|
69
|
+
messages for invalid commits or API failures.
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { readFileSync } from "fs"
|
|
2
|
+
import { Command } from "commander"
|
|
3
|
+
|
|
4
|
+
export interface CLIOptions {
|
|
5
|
+
output?: string
|
|
6
|
+
file?: string
|
|
7
|
+
commits: string[]
|
|
8
|
+
author?: string
|
|
9
|
+
limit?: number
|
|
10
|
+
useDefaults: boolean
|
|
11
|
+
resume?: boolean
|
|
12
|
+
clear?: boolean
|
|
13
|
+
model?: string
|
|
14
|
+
report?: boolean
|
|
15
|
+
inputCsv?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class CLIService {
|
|
19
|
+
static parseArguments(): CLIOptions {
|
|
20
|
+
const program = new Command()
|
|
21
|
+
|
|
22
|
+
program
|
|
23
|
+
.name("commit-analyzer")
|
|
24
|
+
.description("Analyze git commits and generate categorized summaries")
|
|
25
|
+
.version("1.0.0")
|
|
26
|
+
.option("-o, --output <file>", "Output CSV file (default: output.csv)")
|
|
27
|
+
.option(
|
|
28
|
+
"-f, --file <file>",
|
|
29
|
+
"Read commit hashes from file (one per line)",
|
|
30
|
+
)
|
|
31
|
+
.option(
|
|
32
|
+
"-a, --author <email>",
|
|
33
|
+
"Filter commits by author email (defaults to current user)",
|
|
34
|
+
)
|
|
35
|
+
.option(
|
|
36
|
+
"-l, --limit <number>",
|
|
37
|
+
"Limit number of commits to analyze",
|
|
38
|
+
parseInt,
|
|
39
|
+
)
|
|
40
|
+
.option(
|
|
41
|
+
"-r, --resume",
|
|
42
|
+
"Resume from last checkpoint if available",
|
|
43
|
+
)
|
|
44
|
+
.option(
|
|
45
|
+
"-c, --clear",
|
|
46
|
+
"Clear any existing progress checkpoint",
|
|
47
|
+
)
|
|
48
|
+
.option(
|
|
49
|
+
"-m, --model <model>",
|
|
50
|
+
"LLM model to use (claude, gemini, codex)",
|
|
51
|
+
)
|
|
52
|
+
.option(
|
|
53
|
+
"--report",
|
|
54
|
+
"Generate condensed markdown report from existing CSV",
|
|
55
|
+
)
|
|
56
|
+
.option(
|
|
57
|
+
"--input-csv <file>",
|
|
58
|
+
"Input CSV file to read for report generation",
|
|
59
|
+
)
|
|
60
|
+
.argument(
|
|
61
|
+
"[commits...]",
|
|
62
|
+
"Commit hashes to analyze (if none provided, uses current user's commits)",
|
|
63
|
+
)
|
|
64
|
+
.parse()
|
|
65
|
+
|
|
66
|
+
const options = program.opts()
|
|
67
|
+
const args = program.args
|
|
68
|
+
|
|
69
|
+
let commits: string[] = []
|
|
70
|
+
let useDefaults = false
|
|
71
|
+
|
|
72
|
+
if (options.file) {
|
|
73
|
+
commits = this.readCommitsFromFile(options.file)
|
|
74
|
+
} else if (args.length > 0) {
|
|
75
|
+
commits = args
|
|
76
|
+
} else {
|
|
77
|
+
useDefaults = true
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
output: options.output || "output.csv",
|
|
82
|
+
file: options.file,
|
|
83
|
+
commits,
|
|
84
|
+
author: options.author,
|
|
85
|
+
limit: options.limit,
|
|
86
|
+
useDefaults,
|
|
87
|
+
resume: options.resume,
|
|
88
|
+
clear: options.clear,
|
|
89
|
+
model: options.model,
|
|
90
|
+
report: options.report,
|
|
91
|
+
inputCsv: options.inputCsv,
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private static readCommitsFromFile(filename: string): string[] {
|
|
96
|
+
try {
|
|
97
|
+
const content = readFileSync(filename, "utf8")
|
|
98
|
+
return content
|
|
99
|
+
.split("\n")
|
|
100
|
+
.map((line) => line.trim())
|
|
101
|
+
.filter((line) => line.length > 0)
|
|
102
|
+
} catch (error) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Failed to read commits from file ${filename}: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static showHelp(): void {
|
|
110
|
+
console.log(`
|
|
111
|
+
Usage: commit-analyzer [options] [commits...]
|
|
112
|
+
|
|
113
|
+
Analyze git commits and generate categorized summaries using LLM.
|
|
114
|
+
If no commits are specified, analyzes all commits authored by the current user.
|
|
115
|
+
|
|
116
|
+
Options:
|
|
117
|
+
-o, --output <file> Output file (default: output.csv for analysis, summary-report.md for reports)
|
|
118
|
+
-f, --file <file> Read commit hashes from file (one per line)
|
|
119
|
+
-a, --author <email> Filter commits by author email (defaults to current user)
|
|
120
|
+
-l, --limit <number> Limit number of commits to analyze
|
|
121
|
+
-r, --resume Resume from last checkpoint if available
|
|
122
|
+
-c, --clear Clear any existing progress checkpoint
|
|
123
|
+
--report Generate condensed markdown report from existing CSV
|
|
124
|
+
--input-csv <file> Input CSV file to read for report generation
|
|
125
|
+
-h, --help Display help for command
|
|
126
|
+
-V, --version Display version number
|
|
127
|
+
|
|
128
|
+
Examples:
|
|
129
|
+
commit-analyzer # Analyze your authored commits
|
|
130
|
+
commit-analyzer --limit 10 # Analyze your last 10 commits
|
|
131
|
+
commit-analyzer --author user@example.com # Analyze specific user's commits
|
|
132
|
+
commit-analyzer abc123 def456 ghi789 # Analyze specific commits
|
|
133
|
+
commit-analyzer --file commits.txt # Read commits from file
|
|
134
|
+
commit-analyzer --output analysis.csv --limit 20 # Analyze last 20 commits to custom file
|
|
135
|
+
commit-analyzer --resume # Resume from last checkpoint
|
|
136
|
+
commit-analyzer --clear # Clear checkpoint and start fresh
|
|
137
|
+
commit-analyzer --report # Analyze commits, generate CSV, then generate report
|
|
138
|
+
commit-analyzer --input-csv data.csv --report # Skip analysis, generate report from existing CSV
|
|
139
|
+
commit-analyzer --report -o custom-report.md # Analyze commits, generate CSV, then generate custom report
|
|
140
|
+
`)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|