@sun-asterisk/impact-analyzer 1.0.0

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/README.md ADDED
@@ -0,0 +1,506 @@
1
+ # Impact Analyzer
2
+
3
+ Automated impact analysis tool for TypeScript/JavaScript projects. Analyzes code changes between git references and generates comprehensive impact reports.
4
+
5
+ ## Overview
6
+
7
+ Impact Analyzer is a powerful tool designed to help development teams understand the full impact of code changes in their TypeScript/JavaScript projects. It detects changes between git commits/branches and automatically analyzes:
8
+
9
+ - **API Endpoints** - Which REST APIs are affected by the changes
10
+ - **Database Operations** - Which database tables and fields are impacted
11
+ - **Pages/Components** - Which UI components and pages are modified
12
+ - **Logic Impact** - Function call dependencies and impact scope
13
+ - **Test Coverage** - Recommended test cases based on changes
14
+
15
+ ### Key Benefits
16
+
17
+ - 🎯 **Reduce Testing Effort** - Know exactly what to test instead of full regression
18
+ - πŸš€ **Faster Code Reviews** - Reviewers can quickly understand the scope of changes
19
+ - πŸ“Š **Risk Assessment** - Automatically calculates impact scores and severity levels
20
+ - πŸ” **Dependency Tracking** - Identifies all files and functions affected by changes
21
+ - πŸ“ **Automated Reports** - Generates detailed markdown and JSON reports
22
+
23
+ ## Analysis Flow
24
+
25
+ ```
26
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
27
+ β”‚ 1. GIT CHANGE DETECTION β”‚
28
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
29
+ β”‚ β”‚ Git Diff β”‚ ───> β”‚ Changed β”‚ ───> β”‚ AST Parser β”‚ β”‚
30
+ │ │ (base→head) │ │ Files │ │ (Symbols) │ │
31
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
32
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
33
+ β”‚
34
+ β–Ό
35
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
36
+ β”‚ 2. METHOD-LEVEL CALL GRAPH (ts-morph) β”‚
37
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
38
+ β”‚ β”‚ Parse TS/JS β”‚ ───> β”‚ Extract β”‚ ───> β”‚ Build Call β”‚ β”‚
39
+ β”‚ β”‚ Files β”‚ β”‚ Methods β”‚ β”‚ Graph Maps β”‚ β”‚
40
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
41
+ β”‚ β”‚
42
+ β”‚ ⚑ OPTIMIZED: Only parses source files, skips loading all to RAM β”‚
43
+ β”‚ β€’ method β†’ [methods it calls] (forward map) β”‚
44
+ β”‚ β€’ method β†’ [callers] (reverse map) β”‚
45
+ β”‚ β€’ method β†’ endpoint info (HTTP decorators) β”‚
46
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
47
+ β”‚
48
+ β–Ό
49
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
50
+ β”‚ 3. IMPACT DETECTION β”‚
51
+ β”‚ β”‚
52
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
53
+ β”‚ β”‚ ENDPOINT DETECTOR β”‚ β”‚ DATABASE DETECTOR β”‚ β”‚
54
+ β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚
55
+ β”‚ β”‚ Changed Method β”‚ β”‚ Changed Method β”‚ β”‚
56
+ β”‚ β”‚ ↓ β”‚ β”‚ ↓ β”‚ β”‚
57
+ β”‚ β”‚ Traverse Call Graph ↑ β”‚ β”‚ Find Repository β”‚ β”‚
58
+ β”‚ β”‚ ↓ β”‚ β”‚ Methods ↓ β”‚ β”‚
59
+ β”‚ β”‚ Find Callers β”‚ β”‚ Detect DB Ops β”‚ β”‚
60
+ β”‚ β”‚ ↓ β”‚ β”‚ (TypeORM/Prisma) β”‚ β”‚
61
+ β”‚ β”‚ Filter @Get/@Post β”‚ β”‚ ↓ β”‚ β”‚
62
+ β”‚ β”‚ ↓ β”‚ β”‚ Extract Tables/Fields β”‚ β”‚
63
+ β”‚ β”‚ πŸ“‘ Affected Endpoints β”‚ β”‚ πŸ’Ύ DB Impact β”‚ β”‚
64
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
65
+ β”‚ β”‚
66
+ β”‚ Flow: Repository β†’ Service β†’ Controller β†’ @Endpoint β”‚
67
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
68
+ β”‚
69
+ β–Ό
70
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
71
+ β”‚ 4. LOGIC IMPACT ANALYSIS β”‚
72
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
73
+ β”‚ β”‚ Direct β”‚ ───> β”‚ Indirect β”‚ ───> β”‚ Risk Level β”‚ β”‚
74
+ β”‚ β”‚ Callers β”‚ β”‚ Callers β”‚ β”‚ Calculation β”‚ β”‚
75
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
76
+ β”‚ β”‚
77
+ β”‚ Uses method call graph for accurate caller tracking β”‚
78
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
79
+ β”‚
80
+ β–Ό
81
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
82
+ β”‚ 5. IMPACT SCORE CALCULATION β”‚
83
+ β”‚ β”‚
84
+ β”‚ Score = (Endpoints Γ— 10) + (DB Tables Γ— 5) + β”‚
85
+ β”‚ (Direct Callers Γ— 3) + (Indirect Callers Γ— 1) β”‚
86
+ β”‚ β”‚
87
+ β”‚ Multipliers: β”‚
88
+ β”‚ β€’ High Risk Logic: Γ—1.5 β”‚
89
+ β”‚ β€’ DB Migration: +20 β”‚
90
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
91
+ β”‚
92
+ β–Ό
93
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
94
+ β”‚ 6. REPORT GENERATION β”‚
95
+ β”‚ β”‚
96
+ β”‚ Score β†’ Severity: 🟒 LOW | 🟑 MEDIUM | 🟠 HIGH | πŸ”΄ CRITICAL β”‚
97
+ β”‚ β”‚
98
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
99
+ β”‚ β”‚ Console β”‚ β”‚ Markdown β”‚ β”‚ JSON β”‚ β”‚
100
+ β”‚ β”‚ Report β”‚ β”‚ Report β”‚ β”‚ (CI/CD) β”‚ β”‚
101
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
102
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
103
+ ```
104
+
105
+ ### Architecture Highlights
106
+
107
+ **Layer-Aware Tracking**
108
+ ```
109
+ Controller (@Get/@Post) ──┐
110
+ ↑ β”‚
111
+ Service β”‚ Call Graph
112
+ ↑ β”‚ Traversal
113
+ Repository β”‚
114
+ ↑ β”‚
115
+ Database β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
116
+ ```
117
+
118
+ **Component Separation**
119
+ - `MethodCallGraph`: Pure graph construction logic (no logging)
120
+ - `EndpointDetector`: Endpoint impact analysis + verbose logging
121
+ - `DatabaseDetector`: Database impact analysis + verbose logging
122
+ - `ImpactAnalyzer`: Orchestration and aggregation
123
+
124
+ ## Features
125
+
126
+ ### 1. Change Detection
127
+ - Detects modified, added, and deleted files between git references
128
+ - Extracts changed symbols (functions, classes, methods) using AST parsing
129
+ - Categorizes files by type (source, test, config)
130
+ - Calculates line changes for each file
131
+
132
+ ### 2. API Endpoint Analysis
133
+ - Automatically detects affected REST API endpoints
134
+ - Supports multiple frameworks:
135
+ - NestJS decorators (`@Get()`, `@Post()`, etc.)
136
+ - Express routes (`app.get()`, `router.post()`, etc.)
137
+ - Fastify routes
138
+ - Groups endpoints by controller
139
+ - Shows impact level for each endpoint
140
+
141
+ ### 3. Database Impact Analysis
142
+ - Detects database operations across ORMs:
143
+ - Prisma
144
+ - TypeORM
145
+ - Sequelize
146
+ - Identifies affected tables and fields
147
+ - Lists database operations (CREATE, UPDATE, DELETE, etc.)
148
+ - Checks for migration files
149
+ - Shows sample queries
150
+
151
+ ### 4. Pages/Components Detection
152
+ - Automatically detects UI changes
153
+ - Supports:
154
+ - Pages (React, Next.js, Vue, etc.)
155
+ - Components
156
+ - Views
157
+ - Screens (React Native)
158
+ - Groups by type for easy review
159
+ - Shows status and line changes
160
+
161
+ ### 5. Logic Impact Analysis
162
+ - Builds dependency graphs
163
+ - Finds direct and indirect callers of changed functions
164
+ - Calculates risk levels based on impact scope
165
+ - Detects control flow changes
166
+
167
+ ### 7. Comprehensive Reporting
168
+ - **Markdown Reports** - Formatted, readable reports with tables and sections
169
+ - **JSON Reports** - Machine-readable output for CI/CD integration
170
+ - **Console Output** - Quick summary with color-coded severity
171
+ - **Impact Scoring** - Numerical score based on change magnitude
172
+
173
+ ## Configuration
174
+
175
+ ### Command Line Options
176
+
177
+ ```bash
178
+ node index.js [OPTIONS]
179
+ ```
180
+
181
+ | Option | Description | Default |
182
+ |--------|-------------|---------|
183
+ | `--input=DIR` | Source directory to analyze | `src` |
184
+ | `--base=REF` | Base git reference (branch/commit) | `origin/main` |
185
+ | `--head=REF` | Head git reference (branch/commit) | `HEAD` |
186
+ | `--exclude=PATHS` | Comma-separated paths to exclude | `node_modules,dist,build,specs,coverage` |
187
+ | `--output=FILE` | Output markdown file path | `impact-report.md` |
188
+ | `--json=FILE` | Optional JSON output file | - |
189
+ | `--max-depth=N` | Maximum dependency traversal depth | `3` |
190
+ | `--include-tests` | Include test files in analysis | `false` |
191
+ | `--no-fail` | Don't exit with error on critical impact | `false` |
192
+ | `--verbose` | Show verbose output | `false` |
193
+
194
+ ### Configuration File
195
+
196
+ Default configuration in `config/default-config.js`:
197
+
198
+ ```javascript
199
+ {
200
+ sourceDir: 'src',
201
+ excludePaths: ['node_modules', 'dist', 'build', 'specs', 'coverage'],
202
+ baseRef: 'origin/main',
203
+ headRef: 'HEAD',
204
+ maxDepth: 3,
205
+ includeTests: false,
206
+ verbose: false,
207
+ outputFormat: 'markdown',
208
+ outputFile: 'impact-report.md'
209
+ }
210
+ ```
211
+
212
+ ### Environment Setup
213
+
214
+ 1. **Prerequisites**
215
+ - Node.js 16+
216
+ - Git repository
217
+ - npm or yarn
218
+
219
+ 2. **Installation**
220
+ ```bash
221
+ cd impact-analyzer
222
+ npm install
223
+ # or
224
+ yarn install
225
+ ```
226
+
227
+ ## Usage
228
+
229
+ ### Basic Usage
230
+
231
+ Analyze changes between current branch and main:
232
+
233
+ ```bash
234
+ node index.js --input=src --base=origin/main --head=HEAD
235
+ ```
236
+
237
+ ### Using the Shell Script
238
+
239
+ The included shell script provides a convenient wrapper:
240
+
241
+ ```bash
242
+ # Make it executable
243
+ chmod +x run-impact-analysis.sh
244
+
245
+ # Run with defaults
246
+ ./run-impact-analysis.sh
247
+
248
+ # Run with custom options
249
+ ./run-impact-analysis.sh --input=src --base=origin/develop --output=report.md
250
+ ```
251
+
252
+ ### NPM Scripts
253
+
254
+ ```bash
255
+ # Analyze local changes
256
+ npm run analyze:local
257
+
258
+ # Custom analysis
259
+ npm run analyze -- --input=src --base=main --json=impact.json
260
+ ```
261
+
262
+ ### Common Scenarios
263
+
264
+ #### 1. Analyze PR Changes
265
+
266
+ ```bash
267
+ # Compare feature branch against main
268
+ node index.js \
269
+ --input=src \
270
+ --base=origin/main \
271
+ --head=HEAD \
272
+ --output=pr-impact.md
273
+ ```
274
+
275
+ #### 2. Analyze Specific Commit Range
276
+
277
+ ```bash
278
+ # Compare two commits
279
+ node index.js \
280
+ --input=src \
281
+ --base=abc123 \
282
+ --head=def456 \
283
+ --output=commit-impact.md
284
+ ```
285
+
286
+ #### 3. Generate JSON Report for CI/CD
287
+
288
+ ```bash
289
+ # Generate both markdown and JSON
290
+ node index.js \
291
+ --input=src \
292
+ --base=origin/main \
293
+ --head=HEAD \
294
+ --output=impact-report.md \
295
+ --json=impact-report.json
296
+ ```
297
+
298
+ #### 4. Analyze with Verbose Output
299
+
300
+ ```bash
301
+ # Show detailed logs
302
+ node index.js \
303
+ --input=src \
304
+ --base=origin/main \
305
+ --verbose
306
+ ```
307
+
308
+ #### 5. Continue on Critical Impact
309
+
310
+ ```bash
311
+ # Don't fail CI on critical severity
312
+ node index.js \
313
+ --input=src \
314
+ --base=origin/main \
315
+ --no-fail
316
+ ```
317
+
318
+ ### CI/CD Integration
319
+
320
+ #### GitHub Actions Example
321
+
322
+ ```yaml
323
+ name: Impact Analysis
324
+
325
+ on:
326
+ pull_request:
327
+ branches: [main, develop]
328
+
329
+ jobs:
330
+ analyze:
331
+ runs-on: ubuntu-latest
332
+ steps:
333
+ - uses: actions/checkout@v3
334
+ with:
335
+ fetch-depth: 0
336
+
337
+ - name: Setup Node.js
338
+ uses: actions/setup-node@v3
339
+ with:
340
+ node-version: '18'
341
+
342
+ - name: Install Dependencies
343
+ run: |
344
+ cd impact-analyzer
345
+ npm install
346
+
347
+ - name: Run Impact Analysis
348
+ run: |
349
+ cd impact-analyzer
350
+ node index.js \
351
+ --input=../src \
352
+ --base=origin/${{ github.base_ref }} \
353
+ --head=HEAD \
354
+ --output=impact-report.md \
355
+ --json=impact-report.json
356
+
357
+ - name: Upload Report
358
+ uses: actions/upload-artifact@v3
359
+ with:
360
+ name: impact-report
361
+ path: impact-analyzer/impact-report.md
362
+
363
+ - name: Comment PR
364
+ uses: actions/github-script@v6
365
+ with:
366
+ script: |
367
+ const fs = require('fs');
368
+ const report = fs.readFileSync('impact-analyzer/impact-report.md', 'utf8');
369
+ github.rest.issues.createComment({
370
+ issue_number: context.issue.number,
371
+ owner: context.repo.owner,
372
+ repo: context.repo.repo,
373
+ body: report
374
+ });
375
+ ```
376
+
377
+ #### GitLab CI Example
378
+
379
+ ```yaml
380
+ impact_analysis:
381
+ stage: test
382
+ script:
383
+ - cd impact-analyzer
384
+ - npm install
385
+ - |
386
+ node index.js \
387
+ --input=../src \
388
+ --base=origin/main \
389
+ --head=HEAD \
390
+ --output=impact-report.md \
391
+ --json=impact-report.json
392
+ artifacts:
393
+ paths:
394
+ - impact-analyzer/impact-report.md
395
+ - impact-analyzer/impact-report.json
396
+ reports:
397
+ dotenv: impact-analyzer/impact-report.json
398
+ ```
399
+
400
+ ### Reading the Report
401
+
402
+ The generated report includes:
403
+
404
+ 1. **πŸ“Š Summary** - Overview of changes and severity
405
+ 2. **πŸ“‘ Affected API Endpoints** - List of impacted APIs grouped by controller
406
+ 3. **πŸ’Ύ Database Impact** - Tables, fields, and operations affected
407
+ 4. **πŸ“„ Affected Pages/Components** - UI changes grouped by type
408
+ 5. **πŸ”„ Logic Impact** - Call dependencies and risk level
409
+ 6. **βœ… Recommended Test Cases** - Suggested tests based on changes
410
+ 7. **πŸ“ Changed Files** - Complete list of modified files
411
+
412
+ #### Severity Levels
413
+
414
+ - 🟒 **LOW** (0-20 points) - Minor changes, low risk
415
+ - 🟑 **MEDIUM** (21-50 points) - Moderate impact, standard testing required
416
+ - 🟠 **HIGH** (51-100 points) - Significant impact, thorough testing needed
417
+ - πŸ”΄ **CRITICAL** (100+ points) - Major changes, full regression testing recommended
418
+
419
+ #### Impact Scoring
420
+
421
+ The impact score is calculated based on:
422
+ - Affected endpoints: +10 points each
423
+ - Database tables impacted: +5 points each
424
+ - Direct function callers: +3 points each
425
+ - Indirect function callers: +1 point each
426
+ - High risk logic: 1.5x multiplier
427
+ - Database migration: +20 points
428
+
429
+ ### Example Output
430
+
431
+ ```markdown
432
+ # πŸ” Impact Analysis Report
433
+
434
+ ## πŸ“Š Summary
435
+
436
+ | Metric | Value |
437
+ |--------|-------|
438
+ | Files Changed | 5 |
439
+ | Symbols Modified | 12 |
440
+ | Impact Score | **45** |
441
+ | Severity | 🟑 **MEDIUM** |
442
+
443
+ ## πŸ“‘ Affected API Endpoints
444
+
445
+ **Total Endpoints Affected:** 3
446
+
447
+ ### Endpoint List
448
+ | Method | Path | Controller | Impact |
449
+ |--------|------|------------|--------|
450
+ | **GET** | `/api/users` | UserController | 🟑 medium |
451
+ | **POST** | `/api/users` | UserController | πŸ”΄ high |
452
+
453
+ ## πŸ’Ύ Database Impact
454
+
455
+ **Total Tables Affected:** 2
456
+
457
+ ### Tables Summary
458
+ | Table | Operations | Fields Count | Migration |
459
+ |-------|------------|--------------|-----------|
460
+ | `users` | UPDATE | 3 | βœ… Yes |
461
+ | `profiles` | CREATE, UPDATE | 5 | ❌ No |
462
+ ```
463
+
464
+ ## Troubleshooting
465
+
466
+ ### Common Issues
467
+
468
+ 1. **"Source directory does not exist"**
469
+ - Ensure the `--input` path is correct and relative to the analyzer directory
470
+
471
+ 2. **"Base ref does not exist"**
472
+ - Run `git fetch` to ensure remote branches are up to date
473
+ - Verify the branch/commit exists: `git show origin/main`
474
+
475
+ 3. **"No changes detected"**
476
+ - Check if there are actual differences: `git diff origin/main HEAD`
477
+ - Ensure you're in a git repository
478
+
479
+ 4. **Parse errors for certain files**
480
+ - The analyzer uses Babel parser with common plugins
481
+ - Some experimental syntax may not be supported
482
+ - These files will be logged and skipped
483
+
484
+ ### Debug Mode
485
+
486
+ Run with verbose flag to see detailed logs:
487
+
488
+ ```bash
489
+ node index.js --input=src --base=origin/main --verbose
490
+ ```
491
+
492
+ ## Contributing
493
+
494
+ Contributions are welcome! Please ensure:
495
+ - Code follows existing style (no spaces after dots)
496
+ - All functions have single responsibility
497
+ - Use descriptive variable and function names
498
+ - Add tests for new features
499
+
500
+ ## License
501
+
502
+ MIT
503
+
504
+ ## Support
505
+
506
+ For issues, questions, or suggestions, please create an issue in the repository.
package/cli.js ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * CLI - Command Line Interface Parser
3
+ * Handles argument parsing and validation
4
+ */
5
+
6
+ export class CLI {
7
+ constructor(argv) {
8
+ this.args = new Map();
9
+ this.parseArgs(argv);
10
+ }
11
+
12
+ parseArgs(argv) {
13
+ for (let i = 2; i < argv.length; i++) {
14
+ const arg = argv[i];
15
+
16
+ if (arg.startsWith('--')) {
17
+ const [key, value] = arg.substring(2).split('=');
18
+ this.args.set(key, value || 'true');
19
+ } else if (arg.startsWith('-')) {
20
+ // Short flags
21
+ const key = arg.substring(1);
22
+ this.args.set(key, 'true');
23
+ }
24
+ }
25
+ }
26
+
27
+ getArg(key, defaultValue = '') {
28
+ return this.args.get(key) || defaultValue;
29
+ }
30
+
31
+ hasArg(key) {
32
+ return this.args.has(key);
33
+ }
34
+
35
+ getAllArgs() {
36
+ return Object.fromEntries(this.args);
37
+ }
38
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Configuration Loader
3
+ * Loads and validates configuration from CLI args and defaults
4
+ */
5
+
6
+ export function loadConfig(cli) {
7
+ const config = {
8
+ // Source directory to analyze
9
+ sourceDir: cli.getArg('input', 'src'),
10
+
11
+ // Paths to exclude from analysis
12
+ excludePaths: cli.getArg('exclude', 'node_modules,dist,build,specs,coverage')
13
+ .split(',')
14
+ .map(p => p.trim()),
15
+
16
+ // Git references
17
+ baseRef: cli.getArg('base', 'origin/main'),
18
+ headRef: cli.getArg('head', 'HEAD'),
19
+
20
+ // Analysis options
21
+ maxDepth: parseInt(cli.getArg('max-depth', '3')),
22
+ includeTests: cli.hasArg('include-tests'),
23
+ verbose: cli.hasArg('verbose'),
24
+
25
+ // Report options
26
+ outputFormat: cli.getArg('format', 'markdown'),
27
+ outputFile: cli.getArg('output', 'impact-report.md'),
28
+ };
29
+
30
+ // Validate configuration
31
+ validateConfig(config);
32
+
33
+ return config;
34
+ }
35
+
36
+ function validateConfig(config) {
37
+ if (!config.sourceDir) {
38
+ throw new Error('Source directory (--input) is required');
39
+ }
40
+
41
+ if (!config.baseRef || !config.headRef) {
42
+ throw new Error('Git references (--base and --head) are required');
43
+ }
44
+ }
45
+
46
+ export const DEFAULT_CONFIG = {
47
+ sourceDir: 'src',
48
+ excludePaths: ['node_modules', 'dist', 'build', 'specs', 'coverage'],
49
+ baseRef: 'origin/main',
50
+ headRef: 'HEAD',
51
+ maxDepth: 3,
52
+ includeTests: false,
53
+ verbose: false,
54
+ outputFormat: 'markdown',
55
+ outputFile: 'impact-report.md',
56
+ };