forked from zereight/gitlab-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-resolve-issue-note.ts
More file actions
153 lines (136 loc) · 4.57 KB
/
test-resolve-issue-note.ts
File metadata and controls
153 lines (136 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* This test file demonstrates the new resolve functionality for issue notes.
* It shows how to use the update_issue_note tool to resolve or unresolve
* issue discussion threads.
*/
import fetch from "node-fetch";
// GitLab API configuration (replace with actual values when testing)
const GITLAB_API_URL = process.env.GITLAB_API_URL || "https://gitlab.com";
const GITLAB_PERSONAL_ACCESS_TOKEN = process.env.GITLAB_TOKEN || "";
const PROJECT_ID = process.env.PROJECT_ID || "your/project";
const ISSUE_IID = Number(process.env.ISSUE_IID || "1");
const DISCUSSION_ID = process.env.DISCUSSION_ID || "your-discussion-id";
const NOTE_ID = process.env.NOTE_ID || "your-note-id";
/**
* Test resolving an issue note
*/
async function testResolveIssueNote() {
try {
const url = new URL(
`${GITLAB_API_URL}/api/v4/projects/${encodeURIComponent(
PROJECT_ID
)}/issues/${ISSUE_IID}/discussions/${DISCUSSION_ID}/notes/${NOTE_ID}`
);
const response = await fetch(url.toString(), {
method: "PUT",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Bearer ${GITLAB_PERSONAL_ACCESS_TOKEN}`,
},
body: JSON.stringify({ resolved: true }),
});
if (!response.ok) {
const errorBody = await response.text();
throw new Error(`GitLab API error: ${response.status} ${response.statusText}\n${errorBody}`);
}
const data = await response.json();
console.log("Successfully resolved issue note:");
console.log(JSON.stringify(data, null, 2));
return true;
} catch (error) {
console.error("Error resolving issue note:", error);
return false;
}
}
/**
* Test unresolving an issue note
*/
async function testUnresolveIssueNote() {
try {
const url = new URL(
`${GITLAB_API_URL}/api/v4/projects/${encodeURIComponent(
PROJECT_ID
)}/issues/${ISSUE_IID}/discussions/${DISCUSSION_ID}/notes/${NOTE_ID}`
);
const response = await fetch(url.toString(), {
method: "PUT",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Bearer ${GITLAB_PERSONAL_ACCESS_TOKEN}`,
},
body: JSON.stringify({ resolved: false }),
});
if (!response.ok) {
const errorBody = await response.text();
throw new Error(`GitLab API error: ${response.status} ${response.statusText}\n${errorBody}`);
}
const data = await response.json();
console.log("Successfully unresolved issue note:");
console.log(JSON.stringify(data, null, 2));
return true;
} catch (error) {
console.error("Error unresolving issue note:", error);
return false;
}
}
/**
* Test updating note body (existing functionality should still work)
*/
async function testUpdateIssueNoteBody() {
try {
const url = new URL(
`${GITLAB_API_URL}/api/v4/projects/${encodeURIComponent(
PROJECT_ID
)}/issues/${ISSUE_IID}/discussions/${DISCUSSION_ID}/notes/${NOTE_ID}`
);
const response = await fetch(url.toString(), {
method: "PUT",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Bearer ${GITLAB_PERSONAL_ACCESS_TOKEN}`,
},
body: JSON.stringify({ body: "Updated note content" }),
});
if (!response.ok) {
const errorBody = await response.text();
throw new Error(`GitLab API error: ${response.status} ${response.statusText}\n${errorBody}`);
}
const data = await response.json();
console.log("Successfully updated issue note body:");
console.log(JSON.stringify(data, null, 2));
return true;
} catch (error) {
console.error("Error updating issue note body:", error);
return false;
}
}
// Only run the test if executed directly
if (require.main === module) {
console.log("Testing issue note resolve functionality...\n");
console.log("Note: This is a demonstration test file.");
console.log("To run actual tests, set the following environment variables:");
console.log(" - GITLAB_API_URL");
console.log(" - GITLAB_TOKEN");
console.log(" - PROJECT_ID");
console.log(" - ISSUE_IID");
console.log(" - DISCUSSION_ID");
console.log(" - NOTE_ID");
console.log("\nExample MCP tool usage:");
console.log(`
{
"name": "update_issue_note",
"arguments": {
"project_id": "your/project",
"issue_iid": "1",
"discussion_id": "abc123",
"note_id": "456",
"resolved": true
}
}
`);
}
// Export for use in other tests
export { testResolveIssueNote, testUnresolveIssueNote, testUpdateIssueNoteBody };