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.
- package/LICENSE +21 -0
- package/README.md +1878 -0
- package/dist/api/gitlab-api.d.ts +136 -0
- package/dist/api/gitlab-api.d.ts.map +1 -0
- package/dist/api/gitlab-api.js +334 -0
- package/dist/api/gitlab-api.js.map +1 -0
- package/dist/bin/cli.d.ts +10 -0
- package/dist/bin/cli.d.ts.map +1 -0
- package/dist/bin/cli.js +186 -0
- package/dist/bin/cli.js.map +1 -0
- package/dist/bin/deprecated-mcp.d.ts +12 -0
- package/dist/bin/deprecated-mcp.d.ts.map +1 -0
- package/dist/bin/deprecated-mcp.js +73 -0
- package/dist/bin/deprecated-mcp.js.map +1 -0
- package/dist/bin/index.d.ts +18 -0
- package/dist/bin/index.d.ts.map +1 -0
- package/dist/bin/index.js +78 -0
- package/dist/bin/index.js.map +1 -0
- package/dist/bin/mcp.d.ts +11 -0
- package/dist/bin/mcp.d.ts.map +1 -0
- package/dist/bin/mcp.js +43 -0
- package/dist/bin/mcp.js.map +1 -0
- package/dist/cache/cache.service.d.ts +113 -0
- package/dist/cache/cache.service.d.ts.map +1 -0
- package/dist/cache/cache.service.js +213 -0
- package/dist/cache/cache.service.js.map +1 -0
- package/dist/cli/commands.d.ts +40 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +142 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/output.d.ts +24 -0
- package/dist/cli/output.d.ts.map +1 -0
- package/dist/cli/output.js +143 -0
- package/dist/cli/output.js.map +1 -0
- package/dist/config/config.service.d.ts +89 -0
- package/dist/config/config.service.d.ts.map +1 -0
- package/dist/config/config.service.js +169 -0
- package/dist/config/config.service.js.map +1 -0
- package/dist/datasources/git-data-source.interface.d.ts +140 -0
- package/dist/datasources/git-data-source.interface.d.ts.map +1 -0
- package/dist/datasources/git-data-source.interface.js +2 -0
- package/dist/datasources/git-data-source.interface.js.map +1 -0
- package/dist/datasources/gitlab-api-data-source.d.ts +127 -0
- package/dist/datasources/gitlab-api-data-source.d.ts.map +1 -0
- package/dist/datasources/gitlab-api-data-source.js +248 -0
- package/dist/datasources/gitlab-api-data-source.js.map +1 -0
- package/dist/datasources/local-git-data-source.d.ts +124 -0
- package/dist/datasources/local-git-data-source.d.ts.map +1 -0
- package/dist/datasources/local-git-data-source.js +580 -0
- package/dist/datasources/local-git-data-source.js.map +1 -0
- package/dist/errors/error-handler.d.ts +113 -0
- package/dist/errors/error-handler.d.ts.map +1 -0
- package/dist/errors/error-handler.js +230 -0
- package/dist/errors/error-handler.js.map +1 -0
- package/dist/index.d.ts +139 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +139 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/example.d.ts +15 -0
- package/dist/logging/example.d.ts.map +1 -0
- package/dist/logging/example.js +79 -0
- package/dist/logging/example.js.map +1 -0
- package/dist/logging/index.d.ts +7 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +7 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/logger.service.d.ts +98 -0
- package/dist/logging/logger.service.d.ts.map +1 -0
- package/dist/logging/logger.service.js +160 -0
- package/dist/logging/logger.service.js.map +1 -0
- package/dist/mcp/server.d.ts +67 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +213 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools.d.ts +22 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +176 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/services/blacklist.service.d.ts +32 -0
- package/dist/services/blacklist.service.d.ts.map +1 -0
- package/dist/services/blacklist.service.js +59 -0
- package/dist/services/blacklist.service.js.map +1 -0
- package/dist/services/codeowners.service.d.ts +45 -0
- package/dist/services/codeowners.service.d.ts.map +1 -0
- package/dist/services/codeowners.service.js +200 -0
- package/dist/services/codeowners.service.js.map +1 -0
- package/dist/services/comment-builder.service.d.ts +48 -0
- package/dist/services/comment-builder.service.d.ts.map +1 -0
- package/dist/services/comment-builder.service.js +61 -0
- package/dist/services/comment-builder.service.js.map +1 -0
- package/dist/services/contributors.service.d.ts +52 -0
- package/dist/services/contributors.service.d.ts.map +1 -0
- package/dist/services/contributors.service.js +144 -0
- package/dist/services/contributors.service.js.map +1 -0
- package/dist/services/reviewer-service.d.ts +125 -0
- package/dist/services/reviewer-service.d.ts.map +1 -0
- package/dist/services/reviewer-service.js +554 -0
- package/dist/services/reviewer-service.js.map +1 -0
- package/dist/services/team-members.service.d.ts +29 -0
- package/dist/services/team-members.service.d.ts.map +1 -0
- package/dist/services/team-members.service.js +45 -0
- package/dist/services/team-members.service.js.map +1 -0
- package/dist/services/whitelist.service.d.ts +31 -0
- package/dist/services/whitelist.service.d.ts.map +1 -0
- package/dist/services/whitelist.service.js +51 -0
- package/dist/services/whitelist.service.js.map +1 -0
- package/dist/tools.d.ts +22 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +176 -0
- package/dist/tools.js.map +1 -0
- package/dist/types/index.d.ts +502 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +91 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types.d.ts +219 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Service
|
|
3
|
+
*
|
|
4
|
+
* Provides in-memory caching with TTL (Time To Live) support for performance optimization.
|
|
5
|
+
* Supports automatic expiration and cache statistics tracking.
|
|
6
|
+
*/
|
|
7
|
+
import { Logger } from '../logging/logger.service.js';
|
|
8
|
+
/**
|
|
9
|
+
* Default cache options
|
|
10
|
+
*/
|
|
11
|
+
export const DEFAULT_CACHE_OPTIONS = {
|
|
12
|
+
ttlMs: 5 * 60 * 1000, // 5 minutes
|
|
13
|
+
maxSize: 1000,
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Cache Service for in-memory caching with TTL support
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Cache Service for in-memory caching with TTL support
|
|
20
|
+
*/
|
|
21
|
+
export class CacheService {
|
|
22
|
+
cache = new Map();
|
|
23
|
+
hits = 0;
|
|
24
|
+
misses = 0;
|
|
25
|
+
logger;
|
|
26
|
+
options;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new cache service
|
|
29
|
+
*
|
|
30
|
+
* @param options - Cache configuration options (ttlMs, maxSize)
|
|
31
|
+
* @param logger - Optional logger instance for logging cache operations
|
|
32
|
+
*/
|
|
33
|
+
constructor(options = {}, logger) {
|
|
34
|
+
this.options = {
|
|
35
|
+
...DEFAULT_CACHE_OPTIONS,
|
|
36
|
+
maxSize: DEFAULT_CACHE_OPTIONS.maxSize,
|
|
37
|
+
...options,
|
|
38
|
+
};
|
|
39
|
+
this.logger = logger || new Logger('CacheService');
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get a value from the cache
|
|
43
|
+
*/
|
|
44
|
+
get(key) {
|
|
45
|
+
const entry = this.cache.get(key);
|
|
46
|
+
if (!entry) {
|
|
47
|
+
this.misses++;
|
|
48
|
+
this.logger.debug(`Cache miss: ${key}`, { key });
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
// Check if entry has expired
|
|
52
|
+
if (Date.now() > entry.expiresAt) {
|
|
53
|
+
this.cache.delete(key);
|
|
54
|
+
this.misses++;
|
|
55
|
+
this.logger.debug(`Cache expired: ${key}`, { key });
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
this.hits++;
|
|
59
|
+
this.logger.debug(`Cache hit: ${key}`, { key });
|
|
60
|
+
return entry.value;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Set a value in the cache
|
|
64
|
+
*/
|
|
65
|
+
set(key, value, ttlMs) {
|
|
66
|
+
const ttl = ttlMs ?? this.options.ttlMs;
|
|
67
|
+
const expiresAt = Date.now() + ttl;
|
|
68
|
+
// Check if cache is full
|
|
69
|
+
if (this.cache.size >= this.options.maxSize && !this.cache.has(key)) {
|
|
70
|
+
this.evictOldest();
|
|
71
|
+
}
|
|
72
|
+
this.cache.set(key, { value, expiresAt });
|
|
73
|
+
this.logger.debug(`Cache set: ${key}`, { key, ttl });
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Check if a key exists in the cache and is not expired
|
|
77
|
+
*
|
|
78
|
+
* @param key - The cache key to check
|
|
79
|
+
* @returns True if key exists and is not expired, false otherwise
|
|
80
|
+
*/
|
|
81
|
+
has(key) {
|
|
82
|
+
const entry = this.cache.get(key);
|
|
83
|
+
if (!entry) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
// Check if expired
|
|
87
|
+
if (Date.now() > entry.expiresAt) {
|
|
88
|
+
this.cache.delete(key);
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Delete a specific key from the cache
|
|
95
|
+
*
|
|
96
|
+
* @param key - The cache key to delete
|
|
97
|
+
* @returns True if key was deleted, false if key didn't exist
|
|
98
|
+
*/
|
|
99
|
+
delete(key) {
|
|
100
|
+
const deleted = this.cache.delete(key);
|
|
101
|
+
if (deleted) {
|
|
102
|
+
this.logger.debug(`Cache deleted: ${key}`, { key });
|
|
103
|
+
}
|
|
104
|
+
return deleted;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Clear all entries from the cache
|
|
108
|
+
*/
|
|
109
|
+
clear() {
|
|
110
|
+
const size = this.cache.size;
|
|
111
|
+
this.cache.clear();
|
|
112
|
+
this.hits = 0;
|
|
113
|
+
this.misses = 0;
|
|
114
|
+
this.logger.info(`Cache cleared`, { entriesCleared: size });
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Invalidate all entries matching a pattern
|
|
118
|
+
*
|
|
119
|
+
* @param pattern - String or RegExp pattern to match cache keys against
|
|
120
|
+
* @returns Number of entries invalidated
|
|
121
|
+
*/
|
|
122
|
+
invalidatePattern(pattern) {
|
|
123
|
+
const regex = typeof pattern === 'string' ? new RegExp(pattern) : pattern;
|
|
124
|
+
let count = 0;
|
|
125
|
+
for (const key of this.cache.keys()) {
|
|
126
|
+
if (regex.test(key)) {
|
|
127
|
+
this.cache.delete(key);
|
|
128
|
+
count++;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (count > 0) {
|
|
132
|
+
this.logger.info(`Cache invalidated by pattern`, { pattern: pattern.toString(), count });
|
|
133
|
+
}
|
|
134
|
+
return count;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Remove expired entries from the cache
|
|
138
|
+
*/
|
|
139
|
+
cleanup() {
|
|
140
|
+
const now = Date.now();
|
|
141
|
+
let count = 0;
|
|
142
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
143
|
+
if (now > entry.expiresAt) {
|
|
144
|
+
this.cache.delete(key);
|
|
145
|
+
count++;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (count > 0) {
|
|
149
|
+
this.logger.debug(`Cache cleanup completed`, { expiredEntries: count });
|
|
150
|
+
}
|
|
151
|
+
return count;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get cache statistics
|
|
155
|
+
*/
|
|
156
|
+
getStats() {
|
|
157
|
+
const total = this.hits + this.misses;
|
|
158
|
+
const hitRate = total > 0 ? this.hits / total : 0;
|
|
159
|
+
return {
|
|
160
|
+
hits: this.hits,
|
|
161
|
+
misses: this.misses,
|
|
162
|
+
size: this.cache.size,
|
|
163
|
+
hitRate,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Wrap an operation with caching
|
|
168
|
+
*/
|
|
169
|
+
async wrap(key, operation, ttlMs) {
|
|
170
|
+
// Check cache first
|
|
171
|
+
const cached = this.get(key);
|
|
172
|
+
if (cached !== undefined) {
|
|
173
|
+
return cached;
|
|
174
|
+
}
|
|
175
|
+
// Execute operation
|
|
176
|
+
const endTimer = this.logger.startTimer(`Cache wrap: ${key}`);
|
|
177
|
+
const result = await operation();
|
|
178
|
+
endTimer();
|
|
179
|
+
// Store in cache
|
|
180
|
+
this.set(key, result, ttlMs);
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Evict the oldest entry from the cache
|
|
185
|
+
*/
|
|
186
|
+
evictOldest() {
|
|
187
|
+
let oldestKey;
|
|
188
|
+
let oldestTime = Infinity;
|
|
189
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
190
|
+
if (entry.expiresAt < oldestTime) {
|
|
191
|
+
oldestTime = entry.expiresAt;
|
|
192
|
+
oldestKey = key;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (oldestKey) {
|
|
196
|
+
this.cache.delete(oldestKey);
|
|
197
|
+
this.logger.debug(`Cache evicted oldest entry`, { key: oldestKey });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Get the current cache size
|
|
202
|
+
*/
|
|
203
|
+
get size() {
|
|
204
|
+
return this.cache.size;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get all cache keys
|
|
208
|
+
*/
|
|
209
|
+
keys() {
|
|
210
|
+
return Array.from(this.cache.keys());
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=cache.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.service.js","sourceRoot":"","sources":["../../src/cache/cache.service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAoCtD;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAiB;IACjD,KAAK,EAAE,C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;QAC9D,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;QACjC,QAAQ,EAAE,CAAC;QAEX,iBAAiB;QACjB,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAE7B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACK,WAAW;QACjB,IAAI,SAA6B,CAAC;QAClC,IAAI,UAAU,GAAG,QAAQ,CAAC;QAE1B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAChD,IAAI,KAAK,CAAC,SAAS,GAAG,UAAU,EAAE,CAAC;gBACjC,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC;gBAC7B,SAAS,GAAG,GAAG,CAAC;YAClB,CAAC;QACH,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA4B,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAI;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Command Handlers
|
|
3
|
+
*
|
|
4
|
+
* This module implements command handlers for the CLI mode.
|
|
5
|
+
* Handles argument parsing, validation, and execution of reviewer suggestions.
|
|
6
|
+
*
|
|
7
|
+
* @module cli/commands
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* CLI Command Options
|
|
11
|
+
*
|
|
12
|
+
* @property repoPath - Path to the local git repository (required)
|
|
13
|
+
* @property mergeRequestIid - Merge request IID number (required if branch not provided)
|
|
14
|
+
* @property branch - Branch name (required if mergeRequestIid not provided)
|
|
15
|
+
* @property gitlabUrl - GitLab instance URL (optional, defaults to https://gitlab.com)
|
|
16
|
+
* @property gitlabToken - GitLab API token (optional, can use GITLAB_TOKEN env var)
|
|
17
|
+
* @property format - Output format: 'json' or 'text' (optional, defaults to 'text')
|
|
18
|
+
* @property verbose - Enable verbose logging (optional, defaults to false)
|
|
19
|
+
*/
|
|
20
|
+
export interface CLIOptions {
|
|
21
|
+
repoPath: string;
|
|
22
|
+
mergeRequestIid?: number;
|
|
23
|
+
branch?: string;
|
|
24
|
+
gitlabUrl?: string;
|
|
25
|
+
gitlabToken?: string;
|
|
26
|
+
format?: 'json' | 'text';
|
|
27
|
+
verbose?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Execute the suggest-reviewers command
|
|
31
|
+
*
|
|
32
|
+
* @param options - CLI options including repository path and MR identifier
|
|
33
|
+
* @returns Exit code (0 for success, 1 for error)
|
|
34
|
+
*/
|
|
35
|
+
export declare function suggestReviewersCommand(options: CLIOptions): Promise<number>;
|
|
36
|
+
/**
|
|
37
|
+
* Display help text
|
|
38
|
+
*/
|
|
39
|
+
export declare function displayHelp(): void;
|
|
40
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/cli/commands.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH;;;;;;;;;;GAUG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAmGlF;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CA8ClC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Command Handlers
|
|
3
|
+
*
|
|
4
|
+
* This module implements command handlers for the CLI mode.
|
|
5
|
+
* Handles argument parsing, validation, and execution of reviewer suggestions.
|
|
6
|
+
*
|
|
7
|
+
* @module cli/commands
|
|
8
|
+
*/
|
|
9
|
+
import { ReviewerService } from "../services/reviewer-service.js";
|
|
10
|
+
import { Logger, LogLevel } from "../logging/logger.service.js";
|
|
11
|
+
import { ErrorHandler } from "../errors/error-handler.js";
|
|
12
|
+
import { formatJSON, formatText } from "./output.js";
|
|
13
|
+
/**
|
|
14
|
+
* Execute the suggest-reviewers command
|
|
15
|
+
*
|
|
16
|
+
* @param options - CLI options including repository path and MR identifier
|
|
17
|
+
* @returns Exit code (0 for success, 1 for error)
|
|
18
|
+
*/
|
|
19
|
+
export async function suggestReviewersCommand(options) {
|
|
20
|
+
// When using JSON format, suppress logger output unless verbose is enabled
|
|
21
|
+
// This prevents logger messages from mixing with JSON output
|
|
22
|
+
const logLevel = options.format === 'json' && !options.verbose
|
|
23
|
+
? LogLevel.ERROR
|
|
24
|
+
: (options.verbose ? LogLevel.DEBUG : LogLevel.INFO);
|
|
25
|
+
const logger = new Logger('CLI', logLevel);
|
|
26
|
+
try {
|
|
27
|
+
// Validate required options
|
|
28
|
+
if (!options.repoPath) {
|
|
29
|
+
throw ErrorHandler.validationError('Repository path is required', { providedPath: options.repoPath });
|
|
30
|
+
}
|
|
31
|
+
// Validate that either MR IID or branch is provided
|
|
32
|
+
if (!options.mergeRequestIid && !options.branch) {
|
|
33
|
+
throw ErrorHandler.validationError('Either merge request IID or branch name must be provided', { mergeRequestIid: options.mergeRequestIid, branch: options.branch });
|
|
34
|
+
}
|
|
35
|
+
// Get GitLab credentials from environment or options
|
|
36
|
+
const gitlabUrl = options.gitlabUrl || process.env.GITLAB_URL || 'https://gitlab.com';
|
|
37
|
+
const gitlabToken = options.gitlabToken || process.env.GITLAB_TOKEN;
|
|
38
|
+
if (!gitlabToken) {
|
|
39
|
+
throw ErrorHandler.validationError('GitLab token is required. Provide via --gitlab-token option or GITLAB_TOKEN environment variable', { gitlabUrl });
|
|
40
|
+
}
|
|
41
|
+
logger.info('Initializing reviewer service', {
|
|
42
|
+
repoPath: options.repoPath,
|
|
43
|
+
gitlabUrl,
|
|
44
|
+
dataSource: 'LocalGit',
|
|
45
|
+
});
|
|
46
|
+
// Initialize reviewer service with local git data source
|
|
47
|
+
const reviewerService = new ReviewerService(gitlabUrl, gitlabToken, options.repoPath, logger);
|
|
48
|
+
logger.info('Analyzing merge request', {
|
|
49
|
+
mergeRequestIid: options.mergeRequestIid,
|
|
50
|
+
branch: options.branch,
|
|
51
|
+
});
|
|
52
|
+
// Suggest reviewers
|
|
53
|
+
const result = await reviewerService.suggestReviewers({
|
|
54
|
+
mergeRequestIid: options.mergeRequestIid,
|
|
55
|
+
branch: options.branch,
|
|
56
|
+
});
|
|
57
|
+
// Format and output results
|
|
58
|
+
const format = options.format || 'text';
|
|
59
|
+
const output = format === 'json'
|
|
60
|
+
? formatJSON(result)
|
|
61
|
+
: formatText(result);
|
|
62
|
+
console.log(output);
|
|
63
|
+
logger.info('Reviewer suggestion completed successfully', {
|
|
64
|
+
contributorCount: result.contributors.length,
|
|
65
|
+
teamMemberCount: result.teamMembers.length,
|
|
66
|
+
codeOwnerCount: result.codeOwners.length,
|
|
67
|
+
});
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
72
|
+
const errorDetails = ErrorHandler.formatError(error instanceof Error ? error : new Error(String(error)));
|
|
73
|
+
logger.error('Command failed', error instanceof Error ? error : new Error(String(error)), {
|
|
74
|
+
command: 'suggest-reviewers',
|
|
75
|
+
});
|
|
76
|
+
// Output error in appropriate format
|
|
77
|
+
if (options.format === 'json') {
|
|
78
|
+
console.error(JSON.stringify({
|
|
79
|
+
error: errorMessage,
|
|
80
|
+
details: errorDetails,
|
|
81
|
+
}, null, 2));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
console.error(`Error: ${errorMessage}`);
|
|
85
|
+
if (options.verbose) {
|
|
86
|
+
console.error(errorDetails);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return 1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Display help text
|
|
94
|
+
*/
|
|
95
|
+
export function displayHelp() {
|
|
96
|
+
console.log(`
|
|
97
|
+
gitlab-auto-reviewers CLI
|
|
98
|
+
|
|
99
|
+
USAGE:
|
|
100
|
+
gitlab-auto-reviewers cli [OPTIONS]
|
|
101
|
+
|
|
102
|
+
OPTIONS:
|
|
103
|
+
--repo-path <path> Path to local git repository (required)
|
|
104
|
+
--mr <number> Merge request IID (required if --branch not provided)
|
|
105
|
+
--branch <name> Branch name (required if --mr not provided)
|
|
106
|
+
--gitlab-url <url> GitLab instance URL (default: https://gitlab.com)
|
|
107
|
+
--gitlab-token <token> GitLab API token (or use GITLAB_TOKEN env var)
|
|
108
|
+
--format <json|text> Output format (default: text)
|
|
109
|
+
--verbose Enable verbose logging
|
|
110
|
+
--help Display this help message
|
|
111
|
+
|
|
112
|
+
ENVIRONMENT VARIABLES:
|
|
113
|
+
GITLAB_URL GitLab instance URL
|
|
114
|
+
GITLAB_TOKEN GitLab API token (required)
|
|
115
|
+
|
|
116
|
+
EXAMPLES:
|
|
117
|
+
# Suggest reviewers for MR 123 in current directory
|
|
118
|
+
gitlab-auto-reviewers cli --repo-path . --mr 123
|
|
119
|
+
|
|
120
|
+
# Suggest reviewers for current branch
|
|
121
|
+
gitlab-auto-reviewers cli --repo-path . --branch feature/my-feature
|
|
122
|
+
|
|
123
|
+
# Output as JSON
|
|
124
|
+
gitlab-auto-reviewers cli --repo-path . --mr 123 --format json
|
|
125
|
+
|
|
126
|
+
# Use custom GitLab instance
|
|
127
|
+
gitlab-auto-reviewers cli --repo-path . --mr 123 --gitlab-url https://gitlab.example.com
|
|
128
|
+
|
|
129
|
+
# Enable verbose logging
|
|
130
|
+
gitlab-auto-reviewers cli --repo-path . --mr 123 --verbose
|
|
131
|
+
|
|
132
|
+
DEVELOPMENT USAGE:
|
|
133
|
+
# In development environment
|
|
134
|
+
cd /path/to/my-project
|
|
135
|
+
gitlab-auto-reviewers cli --repo-path . --mr 123
|
|
136
|
+
|
|
137
|
+
CI/CD USAGE:
|
|
138
|
+
# In CI/CD pipeline (repository already cloned)
|
|
139
|
+
gitlab-auto-reviewers cli --repo-path $CI_PROJECT_DIR --mr $CI_MERGE_REQUEST_IID
|
|
140
|
+
`);
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/cli/commands.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAuBrD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,OAAmB;IAC/D,2EAA2E;IAC3E,6DAA6D;IAC7D,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO;QAC5D,CAA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AAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE;YACxF,OAAO,EAAE,mBAAmB;SAC7B,CAAC,CAAC;QAEH,qCAAqC;QACrC,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC9B,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;gBAC3B,KAAK,EAAE,YAAY;gBACnB,OAAO,EAAE,YAAY;aACtB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACf,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,UAAU,YAAY,EAAE,CAAC,CAAC;YACxC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;gBACpB,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;QAED,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Cb,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Output Formatters
|
|
3
|
+
*
|
|
4
|
+
* This module provides output formatting functions for CLI results.
|
|
5
|
+
* Supports both JSON and human-readable text formats.
|
|
6
|
+
*
|
|
7
|
+
* @module cli/output
|
|
8
|
+
*/
|
|
9
|
+
import { AutoReviewerResult } from "../types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Format reviewer suggestions as JSON
|
|
12
|
+
*
|
|
13
|
+
* @param result - Reviewer analysis result
|
|
14
|
+
* @returns JSON string with formatted output
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatJSON(result: AutoReviewerResult): string;
|
|
17
|
+
/**
|
|
18
|
+
* Format reviewer suggestions as human-readable text
|
|
19
|
+
*
|
|
20
|
+
* @param result - Reviewer analysis result
|
|
21
|
+
* @returns Formatted text string
|
|
22
|
+
*/
|
|
23
|
+
export declare function formatText(result: AutoReviewerResult): string;
|
|
24
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/cli/output.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,kBAAkB,EAAsB,MAAM,aAAa,CAAC;AAErE;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAY7D;AAiBD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAuD7D"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Output Formatters
|
|
3
|
+
*
|
|
4
|
+
* This module provides output formatting functions for CLI results.
|
|
5
|
+
* Supports both JSON and human-readable text formats.
|
|
6
|
+
*
|
|
7
|
+
* @module cli/output
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Format reviewer suggestions as JSON
|
|
11
|
+
*
|
|
12
|
+
* @param result - Reviewer analysis result
|
|
13
|
+
* @returns JSON string with formatted output
|
|
14
|
+
*/
|
|
15
|
+
export function formatJSON(result) {
|
|
16
|
+
return JSON.stringify({
|
|
17
|
+
contributors: result.contributors.map(formatReviewerJSON),
|
|
18
|
+
teamMembers: result.teamMembers.map(formatReviewerJSON),
|
|
19
|
+
codeOwners: result.codeOwners.map(formatReviewerJSON),
|
|
20
|
+
summary: {
|
|
21
|
+
totalSuggestions: result.contributors.length + result.teamMembers.length + result.codeOwners.length,
|
|
22
|
+
contributorCount: result.contributors.length,
|
|
23
|
+
teamMemberCount: result.teamMembers.length,
|
|
24
|
+
codeOwnerCount: result.codeOwners.length,
|
|
25
|
+
},
|
|
26
|
+
}, null, 2);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Format a single reviewer suggestion as JSON object
|
|
30
|
+
*/
|
|
31
|
+
function formatReviewerJSON(reviewer) {
|
|
32
|
+
return {
|
|
33
|
+
username: reviewer.username,
|
|
34
|
+
score: reviewer.score,
|
|
35
|
+
reason: reviewer.reason,
|
|
36
|
+
workload: reviewer.workload,
|
|
37
|
+
fte: reviewer.fte,
|
|
38
|
+
workloadDetails: reviewer.workloadDetails,
|
|
39
|
+
reasoning: reviewer.reasoning,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Format reviewer suggestions as human-readable text
|
|
44
|
+
*
|
|
45
|
+
* @param result - Reviewer analysis result
|
|
46
|
+
* @returns Formatted text string
|
|
47
|
+
*/
|
|
48
|
+
export function formatText(result) {
|
|
49
|
+
const lines = [];
|
|
50
|
+
lines.push('='.repeat(80));
|
|
51
|
+
lines.push('REVIEWER SUGGESTIONS');
|
|
52
|
+
lines.push('='.repeat(80));
|
|
53
|
+
lines.push('');
|
|
54
|
+
// Summary
|
|
55
|
+
const totalSuggestions = result.contributors.length + result.teamMembers.length + result.codeOwners.length;
|
|
56
|
+
lines.push(`Total Suggestions: ${totalSuggestions}`);
|
|
57
|
+
lines.push(` - Contributors: ${result.contributors.length}`);
|
|
58
|
+
lines.push(` - Team Members: ${result.teamMembers.length}`);
|
|
59
|
+
lines.push(` - Code Owners: ${result.codeOwners.length}`);
|
|
60
|
+
lines.push('');
|
|
61
|
+
// Contributors
|
|
62
|
+
if (result.contributors.length > 0) {
|
|
63
|
+
lines.push('-'.repeat(80));
|
|
64
|
+
lines.push('CONTRIBUTORS');
|
|
65
|
+
lines.push('-'.repeat(80));
|
|
66
|
+
lines.push('');
|
|
67
|
+
result.contributors.forEach((reviewer, index) => {
|
|
68
|
+
lines.push(...formatReviewerText(reviewer, index + 1));
|
|
69
|
+
lines.push('');
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// Team Members
|
|
73
|
+
if (result.teamMembers.length > 0) {
|
|
74
|
+
lines.push('-'.repeat(80));
|
|
75
|
+
lines.push('TEAM MEMBERS');
|
|
76
|
+
lines.push('-'.repeat(80));
|
|
77
|
+
lines.push('');
|
|
78
|
+
result.teamMembers.forEach((reviewer, index) => {
|
|
79
|
+
lines.push(...formatReviewerText(reviewer, index + 1));
|
|
80
|
+
lines.push('');
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// Code Owners
|
|
84
|
+
if (result.codeOwners.length > 0) {
|
|
85
|
+
lines.push('-'.repeat(80));
|
|
86
|
+
lines.push('CODE OWNERS');
|
|
87
|
+
lines.push('-'.repeat(80));
|
|
88
|
+
lines.push('');
|
|
89
|
+
result.codeOwners.forEach((reviewer, index) => {
|
|
90
|
+
lines.push(...formatReviewerText(reviewer, index + 1));
|
|
91
|
+
lines.push('');
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
lines.push('='.repeat(80));
|
|
95
|
+
return lines.join('\n');
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Format a single reviewer suggestion as text
|
|
99
|
+
*/
|
|
100
|
+
function formatReviewerText(reviewer, index) {
|
|
101
|
+
const lines = [];
|
|
102
|
+
lines.push(`${index}. @${reviewer.username}`);
|
|
103
|
+
if (reviewer.score) {
|
|
104
|
+
lines.push(` Score: ${reviewer.score.total}/100`);
|
|
105
|
+
}
|
|
106
|
+
lines.push(` Reason: ${reviewer.reason}`);
|
|
107
|
+
// Score breakdown
|
|
108
|
+
if (reviewer.score?.breakdown) {
|
|
109
|
+
const breakdown = reviewer.score.breakdown;
|
|
110
|
+
const parts = [];
|
|
111
|
+
if (breakdown.contribution > 0)
|
|
112
|
+
parts.push(`Contribution: ${breakdown.contribution}`);
|
|
113
|
+
if (breakdown.codeOwnership > 0)
|
|
114
|
+
parts.push(`Code Ownership: ${breakdown.codeOwnership}`);
|
|
115
|
+
if (breakdown.teamMembership > 0)
|
|
116
|
+
parts.push(`Team Membership: ${breakdown.teamMembership}`);
|
|
117
|
+
if (breakdown.availability > 0)
|
|
118
|
+
parts.push(`Availability: ${breakdown.availability}`);
|
|
119
|
+
if (parts.length > 0) {
|
|
120
|
+
lines.push(` Breakdown: ${parts.join(', ')}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Workload details
|
|
124
|
+
if (reviewer.workloadDetails) {
|
|
125
|
+
const { current, capacity, utilizationPercent } = reviewer.workloadDetails;
|
|
126
|
+
lines.push(` Workload: ${current}/${capacity} MRs (${utilizationPercent}% utilized)`);
|
|
127
|
+
}
|
|
128
|
+
// FTE
|
|
129
|
+
if (reviewer.fte !== undefined && reviewer.fte !== 1) {
|
|
130
|
+
lines.push(` FTE: ${reviewer.fte}`);
|
|
131
|
+
}
|
|
132
|
+
// Reasoning
|
|
133
|
+
if (reviewer.reasoning) {
|
|
134
|
+
lines.push(` Details: ${reviewer.reasoning.primary}`);
|
|
135
|
+
if (reviewer.reasoning.factors && reviewer.reasoning.factors.length > 0) {
|
|
136
|
+
reviewer.reasoning.factors.forEach((factor) => {
|
|
137
|
+
lines.push(` - ${factor.description} (weight: ${factor.weight})`);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return lines;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/cli/output.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,MAA0B;IACnD,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,kBAAkB,CAAC;QACzD,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,kBAAkB,CAAC;QACvD,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,kBAAkB,CAAC;QACrD,OAAO,EAAE;Y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