gitlab-auto-reviewers 2.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.
Files changed (119) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1878 -0
  3. package/dist/api/gitlab-api.d.ts +136 -0
  4. package/dist/api/gitlab-api.d.ts.map +1 -0
  5. package/dist/api/gitlab-api.js +334 -0
  6. package/dist/api/gitlab-api.js.map +1 -0
  7. package/dist/bin/cli.d.ts +10 -0
  8. package/dist/bin/cli.d.ts.map +1 -0
  9. package/dist/bin/cli.js +186 -0
  10. package/dist/bin/cli.js.map +1 -0
  11. package/dist/bin/deprecated-mcp.d.ts +12 -0
  12. package/dist/bin/deprecated-mcp.d.ts.map +1 -0
  13. package/dist/bin/deprecated-mcp.js +73 -0
  14. package/dist/bin/deprecated-mcp.js.map +1 -0
  15. package/dist/bin/index.d.ts +18 -0
  16. package/dist/bin/index.d.ts.map +1 -0
  17. package/dist/bin/index.js +78 -0
  18. package/dist/bin/index.js.map +1 -0
  19. package/dist/bin/mcp.d.ts +11 -0
  20. package/dist/bin/mcp.d.ts.map +1 -0
  21. package/dist/bin/mcp.js +43 -0
  22. package/dist/bin/mcp.js.map +1 -0
  23. package/dist/cache/cache.service.d.ts +113 -0
  24. package/dist/cache/cache.service.d.ts.map +1 -0
  25. package/dist/cache/cache.service.js +213 -0
  26. package/dist/cache/cache.service.js.map +1 -0
  27. package/dist/cli/commands.d.ts +40 -0
  28. package/dist/cli/commands.d.ts.map +1 -0
  29. package/dist/cli/commands.js +142 -0
  30. package/dist/cli/commands.js.map +1 -0
  31. package/dist/cli/output.d.ts +24 -0
  32. package/dist/cli/output.d.ts.map +1 -0
  33. package/dist/cli/output.js +143 -0
  34. package/dist/cli/output.js.map +1 -0
  35. package/dist/config/config.service.d.ts +89 -0
  36. package/dist/config/config.service.d.ts.map +1 -0
  37. package/dist/config/config.service.js +169 -0
  38. package/dist/config/config.service.js.map +1 -0
  39. package/dist/datasources/git-data-source.interface.d.ts +140 -0
  40. package/dist/datasources/git-data-source.interface.d.ts.map +1 -0
  41. package/dist/datasources/git-data-source.interface.js +2 -0
  42. package/dist/datasources/git-data-source.interface.js.map +1 -0
  43. package/dist/datasources/gitlab-api-data-source.d.ts +127 -0
  44. package/dist/datasources/gitlab-api-data-source.d.ts.map +1 -0
  45. package/dist/datasources/gitlab-api-data-source.js +248 -0
  46. package/dist/datasources/gitlab-api-data-source.js.map +1 -0
  47. package/dist/datasources/local-git-data-source.d.ts +124 -0
  48. package/dist/datasources/local-git-data-source.d.ts.map +1 -0
  49. package/dist/datasources/local-git-data-source.js +580 -0
  50. package/dist/datasources/local-git-data-source.js.map +1 -0
  51. package/dist/errors/error-handler.d.ts +113 -0
  52. package/dist/errors/error-handler.d.ts.map +1 -0
  53. package/dist/errors/error-handler.js +230 -0
  54. package/dist/errors/error-handler.js.map +1 -0
  55. package/dist/index.d.ts +139 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +139 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/logging/example.d.ts +15 -0
  60. package/dist/logging/example.d.ts.map +1 -0
  61. package/dist/logging/example.js +79 -0
  62. package/dist/logging/example.js.map +1 -0
  63. package/dist/logging/index.d.ts +7 -0
  64. package/dist/logging/index.d.ts.map +1 -0
  65. package/dist/logging/index.js +7 -0
  66. package/dist/logging/index.js.map +1 -0
  67. package/dist/logging/logger.service.d.ts +98 -0
  68. package/dist/logging/logger.service.d.ts.map +1 -0
  69. package/dist/logging/logger.service.js +160 -0
  70. package/dist/logging/logger.service.js.map +1 -0
  71. package/dist/mcp/server.d.ts +67 -0
  72. package/dist/mcp/server.d.ts.map +1 -0
  73. package/dist/mcp/server.js +213 -0
  74. package/dist/mcp/server.js.map +1 -0
  75. package/dist/mcp/tools.d.ts +22 -0
  76. package/dist/mcp/tools.d.ts.map +1 -0
  77. package/dist/mcp/tools.js +176 -0
  78. package/dist/mcp/tools.js.map +1 -0
  79. package/dist/services/blacklist.service.d.ts +32 -0
  80. package/dist/services/blacklist.service.d.ts.map +1 -0
  81. package/dist/services/blacklist.service.js +59 -0
  82. package/dist/services/blacklist.service.js.map +1 -0
  83. package/dist/services/codeowners.service.d.ts +45 -0
  84. package/dist/services/codeowners.service.d.ts.map +1 -0
  85. package/dist/services/codeowners.service.js +200 -0
  86. package/dist/services/codeowners.service.js.map +1 -0
  87. package/dist/services/comment-builder.service.d.ts +48 -0
  88. package/dist/services/comment-builder.service.d.ts.map +1 -0
  89. package/dist/services/comment-builder.service.js +61 -0
  90. package/dist/services/comment-builder.service.js.map +1 -0
  91. package/dist/services/contributors.service.d.ts +52 -0
  92. package/dist/services/contributors.service.d.ts.map +1 -0
  93. package/dist/services/contributors.service.js +144 -0
  94. package/dist/services/contributors.service.js.map +1 -0
  95. package/dist/services/reviewer-service.d.ts +125 -0
  96. package/dist/services/reviewer-service.d.ts.map +1 -0
  97. package/dist/services/reviewer-service.js +554 -0
  98. package/dist/services/reviewer-service.js.map +1 -0
  99. package/dist/services/team-members.service.d.ts +29 -0
  100. package/dist/services/team-members.service.d.ts.map +1 -0
  101. package/dist/services/team-members.service.js +45 -0
  102. package/dist/services/team-members.service.js.map +1 -0
  103. package/dist/services/whitelist.service.d.ts +31 -0
  104. package/dist/services/whitelist.service.d.ts.map +1 -0
  105. package/dist/services/whitelist.service.js +51 -0
  106. package/dist/services/whitelist.service.js.map +1 -0
  107. package/dist/tools.d.ts +22 -0
  108. package/dist/tools.d.ts.map +1 -0
  109. package/dist/tools.js +176 -0
  110. package/dist/tools.js.map +1 -0
  111. package/dist/types/index.d.ts +502 -0
  112. package/dist/types/index.d.ts.map +1 -0
  113. package/dist/types/index.js +91 -0
  114. package/dist/types/index.js.map +1 -0
  115. package/dist/types.d.ts +219 -0
  116. package/dist/types.d.ts.map +1 -0
  117. package/dist/types.js +7 -0
  118. package/dist/types.js.map +1 -0
  119. package/package.json +71 -0
