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,248 @@
|
|
|
1
|
+
import { Logger } from '../logging/logger.service.js';
|
|
2
|
+
import { ErrorHandler } from '../errors/error-handler.js';
|
|
3
|
+
/**
|
|
4
|
+
* GitLab API data source implementation
|
|
5
|
+
*
|
|
6
|
+
* Provides access to GitLab data through the GitLab REST API.
|
|
7
|
+
* Implements the GitDataSource interface with API-based operations.
|
|
8
|
+
*/
|
|
9
|
+
export class GitLabAPIDataSource {
|
|
10
|
+
logger;
|
|
11
|
+
gitlabApi;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new GitLab API data source
|
|
14
|
+
*
|
|
15
|
+
* @param gitlabApi - GitLab API client instance
|
|
16
|
+
* @param logger - Optional logger instance for logging operations
|
|
17
|
+
*/
|
|
18
|
+
constructor(gitlabApi, logger) {
|
|
19
|
+
this.logger = logger || new Logger('GitLabAPIDataSource');
|
|
20
|
+
this.gitlabApi = gitlabApi;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Find an open merge request by branch name
|
|
24
|
+
*
|
|
25
|
+
* @param project - The project ID or path
|
|
26
|
+
* @param branch - The source branch name to search for
|
|
27
|
+
* @returns Promise resolving to the merge request
|
|
28
|
+
* @throws {MCPError} If no open MR is found for the branch
|
|
29
|
+
*/
|
|
30
|
+
async findMergeRequestByBranch(project, branch) {
|
|
31
|
+
const context = { project, branch, dataSource: 'GitLabAPI' };
|
|
32
|
+
try {
|
|
33
|
+
const mrs = await this.gitlabApi.getMergeRequests(project, "opened");
|
|
34
|
+
const mr = mrs.find((m) => m.source_branch === branch);
|
|
35
|
+
if (!mr) {
|
|
36
|
+
const available = mrs
|
|
37
|
+
.map((m) => m.source_branch)
|
|
38
|
+
.slice(0, 10)
|
|
39
|
+
.join(", ");
|
|
40
|
+
throw ErrorHandler.notFoundError(`No open MR found for branch: ${branch}. Found ${mrs.length} open MRs with branches: ${available}`, context);
|
|
41
|
+
}
|
|
42
|
+
return mr;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error instanceof Error && error.message.includes('MCP')) {
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
throw ErrorHandler.apiCallError('Failed to find merge request by branch', context, error instanceof Error ? error : new Error(String(error)));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the default branch for a project
|
|
53
|
+
*
|
|
54
|
+
* @param project - The project ID or path
|
|
55
|
+
* @returns Promise resolving to the default branch name
|
|
56
|
+
*/
|
|
57
|
+
async getDefaultBranch(project) {
|
|
58
|
+
const context = { project, dataSource: 'GitLabAPI' };
|
|
59
|
+
try {
|
|
60
|
+
return await this.gitlabApi.getDefaultBranch(project);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw ErrorHandler.apiCallError('Failed to get default branch', context, error instanceof Error ? error : new Error(String(error)));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get a specific merge request by IID
|
|
68
|
+
*
|
|
69
|
+
* @param project - The project ID or path
|
|
70
|
+
* @param mr - The merge request internal ID
|
|
71
|
+
* @returns Promise resolving to the merge request or null if not found
|
|
72
|
+
*/
|
|
73
|
+
async getMergeRequest(project, mr) {
|
|
74
|
+
const context = { project, mr, dataSource: 'GitLabAPI' };
|
|
75
|
+
try {
|
|
76
|
+
return await this.gitlabApi.getMergeRequest(project, mr);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw ErrorHandler.apiCallError('Failed to get merge request', context, error instanceof Error ? error : new Error(String(error)));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get a merge request by its source branch name
|
|
84
|
+
*
|
|
85
|
+
* @param project - The project ID or path
|
|
86
|
+
* @param branch - The source branch name
|
|
87
|
+
* @returns Promise resolving to the merge request or null if not found
|
|
88
|
+
*/
|
|
89
|
+
async getMergeRequestByBranch(project, branch) {
|
|
90
|
+
return this.findMergeRequestByBranch(project, branch);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get all diffs for a merge request
|
|
94
|
+
*
|
|
95
|
+
* Note: For very large merge requests (100+ changed files), GitLab API may return
|
|
96
|
+
* limited or truncated data due to API constraints. Consider using LocalGitDataSource
|
|
97
|
+
* for complete analysis of large merge requests.
|
|
98
|
+
*
|
|
99
|
+
* @param project - The project ID or path
|
|
100
|
+
* @param mr - The merge request internal ID
|
|
101
|
+
* @returns Promise resolving to array of diffs (may be limited for large MRs)
|
|
102
|
+
*/
|
|
103
|
+
async getDiffs(project, mr) {
|
|
104
|
+
const context = { project, mr, dataSource: 'GitLabAPI' };
|
|
105
|
+
try {
|
|
106
|
+
const diffs = await this.gitlabApi.getDiffs(project, mr);
|
|
107
|
+
// Log info about data retrieval for large MRs
|
|
108
|
+
if (diffs.length >= 100) {
|
|
109
|
+
this.logger.info('Large merge request processed', {
|
|
110
|
+
project,
|
|
111
|
+
mr,
|
|
112
|
+
diffCount: diffs.length,
|
|
113
|
+
note: 'API may have returned limited data. For complete analysis, use LocalGitDataSource.',
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return diffs;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw ErrorHandler.apiCallError('Failed to get diffs', context, error instanceof Error ? error : new Error(String(error)));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get git blame information for a file
|
|
124
|
+
*
|
|
125
|
+
* @param project - The project ID or path
|
|
126
|
+
* @param path - The file path within the repository
|
|
127
|
+
* @param ref - The branch, tag, or commit SHA
|
|
128
|
+
* @returns Promise resolving to array of blame lines or null if file not found
|
|
129
|
+
*/
|
|
130
|
+
async getBlame(project, path, ref) {
|
|
131
|
+
const context = { project, path, ref, dataSource: 'GitLabAPI' };
|
|
132
|
+
try {
|
|
133
|
+
return await this.gitlabApi.getBlame(project, path, ref);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
throw ErrorHandler.apiCallError('Failed to get blame', context, error instanceof Error ? error : new Error(String(error)));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get raw file content from repository
|
|
141
|
+
*
|
|
142
|
+
* @param project - The project ID or path
|
|
143
|
+
* @param commitSha - The commit SHA
|
|
144
|
+
* @param path - The file path within the repository
|
|
145
|
+
* @returns Promise resolving to file content or null if not found
|
|
146
|
+
*/
|
|
147
|
+
async getRawFile(project, commitSha, path) {
|
|
148
|
+
const context = { project, commitSha, path, dataSource: 'GitLabAPI' };
|
|
149
|
+
try {
|
|
150
|
+
// GitLab API accepts both branch names and commit SHAs in ref parameter
|
|
151
|
+
return await this.gitlabApi.getRawFile(project, commitSha, path);
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
throw ErrorHandler.apiCallError('Failed to get raw file', context, error instanceof Error ? error : new Error(String(error)));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Get and parse a JSON file from repository
|
|
159
|
+
*
|
|
160
|
+
* @param project - The project ID or path
|
|
161
|
+
* @param commitSha - The commit SHA
|
|
162
|
+
* @param path - The file path within the repository
|
|
163
|
+
* @returns Promise resolving to parsed JSON object or null if not found
|
|
164
|
+
* @throws {MCPError} If the file cannot be parsed as JSON
|
|
165
|
+
*/
|
|
166
|
+
async getJsonFile(project, commitSha, path) {
|
|
167
|
+
const context = { project, commitSha, path, dataSource: 'GitLabAPI' };
|
|
168
|
+
try {
|
|
169
|
+
const content = await this.getRawFile(project, commitSha, path);
|
|
170
|
+
if (!content)
|
|
171
|
+
return null;
|
|
172
|
+
return typeof content === "string" ? JSON.parse(content) : content;
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
if (error instanceof Error && error.message.includes('MCP')) {
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
throw ErrorHandler.validationError(`Failed to parse JSON file: ${path}`, context);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Get all merge requests for a project
|
|
183
|
+
*
|
|
184
|
+
* @param project - The project ID or path
|
|
185
|
+
* @param state - The merge request state to filter by (default: "opened")
|
|
186
|
+
* @returns Promise resolving to array of merge requests
|
|
187
|
+
*/
|
|
188
|
+
async getMergeRequests(project, state = "opened") {
|
|
189
|
+
const context = { project, state, dataSource: 'GitLabAPI' };
|
|
190
|
+
try {
|
|
191
|
+
return await this.gitlabApi.getMergeRequests(project, state);
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
throw ErrorHandler.apiCallError('Failed to get merge requests', context, error instanceof Error ? error : new Error(String(error)));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Get all notes (comments) for a merge request
|
|
199
|
+
*
|
|
200
|
+
* @param project - The project ID or path
|
|
201
|
+
* @param mr - The merge request internal ID
|
|
202
|
+
* @returns Promise resolving to array of notes
|
|
203
|
+
*/
|
|
204
|
+
async getNotes(project, mr) {
|
|
205
|
+
const context = { project, mr, dataSource: 'GitLabAPI' };
|
|
206
|
+
try {
|
|
207
|
+
return await this.gitlabApi.getNotes(project, mr);
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
throw ErrorHandler.apiCallError('Failed to get notes', context, error instanceof Error ? error : new Error(String(error)));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Get project contributors by analyzing commit history
|
|
215
|
+
*
|
|
216
|
+
* @param project - The project ID or path
|
|
217
|
+
* @param commitSha - The commit SHA to analyze history from
|
|
218
|
+
* @returns Promise resolving to array of contributor email addresses
|
|
219
|
+
*/
|
|
220
|
+
async getProjectContributors(project, commitSha) {
|
|
221
|
+
const context = { project, commitSha, dataSource: 'GitLabAPI' };
|
|
222
|
+
try {
|
|
223
|
+
// GitLab API accepts both branch names and commit SHAs
|
|
224
|
+
return await this.gitlabApi.getProjectContributors(project, commitSha);
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
throw ErrorHandler.apiCallError('Failed to get project contributors', context, error instanceof Error ? error : new Error(String(error)));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Create a note (comment) on a merge request
|
|
232
|
+
*
|
|
233
|
+
* @param project - The project ID or path
|
|
234
|
+
* @param mr - The merge request internal ID
|
|
235
|
+
* @param body - The comment text (supports Markdown)
|
|
236
|
+
* @returns Promise resolving to the created note
|
|
237
|
+
*/
|
|
238
|
+
async createNote(project, mr, body) {
|
|
239
|
+
const context = { project, mr, dataSource: 'GitLabAPI' };
|
|
240
|
+
try {
|
|
241
|
+
return await this.gitlabApi.postComment(project, mr, body);
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
throw ErrorHandler.apiCallError('Failed to create note', context, error instanceof Error ? error : new Error(String(error)));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=gitlab-api-data-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gitlab-api-data-source.js","sourceRoot":"","sources":["../../src/datasources/gitlab-api-data-source.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,OAAO,mBAAmB;IACpB,MAAM,CAAS;IACf,SAAS,CAAY;IAE/B;;;;;OAKG;IACH,YAAY,SAAoB,EAAE,MAAe;QAC/C,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,MAAM,CAAC,qBAAqB,CAAC,CAAC;QAC1D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;;;;OAOG;IACO,KAAK,CAAC,wBAAwB,CACtC,OAAe,EACf,MAAc;QAEd,MAAM,OAAO,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;QAE7D,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACrE,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,KAAK,MAAM,CAAC,CAAC;YAEvD,IAAI,CAAC,EAAE,EAAE,CAAC;gBACR,MAAM,SAAS,GAA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MAAM,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;QAC7D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,YAAY,CAAC,YAAY,CAC7B,uBAAuB,EACvB,OAAO,EACP,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAC1D,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { GitLabAPI } from "../api/gitlab-api.js";
|
|
2
|
+
import { GitDataSource } from "./git-data-source.interface.js";
|
|
3
|
+
import { GitLabAPIDataSource } from "./gitlab-api-data-source.js";
|
|
4
|
+
import { Logger } from "../logging/logger.service.js";
|
|
5
|
+
import { ConfigService } from "../config/config.service.js";
|
|
6
|
+
import { BlameLine, MergeRequestDiff } from "../types/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Local git repository data source implementation
|
|
9
|
+
*
|
|
10
|
+
* Provides access to git data through local git operations using simple-git.
|
|
11
|
+
* Falls back to GitLab API for operations that fail locally.
|
|
12
|
+
* Extends GitLabAPIDataSource to inherit API-based methods.
|
|
13
|
+
*/
|
|
14
|
+
export declare class LocalGitDataSource extends GitLabAPIDataSource implements GitDataSource {
|
|
15
|
+
private repoPath;
|
|
16
|
+
private config;
|
|
17
|
+
/**
|
|
18
|
+
* Create a new local git data source
|
|
19
|
+
*
|
|
20
|
+
* @param gitlabApi - GitLab API client instance for fallback operations
|
|
21
|
+
* @param repoPath - Path to the local git repository
|
|
22
|
+
* @param logger - Optional logger instance for logging operations
|
|
23
|
+
* @param config - Optional configuration service for settings
|
|
24
|
+
*/
|
|
25
|
+
constructor(gitlabApi: GitLabAPI, repoPath: string, logger?: Logger, config?: ConfigService);
|
|
26
|
+
/**
|
|
27
|
+
* Get the project path from the git remote URL
|
|
28
|
+
*
|
|
29
|
+
* Parses the origin remote URL to extract the project path.
|
|
30
|
+
* Supports SSH, HTTPS, and git protocol URLs.
|
|
31
|
+
*
|
|
32
|
+
* @returns Promise resolving to the project path (e.g., "group/project")
|
|
33
|
+
* @throws {MCPError} If no origin remote is found or URL format is unsupported
|
|
34
|
+
*/
|
|
35
|
+
getProjectFromRemote(): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Get the current branch name from the local repository
|
|
38
|
+
*
|
|
39
|
+
* @returns Promise resolving to the current branch name
|
|
40
|
+
* @throws {MCPError} If repository is in detached HEAD state or branch cannot be determined
|
|
41
|
+
*/
|
|
42
|
+
getCurrentBranch(): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Get the default branch from local git repository
|
|
45
|
+
*
|
|
46
|
+
* Queries the remote HEAD to determine the default branch.
|
|
47
|
+
* Falls back to GitLab API if local detection fails.
|
|
48
|
+
*
|
|
49
|
+
* @param project - The project ID or path
|
|
50
|
+
* @returns Promise resolving to the default branch name
|
|
51
|
+
* @throws {MCPError} If both local and API detection fail
|
|
52
|
+
*/
|
|
53
|
+
getDefaultBranch(project: string): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Get project contributors from local git history
|
|
56
|
+
*
|
|
57
|
+
* Analyzes commit history using configurable date range to identify contributors.
|
|
58
|
+
* Uses retry logic for git operations.
|
|
59
|
+
*
|
|
60
|
+
* @param project - The project ID or path (used for logging)
|
|
61
|
+
* @param commitSha - The commit SHA to analyze history from
|
|
62
|
+
* @returns Promise resolving to array of contributor email addresses (up to 100)
|
|
63
|
+
*/
|
|
64
|
+
getProjectContributors(project: string, commitSha: string): Promise<string[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Get git blame information from local repository
|
|
67
|
+
*
|
|
68
|
+
* Validates commit existence before attempting blame.
|
|
69
|
+
* Falls back to API if local blame fails (graceful degradation).
|
|
70
|
+
*
|
|
71
|
+
* @param project - The project ID or path
|
|
72
|
+
* @param path - The file path within the repository
|
|
73
|
+
* @param ref - The commit SHA to blame
|
|
74
|
+
* @returns Promise resolving to array of blame lines (empty array if both local and API fail)
|
|
75
|
+
*/
|
|
76
|
+
getBlame(project: string, path: string, ref: string): Promise<BlameLine[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Validates that a commit exists in the repository (Requirement 6.1)
|
|
79
|
+
*/
|
|
80
|
+
private validateCommitExists;
|
|
81
|
+
/**
|
|
82
|
+
* Get diffs for a merge request from local git repository
|
|
83
|
+
*
|
|
84
|
+
* Validates commits exist, handles special characters in paths,
|
|
85
|
+
* and fetches diffs in parallel for performance.
|
|
86
|
+
*
|
|
87
|
+
* @param project - The project ID or path
|
|
88
|
+
* @param mr - The merge request internal ID
|
|
89
|
+
* @returns Promise resolving to array of diffs
|
|
90
|
+
* @throws {MCPError} If merge request data is invalid or commits don't exist
|
|
91
|
+
*/
|
|
92
|
+
getDiffs(project: string, mr: number): Promise<MergeRequestDiff[]>;
|
|
93
|
+
/**
|
|
94
|
+
* Parses git name-status output with special character handling (Requirement 6.3)
|
|
95
|
+
*/
|
|
96
|
+
private parseGitNameStatus;
|
|
97
|
+
/**
|
|
98
|
+
* Gets diff for a single file with error handling
|
|
99
|
+
*/
|
|
100
|
+
private getDiffForFile;
|
|
101
|
+
/**
|
|
102
|
+
* Get raw file content from local repository
|
|
103
|
+
*
|
|
104
|
+
* Tries git show first, falls back to filesystem read if that fails.
|
|
105
|
+
*
|
|
106
|
+
* @param project - The project ID or path (used for logging)
|
|
107
|
+
* @param branch - The branch name
|
|
108
|
+
* @param path - The file path within the repository
|
|
109
|
+
* @returns Promise resolving to file content or null if not found
|
|
110
|
+
* @throws {MCPError} If file is not found in git or filesystem
|
|
111
|
+
*/
|
|
112
|
+
getRawFile(project: string, branch: string, path: string): Promise<string | null>;
|
|
113
|
+
/**
|
|
114
|
+
* Get and parse a JSON file from local repository
|
|
115
|
+
*
|
|
116
|
+
* @param project - The project ID or path
|
|
117
|
+
* @param branch - The branch name
|
|
118
|
+
* @param path - The file path within the repository
|
|
119
|
+
* @returns Promise resolving to parsed JSON object or null if not found
|
|
120
|
+
* @throws {MCPError} If the file cannot be parsed as JSON
|
|
121
|
+
*/
|
|
122
|
+
getJsonFile<T = unknown>(project: string, branch: string, path: string): Promise<T | null>;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=local-git-data-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-git-data-source.d.ts","sourceRoot":"","sources":["../../src/datasources/local-git-data-source.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEhE;;;;;;GAMG;AACH,qBAAa,kBACX,SAAQ,mBACR,YAAW,aAAa;IActB,OAAO,CAAC,QAAQ;IAZlB,OAAO,CAAC,MAAM,CAAgB;IAE9B;;;;;;;OAOG;gBAED,SAAS,EAAE,SAAS,EACZ,QAAQ,EAAE,MAAM,EACxB,MAAM,CAAC,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,aAAa;IAMxB;;;;;;;;OAQG;IACG,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC;IAyD7C;;;;;OAKG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAmCzC;;;;;;;;;OASG;IACG,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAwExD;;;;;;;;;OASG;IACG,sBAAsB,CAC1B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,M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