Skip to content

Commit 891b5b1

Browse files
authored
fix(mrs): use global API endpoints for code change proposals (#116)
Change endpoints from nested project paths to global paths: - PUT /suggestions/:id/apply - PUT /suggestions/batch_apply Fixes #115
1 parent 1f154c4 commit 891b5b1

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/entities/mrs/registry.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -418,22 +418,26 @@ export const mrsToolRegistry: ToolRegistry = new Map<string, EnhancedToolDefinit
418418

419419
case "apply_suggestion": {
420420
// TypeScript knows: input has suggestion_id (required), commit_message (optional)
421-
const { project_id, merge_request_iid, suggestion_id, commit_message } = input;
421+
// Note: project_id and merge_request_iid are in schema for context but not used in API
422+
// GitLab suggestions API uses global endpoint: PUT /suggestions/:id/apply
423+
const { suggestion_id, commit_message } = input;
422424

423425
const body: Record<string, unknown> = {};
424426
if (commit_message) {
425427
body.commit_message = commit_message;
426428
}
427429

428-
return gitlab.put(
429-
`projects/${normalizeProjectId(project_id)}/merge_requests/${merge_request_iid}/suggestions/${suggestion_id}/apply`,
430-
{ body: Object.keys(body).length > 0 ? body : undefined, contentType: "json" }
431-
);
430+
return gitlab.put(`suggestions/${suggestion_id}/apply`, {
431+
body: Object.keys(body).length > 0 ? body : undefined,
432+
contentType: "json",
433+
});
432434
}
433435

434436
case "apply_suggestions": {
435437
// TypeScript knows: input has suggestion_ids (required), commit_message (optional)
436-
const { project_id, merge_request_iid, suggestion_ids, commit_message } = input;
438+
// Note: project_id and merge_request_iid are in schema for context but not used in API
439+
// GitLab suggestions API uses global endpoint: PUT /suggestions/batch_apply
440+
const { suggestion_ids, commit_message } = input;
437441

438442
const body: Record<string, unknown> = {
439443
ids: suggestion_ids,
@@ -442,10 +446,7 @@ export const mrsToolRegistry: ToolRegistry = new Map<string, EnhancedToolDefinit
442446
body.commit_message = commit_message;
443447
}
444448

445-
return gitlab.put(
446-
`projects/${normalizeProjectId(project_id)}/merge_requests/${merge_request_iid}/suggestions/batch_apply`,
447-
{ body, contentType: "json" }
448-
);
449+
return gitlab.put(`suggestions/batch_apply`, { body, contentType: "json" });
449450
}
450451

451452
case "resolve": {

tests/unit/entities/mrs/registry.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,8 +1162,9 @@ describe("MRS Registry", () => {
11621162
suggestion_id: 12345,
11631163
});
11641164

1165+
// GitLab suggestions API uses global endpoint: PUT /suggestions/:id/apply
11651166
expect(mockGitlab.put).toHaveBeenCalledWith(
1166-
"projects/test%2Fproject/merge_requests/42/suggestions/12345/apply",
1167+
"suggestions/12345/apply",
11671168
expect.objectContaining({
11681169
body: undefined,
11691170
contentType: "json",
@@ -1185,8 +1186,9 @@ describe("MRS Registry", () => {
11851186
commit_message: "Apply suggestion: fix typo",
11861187
});
11871188

1189+
// GitLab suggestions API uses global endpoint: PUT /suggestions/:id/apply
11881190
expect(mockGitlab.put).toHaveBeenCalledWith(
1189-
"projects/test%2Fproject/merge_requests/42/suggestions/12345/apply",
1191+
"suggestions/12345/apply",
11901192
expect.objectContaining({
11911193
body: { commit_message: "Apply suggestion: fix typo" },
11921194
contentType: "json",
@@ -1209,8 +1211,9 @@ describe("MRS Registry", () => {
12091211
suggestion_ids: [12345, 12346, 12347],
12101212
});
12111213

1214+
// GitLab suggestions API uses global endpoint: PUT /suggestions/batch_apply
12121215
expect(mockGitlab.put).toHaveBeenCalledWith(
1213-
"projects/test%2Fproject/merge_requests/42/suggestions/batch_apply",
1216+
"suggestions/batch_apply",
12141217
expect.objectContaining({
12151218
body: { ids: [12345, 12346, 12347] },
12161219
contentType: "json",
@@ -1232,8 +1235,9 @@ describe("MRS Registry", () => {
12321235
commit_message: "Apply code review suggestions",
12331236
});
12341237

1238+
// GitLab suggestions API uses global endpoint: PUT /suggestions/batch_apply
12351239
expect(mockGitlab.put).toHaveBeenCalledWith(
1236-
"projects/test%2Fproject/merge_requests/42/suggestions/batch_apply",
1240+
"suggestions/batch_apply",
12371241
expect.objectContaining({
12381242
body: {
12391243
ids: [12345, 12346],

0 commit comments

Comments
 (0)