package/README.md ADDED
@@ -0,0 +1,1878 @@
1
+ # GitLab Auto Reviewers
2
+
3
+ A shared library for intelligent GitLab merge request reviewer suggestions. Provides MCP server, CLI, and library modes for analyzing git blame data, team member availability with FTE-aware load balancing, CODEOWNERS rules, and current reviewer workload to suggest the most appropriate reviewers.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Installation](#installation)
8
+ - [Quick Start](#quick-start)
9
+ - [What's New in v2.0](#whats-new-in-v20)
10
+ - [Features](#features)
11
+ - [Architecture](#architecture)
12
+ - [Configuration](#configuration)
13
+ - [Tools](#tools)
14
+ - [CLI Usage](#cli-usage)
15
+ - [Library Usage](#library-usage)
16
+ - [Data Source Comparison](#data-source-comparison)
17
+ - [Webhook Integration](#webhook-integration)
18
+ - [MCP Integration](#mcp-integration)
19
+ - [Team Configuration](#team-configuration)
20
+ - [Code Owners](#code-owners)
21
+ - [Known Limitations](#known-limitations)
22
+ - [Troubleshooting](#troubleshooting)
23
+ - [Development](#development)
24
+ - [Contributing](#contributing)
25
+ - [Migration from v1.x](#migration-from-v1x)
26
+ - [Documentation](#documentation)
27
+
28
+ ## Installation
29
+
30
+ Install the package from npm:
31
+
32
+ ```bash
33
+ npm install gitlab-auto-reviewers
34
+ ```
35
+
36
+ ## Quick Start
37
+
38
+ The package supports three execution modes:
39
+
40
+ ### MCP Server Mode
41
+
42
+ Run as an MCP server for AI assistants:
43
+
44
+ ```bash
45
+ # MCP Server mode
46
+ npx gitlab-auto-reviewers mcp
47
+
48
+ # Or using the deprecated command (backward compatibility)
49
+ npx auto-reviewers-mcp-server
50
+ ```
51
+
52
+ Or add it to your MCP configuration (see [MCP Integration](#mcp-integration) section below).
53
+
54
+ ### CLI Mode
55
+
56
+ Use the command-line interface for local analysis:
57
+
58
+ ```bash
59
+ # Analyze a merge request by IID
60
+ npx gitlab-auto-reviewers cli --project my-group/my-project --mr 123
61
+
62
+ # Analyze a branch
63
+ npx gitlab-auto-reviewers cli --project my-group/my-project --branch feature/new-feature
64
+
65
+ # Output as JSON
66
+ npx gitlab-auto-reviewers cli --project my-group/my-project --mr 123 --format json
67
+
68
+ # Use local git repository (faster, works offline)
69
+ npx gitlab-auto-reviewers cli --repo-path /path/to/repo --mr 123
70
+ ```
71
+
72
+ See [CLI Usage](#cli-usage) section for detailed documentation.
73
+
74
+ ### Library Mode
75
+
76
+ Import and use as a library in your Node.js application:
77
+
78
+ ```typescript
79
+ import { ReviewerService, GitLabAPIDataSource } from 'gitlab-auto-reviewers';
80
+
81
+ const dataSource = new GitLabAPIDataSource(gitlabToken, gitlabUrl);
82
+ const service = new ReviewerService(dataSource);
83
+
84
+ const suggestions = await service.suggestReviewers({
85
+ project: 'my-group/my-project',
86
+ mergeRequestIid: 123
87
+ });
88
+ ```
89
+
90
+ See [Library Usage](#library-usage) section for detailed documentation.
91
+
92
+ ## What's New in v2.0
93
+
94
+ Version 2.0 brings significant improvements to reliability, performance, and developer experience:
95
+
96
+ ### 🚀 Performance Improvements
97
+ - **In-memory caching** with configurable TTL (default 5 minutes)
98
+ - **Parallel data fetching** for independent operations
99
+ - **Automatic retry logic** with exponential backoff
100
+ - Up to **5x faster** response times with caching enabled
101
+
102
+ ### 🛡️ Reliability Enhancements
103
+ - **Automatic retry** for transient failures (network errors, rate limits)
104
+ - **Smart error classification** (retryable vs. permanent)
105
+ - **Graceful degradation** with partial results on partial failures
106
+ - **Configuration validation** on startup with clear error messages
107
+
108
+ ### 🔍 Developer Experience
109
+ - **Full TypeScript strict mode** with zero `any` types
110
+ - **Structured logging** with DEBUG, INFO, WARN, ERROR levels
111
+ - **Performance metrics** tracking for all operations
112
+ - **Enhanced error messages** with context and suggestions
113
+ - **Comprehensive documentation** including migration and troubleshooting guides
114
+
115
+ ### 📊 Observability
116
+ - **Cache statistics** (hit rate, size, performance)
117
+ - **Operation timing** for performance monitoring
118
+ - **Debug mode** with detailed diagnostic information
119
+ - **Contextual logging** for easier troubleshooting
120
+
121
+ ### 🔧 Configuration
122
+ - **Centralized configuration** management
123
+ - **Environment variable** support with validation
124
+ - **Default values** with logging
125
+ - **Multiple configuration profiles** (development, production, etc.)
126
+
127
+ See [MIGRATION.md](./MIGRATION.md) for detailed upgrade instructions.
128
+
129
+ ## Features
130
+
131
+ ### Core Functionality
132
+
133
+ - **Intelligent Reviewer Suggestions**: Automatically suggest reviewers based on multiple factors
134
+ - Git blame analysis of changed files to find previous contributors
135
+ - Team member availability with FTE-aware load balancing
136
+ - Code ownership rules from CODEOWNERS file
137
+ - Current reviewer workload across open merge requests
138
+
139
+ - **Dual Data Source Support**: Works with both GitLab API and local git repositories
140
+ - **API Mode**: Fetches data from GitLab API (requires network access)
141
+ - **Local Git Mode**: Analyzes local repository (faster, works offline)
142
+
143
+ ### Performance & Reliability (New in v2.0)
144
+
145
+ - **In-Memory Caching**: Configurable caching with TTL support
146
+ - Reduces API calls and improves response times
147
+ - Automatic cache invalidation
148
+ - Cache statistics tracking
149
+
150
+ - **Automatic Retry Logic**: Resilient error handling
151
+ - Exponential backoff for transient failures
152
+ - Configurable retry attempts and delays
153
+ - Smart classification of retryable vs. permanent errors
154
+
155
+ - **Parallel Operations**: Concurrent data fetching
156
+ - Multiple API requests in parallel
157
+ - Configurable concurrency limits
158
+ - Significantly faster response times
159
+
160
+ ### Developer Experience (New in v2.0)
161
+
162
+ - **Type Safety**: Full TypeScript strict mode
163
+ - Zero `any` types in production code
164
+ - Comprehensive type definitions
165
+ - Type guards for runtime validation
166
+
167
+ - **Structured Logging**: Multi-level logging system
168
+ - DEBUG, INFO, WARN, ERROR levels
169
+ - Contextual information in all logs
170
+ - Performance metrics tracking
171
+ - Easy debugging and monitoring
172
+
173
+ - **Configuration Management**: Centralized configuration
174
+ - Environment variable support
175
+ - Validation on startup with clear error messages
176
+ - Default values with logging
177
+ - Runtime configuration access
178
+
179
+ - **Enhanced Error Messages**: Clear, actionable errors
180
+ - Error codes for programmatic handling
181
+ - Detailed context and suggestions
182
+ - Stack traces in debug mode
183
+
184
+ ## Architecture
185
+
186
+ ### System Overview
187
+
188
+ ```
189
+ ┌─────────────────────────────────────────────────────────────────┐
190
+ │ gitlab-auto-reviewers │
191
+ │ (npm package) │
192
+ ├─────────────────────────────────────────────────────────────────┤
193
+ │ │
194
+ │ ┌────────────────┐ ┌────────────────┐ ┌────────────────┐ │
195
+ │ │ MCP Server │ │ CLI │ │ Shared Library │ │
196
+ │ │ (bin/mcp) │ │ (bin/cli) │ │ (exports) │ │
197
+ │ └────────┬───────┘ └────────┬───────┘ └────────┬───────┘ │
198
+ │ │ │ │ │
199
+ │ └───────────────────┴────────────────────┘ │
200
+ │ │ │
201
+ │ ┌───────────────────────────┴──────────────────────────────┐ │
202
+ │ │ Core Services & Data Sources │ │
203
+ │ ├───────────────────────────────────────────────────────────┤ │
204
+ │ │ • ReviewerService │ │
205
+ │ │ • ContributorsService │ │
206
+ │ │ • CodeownersService │ │
207
+ │ │ • TeamMembersService │ │
208
+ │ │ • CommentBuilderService │ │
209
+ │ ├───────────────────────────────────────────────────────────┤ │
210
+ │ │ Data Sources: │ │
211
+ │ │ • GitLabAPIDataSource (API-based, stateless) │ │
212
+ │ │ • LocalGitDataSource (local repo, faster) │ │
213
+ │ └───────────────────────────────────────────────────────────┘ │
214
+ └─────────────────────────────────────────────────────────────────┘
215
+
216
+ │ imported by
217
+
218
+ ┌─────────────────────────────────────────────────────────────────┐
219
+ │ oce-gitlab-mr-bot │
220
+ │ (NestJS Application) │
221
+ ├─────────────────────────────────────────────────────────────────┤
222
+ │ ┌────────────────────────────────────────────────────────┐ │
223
+ │ │ B2B-MFE Webhook Module │ │
224
+ │ │ • Controller (receives GitLab webhook events) │ │
225
+ │ │ • Service (uses gitlab-auto-reviewers library) │ │
226
+ │ │ • Type Guards (validates webhook payloads) │ │
227
+ │ └────────────────────────────────────────────────────────┘ │
228
+ └─────────────────────────────────────────────────────────────────┘
229
+ ```
230
+
231
+ ### Component Responsibilities
232
+
233
+ - **MCP Server**: Handles MCP protocol communication and tool routing
234
+ - **Config Service**: Centralized configuration management with validation
235
+ - **Logger Service**: Structured logging with appropriate log levels
236
+ - **Error Handler**: Consistent error handling with retry logic
237
+ - **Cache Service**: Optional in-memory caching for performance
238
+ - **Reviewer Service**: Core business logic for reviewer suggestions
239
+ - **Data Sources**: Abstract data access (API or local git)
240
+
241
+ ## Configuration
242
+
243
+ The server can be configured through environment variables or tool parameters.
244
+
245
+ ### Environment Variables
246
+
247
+ | Variable | Description | Default | Required |
248
+ |----------|-------------|---------|----------|
249
+ | `GITLAB_TOKEN` | GitLab API token | - | Yes* |
250
+ | `GITLAB_URL` | GitLab instance URL | `https://gitlab.com` | No |
251
+ | `REPO_PATH` | Local repository path | Auto-detected | No |
252
+ | `CACHE_ENABLED` | Enable in-memory caching | `true` | No |
253
+ | `CACHE_TTL` | Cache TTL in milliseconds | `300000` (5 min) | No |
254
+ | `MAX_PARALLEL_REQUESTS` | Max parallel API requests | `5` | No |
255
+ | `CONTRIBUTOR_DAYS` | Days to analyze for contributors | `365` | No |
256
+ | `MAX_RETRIES` | Max retry attempts for failures | `3` | No |
257
+ | `RETRY_DELAY_MS` | Initial retry delay in ms | `1000` | No |
258
+ | `LOG_LEVEL` | Logging level | `info` | No |
259
+ | `DEBUG` | Enable debug mode | `false` | No |
260
+
261
+ *Can be provided as tool parameter instead
262
+
263
+ ### Configuration File
264
+
265
+ Create a `.env` file in your project root:
266
+
267
+ ```bash
268
+ # GitLab Configuration
269
+ GITLAB_TOKEN=your_gitlab_token_here
270
+ GITLAB_URL=https://gitlab.com
271
+
272
+ # Performance Configuration
273
+ CACHE_ENABLED=true
274
+ CACHE_TTL=300000
275
+ MAX_PARALLEL_REQUESTS=5
276
+
277
+ # Git Configuration
278
+ CONTRIBUTOR_DAYS=365
279
+ MAX_RETRIES=3
280
+ RETRY_DELAY_MS=1000
281
+
282
+ # Logging Configuration
283
+ LOG_LEVEL=info
284
+ DEBUG=false
285
+ ```
286
+
287
+ ### Configuration Examples
288
+
289
+ #### High Performance Setup
290
+ ```bash
291
+ # Optimized for speed with aggressive caching
292
+ CACHE_ENABLED=true
293
+ CACHE_TTL=600000 # 10 minutes
294
+ MAX_PARALLEL_REQUESTS=10 # More concurrent requests
295
+ CONTRIBUTOR_DAYS=90 # Shorter analysis window
296
+ MAX_RETRIES=2 # Fewer retries
297
+ ```
298
+
299
+ #### Development Setup
300
+ ```bash
301
+ # Optimized for debugging
302
+ CACHE_ENABLED=false # Disable cache for fresh data
303
+ LOG_LEVEL=debug # Detailed logging
304
+ DEBUG=true # Enable debug mode
305
+ MAX_RETRIES=1 # Fail fast
306
+ ```
307
+
308
+ #### Production Setup
309
+ ```bash
310
+ # Balanced for reliability and performance
311
+ CACHE_ENABLED=true
312
+ CACHE_TTL=300000 # 5 minutes
313
+ MAX_PARALLEL_REQUESTS=5 # Moderate concurrency
314
+ CONTRIBUTOR_DAYS=365 # Full year analysis
315
+ MAX_RETRIES=3 # Standard retries
316
+ LOG_LEVEL=info # Normal logging
317
+ DEBUG=false # Disable debug mode
318
+ ```
319
+
320
+ #### Offline/Local Git Setup
321
+ ```bash
322
+ # Use local git repository (no API calls)
323
+ REPO_PATH=/path/to/repo # Local repository path
324
+ CACHE_ENABLED=true # Cache git operations
325
+ CONTRIBUTOR_DAYS=180 # Moderate analysis window
326
+ LOG_LEVEL=info
327
+ ```
328
+
329
+ #### Low Memory Setup
330
+ ```bash
331
+ # Minimize memory usage
332
+ CACHE_ENABLED=false # Disable caching
333
+ MAX_PARALLEL_REQUESTS=2 # Reduce concurrency
334
+ CONTRIBUTOR_DAYS=90 # Shorter analysis
335
+ ```
336
+
337
+ ### Configuration Validation
338
+
339
+ The server validates all configuration on startup and will fail fast with clear error messages if:
340
+ - Required values are missing
341
+ - Values are invalid (e.g., negative numbers, invalid URLs)
342
+ - Values are out of acceptable ranges
343
+
344
+ Example error message:
345
+ ```
346
+ Configuration validation failed:
347
+ - GITLAB_URL is not a valid URL: not-a-url
348
+ - CACHE_TTL must be non-negative, got: -1000
349
+ - MAX_PARALLEL_REQUESTS must be at least 1, got: 0
350
+
351
+ Please check your environment variables and try again.
352
+ ```
353
+
354
+ ## Tools
355
+
356
+ The MCP server exposes the following tools for AI assistants:
357
+
358
+ ### suggest_reviewers
359
+
360
+ Suggests reviewers for a GitLab merge request based on multiple factors.
361
+
362
+ **Analysis Factors:**
363
+ - **Git blame analysis** of changed files to find previous contributors
364
+ - **Team member availability** with FTE-aware load balancing
365
+ - **Code ownership rules** from CODEOWNERS file
366
+ - **Current reviewer workload** across open merge requests
367
+
368
+ **Parameters:**
369
+
370
+ | Parameter | Type | Required | Description |
371
+ |-----------|------|----------|-------------|
372
+ | `project` | string \| number | No* | GitLab project ID or path (e.g., "group/project" or 123) |
373
+ | `mergeRequestIid` | number | No* | Merge request internal ID (IID) |
374
+ | `branch` | string | No* | Branch name (alternative to mergeRequestIid) |
375
+ | `gitlabToken` | string | No** | GitLab API token |
376
+ | `gitlabUrl` | string | No | GitLab instance URL (defaults to https://gitlab.com) |
377
+ | `repoPath` | string | No | Local repository path (auto-detected if not provided) |
378
+
379
+ *Either `mergeRequestIid` or `branch` must be provided
380
+ **Required if not set in environment variable `GITLAB_TOKEN`
381
+
382
+ **Returns:**
383
+
384
+ ```typescript
385
+ {
386
+ contributors: ReviewerSuggestion[], // Reviewers based on file contributions
387
+ teamMembers: ReviewerSuggestion[], // Reviewers based on team membership
388
+ codeOwners: ReviewerSuggestion[], // Reviewers based on CODEOWNERS
389
+ comment: string // Formatted comment for GitLab MR
390
+ }
391
+ ```
392
+
393
+ **Example:**
394
+
395
+ ```json
396
+ {
397
+ "project": "my-group/my-project",
398
+ "mergeRequestIid": 123,
399
+ "gitlabToken": "glpat-xxxxxxxxxxxx"
400
+ }
401
+ ```
402
+
403
+ ### get_contributor_analysis
404
+
405
+ Provides detailed analysis of who contributed to the changed files using git blame.
406
+
407
+ **Parameters:**
408
+
409
+ | Parameter | Type | Required | Description |
410
+ |-----------|------|----------|-------------|
411
+ | `project` | string \| number | Yes | GitLab project ID or path |
412
+ | `mergeRequestIid` | number | Yes | Merge request internal ID |
413
+ | `gitlabToken` | string | No* | GitLab API token |
414
+ | `gitlabUrl` | string | No | GitLab instance URL |
415
+
416
+ *Required if not set in environment variable `GITLAB_TOKEN`
417
+
418
+ **Returns:**
419
+
420
+ ```typescript
421
+ {
422
+ files: Array<{
423
+ path: string,
424
+ contributors: Array<{
425
+ username: string,
426
+ email: string,
427
+ lineCount: number
428
+ }>
429
+ }>
430
+ }
431
+ ```
432
+
433
+ **Example:**
434
+
435
+ ```json
436
+ {
437
+ "project": 123,
438
+ "mergeRequestIid": 456
439
+ }
440
+ ```
441
+
442
+ ### get_reviewer_workload
443
+
444
+ Analyzes current workload of potential reviewers across open merge requests.
445
+
446
+ **Parameters:**
447
+
448
+ | Parameter | Type | Required | Description |
449
+ |-----------|------|----------|-------------|
450
+ | `project` | string \| number | Yes | GitLab project ID or path |
451
+ | `gitlabToken` | string | No* | GitLab API token |
452
+ | `gitlabUrl` | string | No | GitLab instance URL |
453
+
454
+ *Required if not set in environment variable `GITLAB_TOKEN`
455
+
456
+ **Returns:**
457
+
458
+ ```typescript
459
+ {
460
+ reviewers: Array<{
461
+ username: string,
462
+ openMRCount: number,
463
+ fte?: number,
464
+ capacity?: number,
465
+ utilizationPercent?: number
466
+ }>
467
+ }
468
+ ```
469
+
470
+ **Example:**
471
+
472
+ ```json
473
+ {
474
+ "project": "my-group/my-project"
475
+ }
476
+ ```
477
+
478
+ ### post_comment
479
+
480
+ Posts a comment to a GitLab merge request.
481
+
482
+ **Parameters:**
483
+
484
+ | Parameter | Type | Required | Description |
485
+ |-----------|------|----------|-------------|
486
+ | `project` | string \| number | No* | GitLab project ID or path |
487
+ | `mergeRequestIid` | number | No* | Merge request internal ID |
488
+ | `branch` | string | No* | Branch name (alternative to mergeRequestIid) |
489
+ | `comment` | string | Yes | Comment text to post |
490
+ | `gitlabToken` | string | No** | GitLab API token |
491
+ | `gitlabUrl` | string | No | GitLab instance URL |
492
+ | `repoPath` | string | No | Local repository path |
493
+
494
+ *Either `mergeRequestIid` or `branch` must be provided
495
+ **Required if not set in environment variable `GITLAB_TOKEN`
496
+
497
+ **Example:**
498
+
499
+ ```json
500
+ {
501
+ "project": 123,
502
+ "mergeRequestIid": 456,
503
+ "comment": "Suggested reviewers: @alice, @bob"
504
+ }
505
+ ```
506
+
507
+ ### invite_reviewers
508
+
509
+ Invites suggested reviewers to a GitLab merge request.
510
+
511
+ **Parameters:**
512
+
513
+ | Parameter | Type | Required | Description |
514
+ |-----------|------|----------|-------------|
515
+ | `project` | string \| number | No* | GitLab project ID or path |
516
+ | `mergeRequestIid` | number | No* | Merge request internal ID |
517
+ | `branch` | string | No* | Branch name (alternative to mergeRequestIid) |
518
+ | `gitlabToken` | string | No** | GitLab API token |
519
+ | `gitlabUrl` | string | No | GitLab instance URL |
520
+ | `repoPath` | string | No | Local repository path |
521
+
522
+ *Either `mergeRequestIid` or `branch` must be provided
523
+ **Required if not set in environment variable `GITLAB_TOKEN`
524
+
525
+ **Example:**
526
+
527
+ ```json
528
+ {
529
+ "project": "my-group/my-project",
530
+ "branch": "feature/new-feature"
531
+ }
532
+ ```
533
+
534
+ ## CLI Usage
535
+
536
+ The CLI mode allows you to analyze merge requests from the command line, useful for development, CI/CD pipelines, and automation scripts.
537
+
538
+ For comprehensive CLI documentation, see [docs/CLI.md](./docs/CLI.md).
539
+
540
+ ### Quick Start
541
+
542
+ ```bash
543
+ # Analyze a merge request
544
+ npx gitlab-auto-reviewers cli --repo-path . --mr 123
545
+
546
+ # Analyze by branch name
547
+ npx gitlab-auto-reviewers cli --repo-path . --branch feature/my-feature
548
+
549
+ # Output as JSON
550
+ npx gitlab-auto-reviewers cli --repo-path . --mr 123 --format json
551
+ ```
552
+
553
+ ### Basic Options
554
+
555
+ | Option | Description | Example |
556
+ |--------|-------------|---------|
557
+ | `--repo-path <path>` | Path to local git repository | `--repo-path .` |
558
+ | `--mr <number>` | Merge request IID | `--mr 123` |
559
+ | `--branch <name>` | Branch name (alternative to --mr) | `--branch feature/new-feature` |
560
+ | `--format <type>` | Output format: `json` or `text` | `--format json` |
561
+ | `--gitlab-token <token>` | GitLab API token | `--gitlab-token glpat-xxxx` |
562
+ | `--gitlab-url <url>` | GitLab instance URL | `--gitlab-url https://gitlab.com` |
563
+ | `--verbose` | Enable verbose logging | `--verbose` |
564
+ | `--help` | Show help message | `--help` |
565
+
566
+ ### Development Environment
567
+
568
+ ```bash
569
+ # Set GitLab token
570
+ export GITLAB_TOKEN=glpat-xxxxxxxxxxxx
571
+
572
+ # Analyze current merge request
573
+ cd /path/to/your/project
574
+ gitlab-auto-reviewers cli --repo-path . --mr 123
575
+
576
+ # Enable verbose output for debugging
577
+ gitlab-auto-reviewers cli --repo-path . --mr 123 --verbose
578
+ ```
579
+
580
+ ### CI/CD Integration
581
+
582
+ #### GitLab CI
583
+
584
+ ```yaml
585
+ suggest-reviewers:
586
+ stage: review
587
+ image: node:18
588
+ script:
589
+ - npx gitlab-auto-reviewers cli --repo-path $CI_PROJECT_DIR --mr $CI_MERGE_REQUEST_IID --format json > reviewers.json
590
+ artifacts:
591
+ paths:
592
+ - reviewers.json
593
+ only:
594
+ - merge_requests
595
+ ```
596
+
597
+ #### GitHub Actions
598
+
599
+ ```yaml
600
+ - name: Suggest Reviewers
601
+ env:
602
+ GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
603
+ run: |
604
+ npx gitlab-auto-reviewers cli \
605
+ --repo-path . \
606
+ --mr ${{ github.event.pull_request.number }} \
607
+ --format json
608
+ ```
609
+
610
+ ### Output Formats
611
+
612
+ **Text Format (Default):**
613
+ ```
614
+ Suggested Reviewers for MR !123
615
+
616
+ Contributors (based on file changes):
617
+ • alice (85 points) - Contributed 45% of changed lines
618
+ • bob (60 points) - Contributed 30% of changed lines
619
+
620
+ Code Owners:
621
+ • charlie - Owner of /backend/
622
+ ```
623
+
624
+ **JSON Format:**
625
+ ```json
626
+ {
627
+ "contributors": [
628
+ {
629
+ "email": "alice@example.com",
630
+ "username": "alice",
631
+ "score": 85,
632
+ "reasons": ["Contributed 45% of changed lines"],
633
+ "isCodeowner": false,
634
+ "contributionCount": 12
635
+ }
636
+ ],
637
+ "teamMembers": [...],
638
+ "codeOwners": [...],
639
+ "comment": "## Suggested Reviewers\n\n..."
640
+ }
641
+ ```
642
+
643
+ ### Complete Documentation
644
+
645
+ For detailed CLI documentation including:
646
+ - Complete command reference
647
+ - Development environment usage patterns
648
+ - CI/CD pipeline integration examples
649
+ - Troubleshooting guide
650
+ - Performance tips
651
+ - Security considerations
652
+
653
+ See **[docs/CLI.md](./docs/CLI.md)**
654
+
655
+ ## Library Usage
656
+
657
+ Use `gitlab-auto-reviewers` as a library in your Node.js or TypeScript application.
658
+
659
+ ### Installation
660
+
661
+ ```bash
662
+ npm install gitlab-auto-reviewers
663
+ ```
664
+
665
+ ### Basic Usage
666
+
667
+ ```typescript
668
+ import {
669
+ ReviewerService,
670
+ GitLabAPIDataSource,
671
+ LocalGitDataSource
672
+ } from 'gitlab-auto-reviewers';
673
+
674
+ // Using GitLab API
675
+ const apiDataSource = new GitLabAPIDataSource(
676
+ 'glpat-xxxxxxxxxxxx', // GitLab token
677
+ 'https://gitlab.com' // GitLab URL
678
+ );
679
+
680
+ const service = new ReviewerService(apiDataSource);
681
+
682
+ const suggestions = await service.suggestReviewers({
683
+ project: 'my-group/my-project',
684
+ mergeRequestIid: 123
685
+ });
686
+
687
+ console.log(suggestions.contributors);
688
+ console.log(suggestions.teamMembers);
689
+ console.log(suggestions.codeOwners);
690
+ console.log(suggestions.comment);
691
+ ```
692
+
693
+ ### Using Local Git Repository
694
+
695
+ ```typescript
696
+ import { ReviewerService, LocalGitDataSource } from 'gitlab-auto-reviewers';
697
+
698
+ // Using local git repository (faster, works offline)
699
+ const localDataSource = new LocalGitDataSource(
700
+ '/path/to/repo', // Repository path
701
+ 'glpat-xxxxxxxxxxxx', // GitLab token (for API fallback)
702
+ 'https://gitlab.com' // GitLab URL (for API fallback)
703
+ );
704
+
705
+ const service = new ReviewerService(localDataSource);
706
+
707
+ const suggestions = await service.suggestReviewers({
708
+ project: 'my-group/my-project',
709
+ mergeRequestIid: 123
710
+ });
711
+ ```
712
+
713
+ ### Advanced Usage
714
+
715
+ #### Custom Configuration
716
+
717
+ ```typescript
718
+ import {
719
+ ReviewerService,
720
+ GitLabAPIDataSource,
721
+ ConfigService
722
+ } from 'gitlab-auto-reviewers';
723
+
724
+ // Custom configuration
725
+ const config = new ConfigService({
726
+ cacheEnabled: true,
727
+ cacheTTL: 600000, // 10 minutes
728
+ maxParallelRequests: 10,
729
+ contributorDays: 180,
730
+ maxRetries: 5,
731
+ logLevel: 'debug'
732
+ });
733
+
734
+ const dataSource = new GitLabAPIDataSource(
735
+ process.env.GITLAB_TOKEN!,
736
+ process.env.GITLAB_URL,
737
+ config
738
+ );
739
+
740
+ const service = new ReviewerService(dataSource, config);
741
+ ```
742
+
743
+ #### Error Handling
744
+
745
+ ```typescript
746
+ import {
747
+ ReviewerService,
748
+ GitLabAPIDataSource,
749
+ MCPError
750
+ } from 'gitlab-auto-reviewers';
751
+
752
+ try {
753
+ const suggestions = await service.suggestReviewers({
754
+ project: 'my-group/my-project',
755
+ mergeRequestIid: 123
756
+ });
757
+ } catch (error) {
758
+ if (error instanceof MCPError) {
759
+ console.error(`Error [${error.code}]: ${error.message}`);
760
+ console.error('Details:', error.details);
761
+
762
+ if (error.retryable) {
763
+ // Retry logic
764
+ console.log('Error is retryable, attempting retry...');
765
+ }
766
+ } else {
767
+ console.error('Unexpected error:', error);
768
+ }
769
+ }
770
+ ```
771
+
772
+ #### Filtering Reviewers
773
+
774
+ ```typescript
775
+ import {
776
+ ReviewerService,
777
+ GitLabAPIDataSource,
778
+ BlacklistService,
779
+ WhitelistService
780
+ } from 'gitlab-auto-reviewers';
781
+
782
+ const dataSource = new GitLabAPIDataSource(token, url);
783
+ const service = new ReviewerService(dataSource);
784
+
785
+ // Apply blacklist
786
+ const blacklist = new BlacklistService(dataSource);
787
+ await blacklist.load(project);
788
+
789
+ // Apply whitelist
790
+ const whitelist = new WhitelistService(dataSource);
791
+ await whitelist.load(project);
792
+
793
+ const suggestions = await service.suggestReviewers({
794
+ project: 'my-group/my-project',
795
+ mergeRequestIid: 123,
796
+ blacklist: blacklist.getBlacklist(),
797
+ whitelist: whitelist.getWhitelist()
798
+ });
799
+ ```
800
+
801
+ #### Posting Comments
802
+
803
+ ```typescript
804
+ import {
805
+ ReviewerService,
806
+ GitLabAPIDataSource,
807
+ CommentBuilderService
808
+ } from 'gitlab-auto-reviewers';
809
+
810
+ const dataSource = new GitLabAPIDataSource(token, url);
811
+ const service = new ReviewerService(dataSource);
812
+
813
+ const suggestions = await service.suggestReviewers({
814
+ project: 'my-group/my-project',
815
+ mergeRequestIid: 123
816
+ });
817
+
818
+ // Post comment to merge request
819
+ await dataSource.createNote(
820
+ 'my-group/my-project',
821
+ 123,
822
+ suggestions.comment
823
+ );
824
+ ```
825
+
826
+ ### TypeScript Types
827
+
828
+ ```typescript
829
+ import type {
830
+ ReviewerSuggestion,
831
+ ReviewerSuggestions,
832
+ MergeRequest,
833
+ User,
834
+ GitDataSource,
835
+ ConfigOptions
836
+ } from 'gitlab-auto-reviewers';
837
+
838
+ // ReviewerSuggestion
839
+ interface ReviewerSuggestion {
840
+ email: string;
841
+ username?: string;
842
+ score: number;
843
+ reasons: string[];
844
+ isCodeowner: boolean;
845
+ contributionCount?: number;
846
+ fte?: number;
847
+ openMRCount?: number;
848
+ }
849
+
850
+ // ReviewerSuggestions
851
+ interface ReviewerSuggestions {
852
+ contributors: ReviewerSuggestion[];
853
+ teamMembers: ReviewerSuggestion[];
854
+ codeOwners: ReviewerSuggestion[];
855
+ comment: string;
856
+ }
857
+ ```
858
+
859
+ ### Data Source Comparison
860
+
861
+ See [Data Source Comparison](#data-source-comparison) section for detailed comparison of GitLabAPIDataSource vs LocalGitDataSource.
862
+
863
+ ## Data Source Comparison
864
+
865
+ The package supports two data source implementations with different trade-offs:
866
+
867
+ ### GitLabAPIDataSource
868
+
869
+ **Use when:**
870
+ - Running in a stateless environment (webhooks, serverless)
871
+ - No local repository available
872
+ - Need to analyze any project without cloning
873
+ - Running in CI/CD without repository checkout
874
+
875
+ **Advantages:**
876
+ - ✅ No local repository required
877
+ - ✅ Works from anywhere with network access
878
+ - ✅ Always up-to-date with GitLab
879
+ - ✅ Stateless operation (no disk usage)
880
+ - ✅ Can analyze any project with API access
881
+
882
+ **Disadvantages:**
883
+ - ❌ Slower (network latency)
884
+ - ❌ Subject to API rate limits
885
+ - ❌ Requires network connectivity
886
+ - ❌ May hit API limits for large merge requests
887
+ - ❌ Higher API usage costs
888
+
889
+ **Configuration:**
890
+ ```typescript
891
+ import { GitLabAPIDataSource } from 'gitlab-auto-reviewers';
892
+
893
+ const dataSource = new GitLabAPIDataSource(
894
+ 'glpat-xxxxxxxxxxxx', // GitLab token
895
+ 'https://gitlab.com' // GitLab URL
896
+ );
897
+ ```
898
+
899
+ **Environment:**
900
+ ```bash
901
+ GITLAB_TOKEN=glpat-xxxxxxxxxxxx
902
+ GITLAB_URL=https://gitlab.com
903
+ ```
904
+
905
+ ### LocalGitDataSource
906
+
907
+ **Use when:**
908
+ - Running on developer machine with repository clone
909
+ - Running in CI/CD with repository checkout
910
+ - Need faster performance
911
+ - Want to work offline
912
+ - Analyzing large merge requests
913
+
914
+ **Advantages:**
915
+ - ✅ Much faster (no network latency)
916
+ - ✅ Works offline
917
+ - ✅ No API rate limits for git operations
918
+ - ✅ Can handle large merge requests
919
+ - ✅ Lower API usage
920
+
921
+ **Disadvantages:**
922
+ - ❌ Requires local repository clone
923
+ - ❌ Requires disk space
924
+ - ❌ Must keep repository up-to-date
925
+ - ❌ Falls back to API for some operations
926
+ - ❌ Requires git installed
927
+
928
+ **Configuration:**
929
+ ```typescript
930
+ import { LocalGitDataSource } from 'gitlab-auto-reviewers';
931
+
932
+ const dataSource = new LocalGitDataSource(
933
+ '/path/to/repo', // Repository path
934
+ 'glpat-xxxxxxxxxxxx', // GitLab token (for API fallback)
935
+ 'https://gitlab.com' // GitLab URL (for API fallback)
936
+ );
937
+ ```
938
+
939
+ **Environment:**
940
+ ```bash
941
+ REPO_PATH=/path/to/repo
942
+ GITLAB_TOKEN=glpat-xxxxxxxxxxxx # For API fallback
943
+ GITLAB_URL=https://gitlab.com
944
+ ```
945
+
946
+ ### Performance Comparison
947
+
948
+ | Operation | GitLabAPIDataSource | LocalGitDataSource | Speedup |
949
+ |-----------|--------------------|--------------------|---------|
950
+ | Get MR details | ~200ms | ~200ms | 1x (same) |
951
+ | Get diffs | ~300ms | ~50ms | 6x faster |
952
+ | Get blame (per file) | ~400ms | ~30ms | 13x faster |
953
+ | Get file content | ~200ms | ~10ms | 20x faster |
954
+ | **Total (typical MR)** | **~3-5s** | **~500ms-1s** | **3-5x faster** |
955
+
956
+ *Performance varies based on network latency, repository size, and number of changed files*
957
+
958
+ ### Feature Comparison
959
+
960
+ | Feature | GitLabAPIDataSource | LocalGitDataSource |
961
+ |---------|--------------------|--------------------|
962
+ | Get merge request | ✅ API | ✅ API (fallback) |
963
+ | Get diffs | ✅ API | ✅ Git command |
964
+ | Get blame | ✅ API | ✅ Git command |
965
+ | Get file content | ✅ API | ✅ Git command |
966
+ | Get contributors | ✅ API | ✅ Git command |
967
+ | Post comments | ✅ API | ✅ API (fallback) |
968
+ | Get open MRs | ✅ API | ✅ API (fallback) |
969
+ | Works offline | ❌ No | ✅ Yes (partial) |
970
+ | Requires repository | ❌ No | ✅ Yes |
971
+ | API rate limits | ⚠️ Subject to limits | ✅ Minimal API usage |
972
+
973
+ ### Choosing the Right Data Source
974
+
975
+ **Use GitLabAPIDataSource for:**
976
+ - Webhook servers (oce-gitlab-mr-bot)
977
+ - Serverless functions
978
+ - Cloud-based CI/CD without repository
979
+ - Multi-project analysis tools
980
+ - When disk space is limited
981
+
982
+ **Use LocalGitDataSource for:**
983
+ - MCP server on developer machine
984
+ - CLI usage in development
985
+ - CI/CD with repository checkout
986
+ - Large merge request analysis
987
+ - Offline development
988
+
989
+ **Hybrid Approach:**
990
+
991
+ LocalGitDataSource automatically falls back to API for operations that require it:
992
+ - Posting comments
993
+ - Getting open merge requests
994
+ - Getting project metadata
995
+
996
+ This provides the best of both worlds: fast local operations with API fallback when needed.
997
+
998
+ ### Example: Webhook Server
999
+
1000
+ ```typescript
1001
+ // oce-gitlab-mr-bot webhook service
1002
+ import { ReviewerService, GitLabAPIDataSource } from 'gitlab-auto-reviewers';
1003
+
1004
+ @Injectable()
1005
+ export class B2BMfeAutoReviewersService {
1006
+ async processWebhook(event: MergeRequestEvent): Promise<void> {
1007
+ // Use API data source (no local repository)
1008
+ const dataSource = new GitLabAPIDataSource(
1009
+ this.configService.get('GITLAB_TOKEN'),
1010
+ this.configService.get('GITLAB_URL')
1011
+ );
1012
+
1013
+ const service = new ReviewerService(dataSource);
1014
+
1015
+ const suggestions = await service.suggestReviewers({
1016
+ project: event.project.id,
1017
+ mergeRequestIid: event.object_attributes.iid
1018
+ });
1019
+
1020
+ // Post comment to MR
1021
+ await dataSource.createNote(
1022
+ event.project.id,
1023
+ event.object_attributes.iid,
1024
+ suggestions.comment
1025
+ );
1026
+ }
1027
+ }
1028
+ ```
1029
+
1030
+ ### Example: CLI Tool
1031
+
1032
+ ```typescript
1033
+ // CLI tool for local development
1034
+ import { ReviewerService, LocalGitDataSource } from 'gitlab-auto-reviewers';
1035
+
1036
+ async function analyzeMR(mrIid: number): Promise<void> {
1037
+ // Use local git data source (faster)
1038
+ const dataSource = new LocalGitDataSource(
1039
+ process.cwd(), // Current directory
1040
+ process.env.GITLAB_TOKEN,
1041
+ process.env.GITLAB_URL
1042
+ );
1043
+
1044
+ const service = new ReviewerService(dataSource);
1045
+
1046
+ const suggestions = await service.suggestReviewers({
1047
+ project: await dataSource.getProjectFromRemote(),
1048
+ mergeRequestIid: mrIid
1049
+ });
1050
+
1051
+ console.log(suggestions.comment);
1052
+ }
1053
+ ```
1054
+
1055
+ ## Webhook Integration
1056
+
1057
+ Integrate `gitlab-auto-reviewers` into your webhook server to automatically suggest reviewers when merge requests are created or updated.
1058
+
1059
+ ### NestJS Integration (oce-gitlab-mr-bot)
1060
+
1061
+ #### Step 1: Install Dependency
1062
+
1063
+ ```bash
1064
+ npm install gitlab-auto-reviewers
1065
+ ```
1066
+
1067
+ #### Step 2: Create Webhook Module
1068
+
1069
+ ```typescript
1070
+ // src/libs/b2b-mfe-auto-reviewers/b2b-mfe-auto-reviewers.module.ts
1071
+ import { Module } from '@nestjs/common';
1072
+ import { B2BMfeAutoReviewersController } from './b2b-mfe-auto-reviewers.controller';
1073
+ import { B2BMfeAutoReviewersService } from './b2b-mfe-auto-reviewers.service';
1074
+
1075
+ @Module({
1076
+ controllers: [B2BMfeAutoReviewersController],
1077
+ providers: [B2BMfeAutoReviewersService],
1078
+ })
1079
+ export class B2BMfeAutoReviewersModule {}
1080
+ ```
1081
+
1082
+ #### Step 3: Create Type Guards
1083
+
1084
+ ```typescript
1085
+ // src/libs/b2b-mfe-auto-reviewers/b2b-mfe-auto-reviewers.type-guards.ts
1086
+ import { z } from 'zod';
1087
+
1088
+ const MergeRequestEventSchema = z.object({
1089
+ object_kind: z.literal('merge_request'),
1090
+ event_type: z.literal('merge_request'),
1091
+ project: z.object({
1092
+ id: z.number(),
1093
+ path_with_namespace: z.string(),
1094
+ }),
1095
+ object_attributes: z.object({
1096
+ iid: z.number(),
1097
+ title: z.string(),
1098
+ source_branch: z.string(),
1099
+ target_branch: z.string(),
1100
+ action: z.enum(['open', 'update', 'reopen']),
1101
+ }),
1102
+ });
1103
+
1104
+ export type MergeRequestEvent = z.infer<typeof MergeRequestEventSchema>;
1105
+
1106
+ export function isMergeRequestEvent(data: unknown): data is MergeRequestEvent {
1107
+ return MergeRequestEventSchema.safeParse(data).success;
1108
+ }
1109
+ ```
1110
+
1111
+ #### Step 4: Create Service
1112
+
1113
+ ```typescript
1114
+ // src/libs/b2b-mfe-auto-reviewers/b2b-mfe-auto-reviewers.service.ts
1115
+ import { Injectable, Logger } from '@nestjs/common';
1116
+ import { ConfigService } from '@nestjs/config';
1117
+ import {
1118
+ ReviewerService,
1119
+ GitLabAPIDataSource,
1120
+ MCPError
1121
+ } from 'gitlab-auto-reviewers';
1122
+ import { MergeRequestEvent } from './b2b-mfe-auto-reviewers.type-guards';
1123
+
1124
+ @Injectable()
1125
+ export class B2BMfeAutoReviewersService {
1126
+ private readonly logger = new Logger(B2BMfeAutoReviewersService.name);
1127
+
1128
+ constructor(private readonly configService: ConfigService) {}
1129
+
1130
+ async processWebhook(event: MergeRequestEvent): Promise<void> {
1131
+ try {
1132
+ this.logger.log(
1133
+ `Processing MR webhook: ${event.project.path_with_namespace}!${event.object_attributes.iid}`
1134
+ );
1135
+
1136
+ // Create data source
1137
+ const dataSource = new GitLabAPIDataSource(
1138
+ this.configService.get<string>('GITLAB_TOKEN')!,
1139
+ this.configService.get<string>('GITLAB_URL', 'https://gitlab.com')
1140
+ );
1141
+
1142
+ // Create reviewer service
1143
+ const service = new ReviewerService(dataSource);
1144
+
1145
+ // Get reviewer suggestions
1146
+ const suggestions = await service.suggestReviewers({
1147
+ project: event.project.id,
1148
+ mergeRequestIid: event.object_attributes.iid,
1149
+ });
1150
+
1151
+ // Post comment to merge request
1152
+ await dataSource.createNote(
1153
+ event.project.id,
1154
+ event.object_attributes.iid,
1155
+ suggestions.comment
1156
+ );
1157
+
1158
+ this.logger.log(
1159
+ `Posted reviewer suggestions to MR !${event.object_attributes.iid}`
1160
+ );
1161
+ } catch (error) {
1162
+ if (error instanceof MCPError) {
1163
+ this.logger.error(
1164
+ `Failed to process webhook [${error.code}]: ${error.message}`,
1165
+ error.details
1166
+ );
1167
+ } else {
1168
+ this.logger.error('Unexpected error processing webhook', error);
1169
+ }
1170
+ throw error;
1171
+ }
1172
+ }
1173
+ }
1174
+ ```
1175
+
1176
+ #### Step 5: Create Controller
1177
+
1178
+ ```typescript
1179
+ // src/libs/b2b-mfe-auto-reviewers/b2b-mfe-auto-reviewers.controller.ts
1180
+ import { Controller, Post, Body, HttpCode, Logger } from '@nestjs/common';
1181
+ import { B2BMfeAutoReviewersService } from './b2b-mfe-auto-reviewers.service';
1182
+ import { isMergeRequestEvent } from './b2b-mfe-auto-reviewers.type-guards';
1183
+
1184
+ @Controller('webhooks/b2b-mfe-auto-reviewers')
1185
+ export class B2BMfeAutoReviewersController {
1186
+ private readonly logger = new Logger(B2BMfeAutoReviewersController.name);
1187
+
1188
+ constructor(
1189
+ private readonly service: B2BMfeAutoReviewersService
1190
+ ) {}
1191
+
1192
+ @Post()
1193
+ @HttpCode(200)
1194
+ async handleWebhook(@Body() body: unknown): Promise<{ success: boolean }> {
1195
+ // Validate webhook event
1196
+ if (!isMergeRequestEvent(body)) {
1197
+ this.logger.warn('Invalid webhook event received');
1198
+ return { success: false };
1199
+ }
1200
+
1201
+ // Only process open/update/reopen actions
1202
+ const action = body.object_attributes.action;
1203
+ if (!['open', 'update', 'reopen'].includes(action)) {
1204
+ this.logger.log(`Ignoring action: ${action}`);
1205
+ return { success: true };
1206
+ }
1207
+
1208
+ // Process webhook
1209
+ await this.service.processWebhook(body);
1210
+
1211
+ return { success: true };
1212
+ }
1213
+ }
1214
+ ```
1215
+
1216
+ #### Step 6: Register Module
1217
+
1218
+ ```typescript
1219
+ // src/app.module.ts
1220
+ import { Module } from '@nestjs/common';
1221
+ import { B2BMfeAutoReviewersModule } from './libs/b2b-mfe-auto-reviewers/b2b-mfe-auto-reviewers.module';
1222
+
1223
+ @Module({
1224
+ imports: [
1225
+ // ... other modules
1226
+ B2BMfeAutoReviewersModule,
1227
+ ],
1228
+ })
1229
+ export class AppModule {}
1230
+ ```
1231
+
1232
+ #### Step 7: Configure Environment
1233
+
1234
+ ```bash
1235
+ # .env
1236
+ GITLAB_TOKEN=glpat-xxxxxxxxxxxx
1237
+ GITLAB_URL=https://gitlab.com
1238
+ ```
1239
+
1240
+ #### Step 8: Configure GitLab Webhook
1241
+
1242
+ 1. Go to your GitLab project: Settings → Webhooks
1243
+ 2. Add webhook URL: `https://your-server.com/webhooks/b2b-mfe-auto-reviewers`
1244
+ 3. Select trigger: "Merge request events"
1245
+ 4. Select actions: "Opened", "Updated", "Reopened"
1246
+ 5. Save webhook
1247
+
1248
+ ### Express.js Integration
1249
+
1250
+ ```typescript
1251
+ import express from 'express';
1252
+ import {
1253
+ ReviewerService,
1254
+ GitLabAPIDataSource
1255
+ } from 'gitlab-auto-reviewers';
1256
+
1257
+ const app = express();
1258
+ app.use(express.json());
1259
+
1260
+ app.post('/webhooks/auto-reviewers', async (req, res) => {
1261
+ try {
1262
+ const event = req.body;
1263
+
1264
+ // Validate event
1265
+ if (event.object_kind !== 'merge_request') {
1266
+ return res.status(200).json({ success: false });
1267
+ }
1268
+
1269
+ // Create data source
1270
+ const dataSource = new GitLabAPIDataSource(
1271
+ process.env.GITLAB_TOKEN!,
1272
+ process.env.GITLAB_URL
1273
+ );
1274
+
1275
+ // Create service
1276
+ const service = new ReviewerService(dataSource);
1277
+
1278
+ // Get suggestions
1279
+ const suggestions = await service.suggestReviewers({
1280
+ project: event.project.id,
1281
+ mergeRequestIid: event.object_attributes.iid,
1282
+ });
1283
+
1284
+ // Post comment
1285
+ await dataSource.createNote(
1286
+ event.project.id,
1287
+ event.object_attributes.iid,
1288
+ suggestions.comment
1289
+ );
1290
+
1291
+ res.status(200).json({ success: true });
1292
+ } catch (error) {
1293
+ console.error('Webhook error:', error);
1294
+ res.status(500).json({ success: false, error: error.message });
1295
+ }
1296
+ });
1297
+
1298
+ app.listen(3000, () => {
1299
+ console.log('Webhook server listening on port 3000');
1300
+ });
1301
+ ```
1302
+
1303
+ ### Webhook Configuration for New Repositories
1304
+
1305
+ To enable auto-reviewer suggestions for a new repository:
1306
+
1307
+ 1. **Install Package** (if using webhook server):
1308
+ ```bash
1309
+ npm install gitlab-auto-reviewers
1310
+ ```
1311
+
1312
+ 2. **Configure Environment Variables**:
1313
+ ```bash
1314
+ GITLAB_TOKEN=glpat-xxxxxxxxxxxx
1315
+ GITLAB_URL=https://gitlab.com
1316
+ ```
1317
+
1318
+ 3. **Create Configuration Files** (in repository root):
1319
+
1320
+ **CONTRIBUTORS** (optional):
1321
+ ```json
1322
+ {
1323
+ "contributors": [
1324
+ {
1325
+ "username": "alice",
1326
+ "email": "alice@example.com",
1327
+ "teams": [
1328
+ { "name": "Backend", "fte": 1.0 },
1329
+ { "name": "API", "fte": 0.5 }
1330
+ ]
1331
+ }
1332
+ ]
1333
+ }
1334
+ ```
1335
+
1336
+ **CODEOWNERS** (optional):
1337
+ ```
1338
+ # Backend team owns all backend code
1339
+ /backend/ @backend-team
1340
+
1341
+ # API section requires 2 approvals
1342
+ [API][2] @api-lead
1343
+ /api/ @alice @bob
1344
+ ```
1345
+
1346
+ 4. **Configure GitLab Webhook**:
1347
+ - Go to: Project → Settings → Webhooks
1348
+ - URL: `https://your-webhook-server.com/webhooks/auto-reviewers`
1349
+ - Trigger: "Merge request events"
1350
+ - Actions: "Opened", "Updated", "Reopened"
1351
+ - Secret token: (optional, for security)
1352
+ - SSL verification: Enabled (recommended)
1353
+
1354
+ 5. **Test Webhook**:
1355
+ - Create a test merge request
1356
+ - Check webhook logs for successful delivery
1357
+ - Verify comment appears on merge request
1358
+
1359
+ 6. **Monitor and Adjust**:
1360
+ - Monitor webhook logs for errors
1361
+ - Adjust CONTRIBUTORS and CODEOWNERS as needed
1362
+ - Update team FTE values based on workload
1363
+
1364
+ ### Webhook Security
1365
+
1366
+ **Verify Webhook Signature** (recommended):
1367
+
1368
+ ```typescript
1369
+ import crypto from 'crypto';
1370
+
1371
+ function verifyWebhookSignature(
1372
+ payload: string,
1373
+ signature: string,
1374
+ secret: string
1375
+ ): boolean {
1376
+ const hmac = crypto.createHmac('sha256', secret);
1377
+ const digest = hmac.update(payload).digest('hex');
1378
+ return crypto.timingSafeEqual(
1379
+ Buffer.from(signature),
1380
+ Buffer.from(digest)
1381
+ );
1382
+ }
1383
+
1384
+ app.post('/webhooks/auto-reviewers', (req, res) => {
1385
+ const signature = req.headers['x-gitlab-token'];
1386
+ const payload = JSON.stringify(req.body);
1387
+
1388
+ if (!verifyWebhookSignature(payload, signature, process.env.WEBHOOK_SECRET!)) {
1389
+ return res.status(401).json({ error: 'Invalid signature' });
1390
+ }
1391
+
1392
+ // Process webhook...
1393
+ });
1394
+ ```
1395
+
1396
+ **IP Whitelist** (optional):
1397
+
1398
+ ```typescript
1399
+ const GITLAB_IPS = [
1400
+ '34.74.90.64/28',
1401
+ '34.74.226.0/24',
1402
+ // Add your GitLab instance IPs
1403
+ ];
1404
+
1405
+ function isGitLabIP(ip: string): boolean {
1406
+ // Check if IP is in whitelist
1407
+ return GITLAB_IPS.some(range => ipInRange(ip, range));
1408
+ }
1409
+ ```
1410
+
1411
+ ## MCP Integration
1412
+
1413
+ To use this MCP server with an AI assistant, add it to your MCP configuration:
1414
+
1415
+ ```json
1416
+ {
1417
+ "mcpServers": {
1418
+ "gitlab-auto-reviewers": {
1419
+ "command": "npx",
1420
+ "args": ["-y", "gitlab-auto-reviewers", "mcp"],
1421
+ "env": {
1422
+ "GITLAB_TOKEN": "your_token_here",
1423
+ "GITLAB_URL": "https://gitlab.com"
1424
+ }
1425
+ }
1426
+ }
1427
+ }
1428
+ ```
1429
+
1430
+ For backward compatibility, the old command name is still supported:
1431
+
1432
+ ```json
1433
+ {
1434
+ "mcpServers": {
1435
+ "auto-reviewers": {
1436
+ "command": "npx",
1437
+ "args": ["-y", "auto-reviewers-mcp-server"],
1438
+ "env": {
1439
+ "GITLAB_TOKEN": "your_token_here",
1440
+ "GITLAB_URL": "https://gitlab.com"
1441
+ }
1442
+ }
1443
+ }
1444
+ }
1445
+ ```
1446
+
1447
+ ## Team Configuration
1448
+
1449
+ Create a `CONTRIBUTORS` file in your repository root with team and FTE data:
1450
+
1451
+ ```json
1452
+ {
1453
+ "contributors": [
1454
+ {
1455
+ "username": "developer1",
1456
+ "email": "dev1@example.com",
1457
+ "teams": [
1458
+ { "name": "Backend", "fte": 1.0 },
1459
+ { "name": "API", "fte": 0.5 }
1460
+ ]
1461
+ }
1462
+ ]
1463
+ }
1464
+ ```
1465
+
1466
+ ## Code Owners
1467
+
1468
+ Create a `CODEOWNERS` file in your repository root (or `docs/CODEOWNERS` or `.gitlab/CODEOWNERS`):
1469
+
1470
+ ```
1471
+ # Backend team owns all backend code
1472
+ /backend/ @backend-team
1473
+
1474
+ # API section requires 2 approvals
1475
+ [API][2] @api-lead
1476
+ /api/ @developer1 @developer2
1477
+ ```
1478
+
1479
+ ## Troubleshooting
1480
+
1481
+ For comprehensive troubleshooting information, see [TROUBLESHOOTING.md](./TROUBLESHOOTING.md).
1482
+
1483
+ ### Quick Diagnostics
1484
+
1485
+ Run these commands to quickly identify issues:
1486
+
1487
+ ```bash
1488
+ # 1. Check Node.js version (must be 18+)
1489
+ node --version
1490
+
1491
+ # 2. Check if server starts
1492
+ npm start 2>&1 | head -20
1493
+
1494
+ # 3. Check environment variables
1495
+ env | grep -E 'GITLAB|CACHE|LOG|DEBUG|REPO'
1496
+
1497
+ # 4. Test GitLab API access
1498
+ curl -H "PRIVATE-TOKEN: $GITLAB_TOKEN" $GITLAB_URL/api/v4/user
1499
+
1500
+ # 5. Check git repository (if using local mode)
1501
+ git status
1502
+ ```
1503
+
1504
+ ### Common Issues
1505
+
1506
+ #### Server Won't Start
1507
+ ```bash
1508
+ # Check Node.js version (must be 18+)
1509
+ node --version
1510
+
1511
+ # Verify environment variables
1512
+ echo $GITLAB_TOKEN
1513
+ cat .env
1514
+
1515
+ # Check for configuration errors
1516
+ npm start 2>&1 | grep ERROR
1517
+ ```
1518
+
1519
+ #### No Reviewers Suggested
1520
+ ```bash
1521
+ # Check git history
1522
+ git log --follow path/to/file
1523
+
1524
+ # Verify configuration files
1525
+ cat CONTRIBUTORS | jq .
1526
+ cat CODEOWNERS
1527
+
1528
+ # Enable debug logging
1529
+ DEBUG=true LOG_LEVEL=debug npm start
1530
+ ```
1531
+
1532
+ #### Performance Issues
1533
+ ```bash
1534
+ # Enable caching
1535
+ CACHE_ENABLED=true
1536
+ CACHE_TTL=300000
1537
+
1538
+ # Use local git mode (faster)
1539
+ REPO_PATH=/path/to/repo
1540
+
1541
+ # Monitor performance
1542
+ DEBUG=true LOG_LEVEL=debug npm start 2>&1 | grep duration
1543
+ ```
1544
+
1545
+ #### Authentication Errors
1546
+ ```bash
1547
+ # Test token
1548
+ curl -H "PRIVATE-TOKEN: $GITLAB_TOKEN" $GITLAB_URL/api/v4/user
1549
+
1550
+ # Create new token with required scopes:
1551
+ # - api OR read_api
1552
+ # - read_repository
1553
+ ```
1554
+
1555
+ ### Debug Mode
1556
+
1557
+ Enable detailed logging:
1558
+
1559
+ ```bash
1560
+ DEBUG=true LOG_LEVEL=debug npm start
1561
+ ```
1562
+
1563
+ Debug logs include:
1564
+ - Configuration loading and validation
1565
+ - Cache hits and misses
1566
+ - API request/response details
1567
+ - Git command execution
1568
+ - Performance timing for all operations
1569
+
1570
+ ### Getting Help
1571
+
1572
+ If you encounter issues:
1573
+
1574
+ 1. **Check Documentation**:
1575
+ - [TROUBLESHOOTING.md](./TROUBLESHOOTING.md) - Comprehensive troubleshooting guide
1576
+ - [MIGRATION.md](./MIGRATION.md) - Migration guide for v1.x to v2.0
1577
+ - [ARCHITECTURE.md](./ARCHITECTURE.md) - Architecture details
1578
+
1579
+ 2. **Enable Debug Mode**: `DEBUG=true LOG_LEVEL=debug npm start`
1580
+
1581
+ 3. **Report Issues**: Open an issue with:
1582
+ - Error messages and stack traces
1583
+ - Configuration (redact sensitive tokens)
1584
+ - Steps to reproduce
1585
+ - Server version and environment
1586
+ - Debug logs
1587
+
1588
+ ## Development
1589
+
1590
+ ### Building from Source
1591
+
1592
+ ```bash
1593
+ # Clone repository
1594
+ git clone ssh://git@code.[company-name].com:2222/frank.renfeng/state-of-merge-requests.git
1595
+ cd state-of-merge-requests/gitlab-auto-reviewers
1596
+
1597
+ # Install dependencies
1598
+ npm install
1599
+
1600
+ # Build
1601
+ npm run build
1602
+
1603
+ # Run tests
1604
+ npm test
1605
+
1606
+ # Run in development mode
1607
+ npm run dev
1608
+ ```
1609
+
1610
+ ### Project Structure
1611
+
1612
+ ```
1613
+ mcp-server/
1614
+ ├── src/
1615
+ │ ├── index.ts # Main entry point
1616
+ │ ├── types.ts # TypeScript interfaces
1617
+ │ ├── tools.ts # MCP tool definitions
1618
+ │ ├── config/
1619
+ │ │ └── config.service.ts # Configuration management
1620
+ │ ├── logging/
1621
+ │ │ └── logger.service.ts # Logging service
1622
+ │ ├── errors/
1623
+ │ │ └── error-handler.ts # Error handling
1624
+ │ ├── cache/
1625
+ │ │ └── cache.service.ts # Caching service
1626
+ │ ├── datasources/
1627
+ │ │ ├── git-data-source.interface.ts
1628
+ │ │ ├── gitlab-api-data-source.ts
1629
+ │ │ └── local-git-data-source.ts
1630
+ │ └── services/
1631
+ │ ├── reviewer-service.ts
1632
+ │ ├── contributors.service.ts
1633
+ │ ├── codeowners.service.ts
1634
+ │ ├── team-members.service.ts
1635
+ │ ├── blacklist.service.ts
1636
+ │ ├── whitelist.service.ts
1637
+ │ └── comment-builder.service.ts
1638
+ ├── dist/ # Compiled output
1639
+ ├── tests/ # Test files
1640
+ └── package.json
1641
+ ```
1642
+
1643
+ ### Running Tests
1644
+
1645
+ ```bash
1646
+ # Run all tests
1647
+ npm test
1648
+
1649
+ # Run tests in watch mode
1650
+ npm run test:watch
1651
+
1652
+ # Run tests with coverage
1653
+ npm run test:coverage
1654
+ ```
1655
+
1656
+ ### Code Style
1657
+
1658
+ The project uses:
1659
+ - **TypeScript** with strict mode enabled
1660
+ - **ESLint** for linting
1661
+ - **Prettier** for code formatting
1662
+
1663
+ ```bash
1664
+ # Lint code
1665
+ npm run lint
1666
+
1667
+ # Format code
1668
+ npm run format
1669
+
1670
+ # Type check
1671
+ npm run type-check
1672
+ ```
1673
+
1674
+ ## Contributing
1675
+
1676
+ Contributions are welcome! Please:
1677
+
1678
+ 1. Fork the repository
1679
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
1680
+ 3. Make your changes
1681
+ 4. Add tests for new functionality
1682
+ 5. Ensure all tests pass (`npm test`)
1683
+ 6. Lint and format code (`npm run lint && npm run format`)
1684
+ 7. Commit your changes (`git commit -m 'Add amazing feature'`)
1685
+ 8. Push to the branch (`git push origin feature/amazing-feature`)
1686
+ 9. Open a Pull Request
1687
+
1688
+ ### Contribution Guidelines
1689
+
1690
+ - Write clear, descriptive commit messages
1691
+ - Add JSDoc comments for all public APIs
1692
+ - Include tests for new features
1693
+ - Update documentation as needed
1694
+ - Follow existing code style and patterns
1695
+
1696
+ ## Migration from v1.x
1697
+
1698
+ If you're upgrading from version 1.x to 2.0, see [MIGRATION.md](./MIGRATION.md) for detailed instructions.
1699
+
1700
+ ### Quick Migration Steps
1701
+
1702
+ 1. **Update Package**:
1703
+ ```bash
1704
+ npm install gitlab-auto-reviewers@2.0.0
1705
+ ```
1706
+
1707
+ 2. **Update Node.js** (if needed):
1708
+ ```bash
1709
+ node --version # Must be 18+
1710
+ ```
1711
+
1712
+ 3. **Add New Configuration** (optional):
1713
+ ```bash
1714
+ # Add to .env
1715
+ CACHE_ENABLED=true
1716
+ CACHE_TTL=300000
1717
+ MAX_PARALLEL_REQUESTS=5
1718
+ LOG_LEVEL=info
1719
+ ```
1720
+
1721
+ 4. **Test Configuration**:
1722
+ ```bash
1723
+ npm start
1724
+ # Should see: [INFO] Configuration loaded successfully
1725
+ ```
1726
+
1727
+ 5. **Update Integration Code** (if needed):
1728
+ ```typescript
1729
+ // Update imports for strict types
1730
+ import { MergeRequest, User, ReviewerSuggestion } from 'gitlab-auto-reviewers';
1731
+ ```
1732
+
1733
+ ### Breaking Changes
1734
+
1735
+ - **Node.js 18+** required (was 16+)
1736
+ - **Configuration validation** now fails fast on startup
1737
+ - **Error response format** includes more structured information
1738
+ - **Log format** changed to structured JSON
1739
+
1740
+ See [MIGRATION.md](./MIGRATION.md) for complete details and troubleshooting.
1741
+
1742
+ ## Known Limitations
1743
+
1744
+ ### Large Merge Request Handling
1745
+
1746
+ **GitLab API Data Limitations**
1747
+
1748
+ When using `GitLabAPIDataSource` (webhook mode or API-based analysis), very large merge requests may encounter GitLab API limitations:
1749
+
1750
+ **Limitations:**
1751
+ - **Diff Size Limits**: GitLab API may truncate or limit diff data for merge requests with extensive changes
1752
+ - **File Count Limits**: Merge requests with hundreds of changed files may return partial file lists
1753
+ - **API Rate Limits**: High-frequency requests may be throttled by GitLab's rate limiting
1754
+ - **Timeout Constraints**: Very large merge requests may exceed API timeout thresholds
1755
+
1756
+ **Impact:**
1757
+ - Reviewer suggestions may be based on partial data
1758
+ - Some changed files may not be analyzed
1759
+ - Contributor analysis may be incomplete
1760
+ - CODEOWNERS matching may miss some files
1761
+
1762
+ **Mitigation Strategies:**
1763
+
1764
+ 1. **Use LocalGitDataSource for Large MRs**:
1765
+ ```bash
1766
+ # CLI mode with local repository (no API limits)
1767
+ npx gitlab-auto-reviewers cli --repo /path/to/repo --mr 123
1768
+ ```
1769
+
1770
+ 2. **Split Large Merge Requests**:
1771
+ - Break large changes into smaller, focused merge requests
1772
+ - Each MR should ideally change fewer than 50-100 files
1773
+
1774
+ 3. **Monitor API Usage**:
1775
+ - Check GitLab API rate limit headers
1776
+ - Implement request throttling if needed
1777
+ - Use caching to reduce API calls
1778
+
1779
+ 4. **Expect Partial Results**:
1780
+ - The system will continue to function with limited data
1781
+ - Reviewer suggestions will be based on available information
1782
+ - No errors will be thrown for partial data
1783
+
1784
+ **When to Use Each Data Source:**
1785
+
1786
+ | Scenario | Recommended Data Source | Reason |
1787
+ |----------|------------------------|--------|
1788
+ | Large MR (100+ files) | LocalGitDataSource | No API limits, complete data |
1789
+ | Webhook integration | GitLabAPIDataSource | Stateless, no repo clone needed |
1790
+ | CI/CD pipeline | LocalGitDataSource | Repo already cloned, faster |
1791
+ | Development | LocalGitDataSource | Faster, works offline |
1792
+ | Small MR (< 50 files) | Either | Both work well |
1793
+
1794
+ **Documentation References:**
1795
+ - Requirements 12.4: System allows limited data for large MRs
1796
+ - Requirements 12.5: Clear messaging about limitations
1797
+ - Design Document: Performance Considerations section
1798
+
1799
+ For more details, see [TROUBLESHOOTING.md](./TROUBLESHOOTING.md).
1800
+
1801
+ ## Documentation
1802
+
1803
+ - **[README.md](./README.md)** - This file, general documentation
1804
+ - **[MIGRATION.md](./MIGRATION.md)** - Migration guide from v1.x to v2.0
1805
+ - **[TROUBLESHOOTING.md](./TROUBLESHOOTING.md)** - Comprehensive troubleshooting guide
1806
+ - **[ARCHITECTURE.md](./ARCHITECTURE.md)** - Architecture and design documentation
1807
+
1808
+ ## License
1809
+
1810
+ MIT
1811
+
1812
+ ## Support
1813
+
1814
+ For issues, questions, or contributions, please visit:
1815
+ - **Issues**: [GitHub Issues](https://github.com/username/repo/issues)
1816
+ - **Repository**: [GitHub Repository](https://github.com/username/repo)
1817
+ - **Documentation**: [Full Documentation](https://github.com/username/repo/wiki)
1818
+
1819
+ ## Changelog
1820
+
1821
+ ### v2.0.0 (2024-12-04)
1822
+
1823
+ **Major Release - Performance & Reliability Improvements**
1824
+
1825
+ **New Features:**
1826
+ - In-memory caching with configurable TTL
1827
+ - Automatic retry logic with exponential backoff
1828
+ - Parallel data fetching for improved performance
1829
+ - Structured logging with multiple log levels
1830
+ - Configuration validation on startup
1831
+ - Performance metrics tracking
1832
+ - Enhanced error messages with context
1833
+
1834
+ **Breaking Changes:**
1835
+ - Node.js 18+ required (was 16+)
1836
+ - Configuration validation now fails fast
1837
+ - Error response format changed
1838
+ - Log format changed to structured JSON
1839
+
1840
+ **Improvements:**
1841
+ - Full TypeScript strict mode (zero `any` types)
1842
+ - Comprehensive type definitions
1843
+ - Better error handling and recovery
1844
+ - Improved observability and debugging
1845
+ - Enhanced documentation
1846
+
1847
+ See [MIGRATION.md](./MIGRATION.md) for upgrade instructions.
1848
+
1849
+
1850
+ ## Documentation
1851
+
1852
+ Comprehensive documentation is available in the `../docs/` directory:
1853
+
1854
+ ### For Users
1855
+ - **[Usage Examples](../docs/guides/USAGE_EXAMPLES.md)** - Practical examples and common use cases
1856
+ - **[CLI Guide](../docs/guides/CLI.md)** - Complete command-line interface documentation
1857
+ - **[Troubleshooting](../docs/guides/TROUBLESHOOTING.md)** - Common issues and solutions
1858
+ - **[Migration Guide](../docs/guides/MIGRATION_GUIDE.md)** - Upgrading from v1.x to v2.0
1859
+ - **[API Limitations](../docs/guides/API_LIMITATIONS.md)** - Known limitations and workarounds
1860
+ - **[Large MR Handling](../docs/guides/LARGE_MR_HANDLING.md)** - Best practices for large merge requests
1861
+
1862
+ ### For Developers
1863
+ - **[Architecture](../docs/architecture/ARCHITECTURE.md)** - System architecture and design
1864
+ - **[Refactoring Summary](../docs/architecture/REFACTORING_SUMMARY.md)** - Package refactoring details
1865
+ - **[Implementation Progress](../docs/architecture/IMPLEMENTATION_PROGRESS.md)** - Development progress tracking
1866
+
1867
+ ### For Testers
1868
+ - **[Cross-Implementation Test Summary](../docs/testing/CROSS-IMPLEMENTATION-TEST-SUMMARY.md)** - Comprehensive test results validating Requirements 12.1-12.9
1869
+ - **[Testing Infrastructure](../docs/testing/TESTING_INFRASTRUCTURE.md)** - Testing setup and methodology
1870
+ - **[Test Repository Setup](../docs/testing/TEST_REPOSITORY_SETUP.md)** - How to set up test environments
1871
+
1872
+ ### For Maintainers
1873
+ - **[Publishing Guide](../docs/guides/PUBLISHING.md)** - How to publish packages to npm
1874
+ - **[Backward Compatibility](../docs/architecture/BACKWARD_COMPATIBILITY_SUMMARY.md)** - Compatibility guarantees
1875
+ - **[Roadmap](../docs/ROADMAP.md)** - Project roadmap and future plans
1876
+
1877
+ ### Documentation Index
1878
+ See **[docs/README.md](../docs/README.md)** for the complete documentation index and organization.