1+ import * as branches from '../operations/codeup/branches.js' ;
2+ import * as files from '../operations/codeup/files.js' ;
3+ import * as repositories from '../operations/codeup/repositories.js' ;
4+ import * as changeRequests from '../operations/codeup/changeRequests.js' ;
5+ import * as changeRequestComments from '../operations/codeup/changeRequestComments.js' ;
6+ import * as compare from '../operations/codeup/compare.js' ;
7+ import * as types from '../common/types.js' ;
8+ import { z } from 'zod' ;
9+
10+ export const handleCodeManagementTools = async ( request : any ) => {
11+ switch ( request . params . name ) {
12+ // Branch Operations
13+ case "create_branch" : {
14+ const args = types . CreateBranchSchema . parse ( request . params . arguments ) ;
15+ const branch = await branches . createBranchFunc (
16+ args . organizationId ,
17+ args . repositoryId ,
18+ args . branch ,
19+ args . ref
20+ ) ;
21+ return {
22+ content : [ { type : "text" , text : JSON . stringify ( branch , null , 2 ) } ] ,
23+ } ;
24+ }
25+
26+ case "get_branch" : {
27+ const args = types . GetBranchSchema . parse ( request . params . arguments ) ;
28+ const branch = await branches . getBranchFunc (
29+ args . organizationId ,
30+ args . repositoryId ,
31+ args . branchName
32+ ) ;
33+ return {
34+ content : [ { type : "text" , text : JSON . stringify ( branch , null , 2 ) } ] ,
35+ } ;
36+ }
37+
38+ case "delete_branch" : {
39+ const args = types . DeleteBranchSchema . parse ( request . params . arguments ) ;
40+ const result = await branches . deleteBranchFunc (
41+ args . organizationId ,
42+ args . repositoryId ,
43+ args . branchName
44+ ) ;
45+ return {
46+ content : [ { type : "text" , text : JSON . stringify ( result , null , 2 ) } ] ,
47+ } ;
48+ }
49+
50+ case "list_branches" : {
51+ const args = types . ListBranchesSchema . parse ( request . params . arguments ) ;
52+ const branchList = await branches . listBranchesFunc (
53+ args . organizationId ,
54+ args . repositoryId ,
55+ args . page ,
56+ args . perPage ,
57+ args . sort ,
58+ args . search ?? undefined
59+ ) ;
60+ return {
61+ content : [ { type : "text" , text : JSON . stringify ( branchList , null , 2 ) } ] ,
62+ } ;
63+ }
64+
65+ // File Operations
66+ case "get_file_blobs" : {
67+ const args = types . GetFileBlobsSchema . parse ( request . params . arguments ) ;
68+ const fileContent = await files . getFileBlobsFunc (
69+ args . organizationId ,
70+ args . repositoryId ,
71+ args . filePath ,
72+ args . ref
73+ ) ;
74+ return {
75+ content : [ { type : "text" , text : JSON . stringify ( fileContent , null , 2 ) } ] ,
76+ } ;
77+ }
78+
79+ case "create_file" : {
80+ const args = types . CreateFileSchema . parse ( request . params . arguments ) ;
81+ const result = await files . createFileFunc (
82+ args . organizationId ,
83+ args . repositoryId ,
84+ args . filePath ,
85+ args . content ,
86+ args . commitMessage ,
87+ args . branch ,
88+ args . encoding
89+ ) ;
90+ return {
91+ content : [ { type : "text" , text : JSON . stringify ( result , null , 2 ) } ] ,
92+ } ;
93+ }
94+
95+ case "update_file" : {
96+ const args = types . UpdateFileSchema . parse ( request . params . arguments ) ;
97+ const result = await files . updateFileFunc (
98+ args . organizationId ,
99+ args . repositoryId ,
100+ args . filePath ,
101+ args . content ,
102+ args . commitMessage ,
103+ args . branch ,
104+ args . encoding
105+ ) ;
106+ return {
107+ content : [ { type : "text" , text : JSON . stringify ( result , null , 2 ) } ] ,
108+ } ;
109+ }
110+
111+ case "delete_file" : {
112+ const args = types . DeleteFileSchema . parse ( request . params . arguments ) ;
113+ const result = await files . deleteFileFunc (
114+ args . organizationId ,
115+ args . repositoryId ,
116+ args . filePath ,
117+ args . commitMessage ,
118+ args . branch
119+ ) ;
120+ return {
121+ content : [ { type : "text" , text : JSON . stringify ( result , null , 2 ) } ] ,
122+ } ;
123+ }
124+
125+ case "list_files" : {
126+ const args = types . ListFilesSchema . parse ( request . params . arguments ) ;
127+ const fileList = await files . listFilesFunc (
128+ args . organizationId ,
129+ args . repositoryId ,
130+ args . path ,
131+ args . ref ,
132+ args . type
133+ ) ;
134+ return {
135+ content : [ { type : "text" , text : JSON . stringify ( fileList , null , 2 ) } ] ,
136+ } ;
137+ }
138+
139+ case "compare" : {
140+ const args = types . GetCompareSchema . parse ( request . params . arguments ) ;
141+ const compareResult = await compare . getCompareFunc (
142+ args . organizationId ,
143+ args . repositoryId ,
144+ args . from ,
145+ args . to ,
146+ args . sourceType ?? undefined ,
147+ args . targetType ?? undefined ,
148+ args . straight ?? undefined
149+ ) ;
150+
151+ return {
152+ content : [ { type : "text" , text : JSON . stringify ( compareResult , null , 2 ) } ] ,
153+ } ;
154+ }
155+
156+ // Repository Operations
157+ case "get_repository" : {
158+ const args = types . GetRepositorySchema . parse ( request . params . arguments ) ;
159+ const repository = await repositories . getRepositoryFunc (
160+ args . organizationId ,
161+ args . repositoryId
162+ ) ;
163+ return {
164+ content : [ { type : "text" , text : JSON . stringify ( repository , null , 2 ) } ] ,
165+ } ;
166+ }
167+
168+ case "list_repositories" : {
169+ const args = types . ListRepositoriesSchema . parse ( request . params . arguments ) ;
170+ const repositoryList = await repositories . listRepositoriesFunc (
171+ args . organizationId ,
172+ args . page ,
173+ args . perPage ,
174+ args . orderBy ,
175+ args . sort ,
176+ args . search ?? undefined ,
177+ args . archived
178+ ) ;
179+ return {
180+ content : [ { type : "text" , text : JSON . stringify ( repositoryList , null , 2 ) } ] ,
181+ } ;
182+ }
183+
184+ // Change Request Operations
185+ case "get_change_request" : {
186+ const args = types . GetChangeRequestSchema . parse ( request . params . arguments ) ;
187+ const changeRequest = await changeRequests . getChangeRequestFunc (
188+ args . organizationId ,
189+ args . repositoryId ,
190+ args . localId
191+ ) ;
192+ return {
193+ content : [ { type : "text" , text : JSON . stringify ( changeRequest , null , 2 ) } ] ,
194+ } ;
195+ }
196+
197+ case "list_change_requests" : {
198+ const args = types . ListChangeRequestsSchema . parse ( request . params . arguments ) ;
199+ const changeRequestList = await changeRequests . listChangeRequestsFunc (
200+ args . organizationId ,
201+ args . page ,
202+ args . perPage ,
203+ args . projectIds ?? undefined ,
204+ args . authorIds ?? undefined ,
205+ args . reviewerIds ?? undefined ,
206+ args . state ?? undefined ,
207+ args . search ?? undefined ,
208+ args . orderBy ,
209+ args . sort ,
210+ args . createdBefore ?? undefined ,
211+ args . createdAfter ?? undefined
212+ ) ;
213+ return {
214+ content : [ { type : "text" , text : JSON . stringify ( changeRequestList , null , 2 ) } ] ,
215+ } ;
216+ }
217+
218+ case "create_change_request" : {
219+ const args = types . CreateChangeRequestSchema . parse ( request . params . arguments ) ;
220+ const changeRequest = await changeRequests . createChangeRequestFunc (
221+ args . organizationId ,
222+ args . repositoryId ,
223+ args . title ,
224+ args . sourceBranch ,
225+ args . targetBranch ,
226+ args . description ?? undefined ,
227+ args . sourceProjectId ,
228+ args . targetProjectId ,
229+ args . reviewerUserIds ?? undefined ,
230+ args . workItemIds ?? undefined ,
231+ args . createFrom
232+ ) ;
233+ return {
234+ content : [ { type : "text" , text : JSON . stringify ( changeRequest , null , 2 ) } ] ,
235+ } ;
236+ }
237+
238+ case "create_change_request_comment" : {
239+ const args = types . CreateChangeRequestCommentSchema . parse ( request . params . arguments ) ;
240+ const comment = await changeRequestComments . createChangeRequestCommentFunc (
241+ args . organizationId ,
242+ args . repositoryId ,
243+ args . localId ,
244+ args . comment_type ,
245+ args . content ,
246+ args . draft ,
247+ args . resolved ,
248+ args . patchset_biz_id ,
249+ args . file_path ?? undefined ,
250+ args . line_number ?? undefined ,
251+ args . from_patchset_biz_id ?? undefined ,
252+ args . to_patchset_biz_id ?? undefined ,
253+ args . parent_comment_biz_id ?? undefined
254+ ) ;
255+ return {
256+ content : [ { type : "text" , text : JSON . stringify ( comment , null , 2 ) } ] ,
257+ } ;
258+ }
259+
260+ case "list_change_request_comments" : {
261+ const args = types . ListChangeRequestCommentsSchema . parse ( request . params . arguments ) ;
262+ const comments = await changeRequestComments . listChangeRequestCommentsFunc (
263+ args . organizationId ,
264+ args . repositoryId ,
265+ args . localId ,
266+ args . patchSetBizIds ?? undefined ,
267+ args . commentType ,
268+ args . state ,
269+ args . resolved ,
270+ args . filePath ?? undefined
271+ ) ;
272+ return {
273+ content : [ { type : "text" , text : JSON . stringify ( comments , null , 2 ) } ] ,
274+ } ;
275+ }
276+
277+ case "list_change_request_patch_sets" : {
278+ const args = types . ListChangeRequestPatchSetsSchema . parse ( request . params . arguments ) ;
279+ const patchSets = await changeRequests . listChangeRequestPatchSetsFunc (
280+ args . organizationId ,
281+ args . repositoryId ,
282+ args . localId
283+ ) ;
284+
285+ return {
286+ content : [ { type : "text" , text : JSON . stringify ( patchSets , null , 2 ) } ] ,
287+ } ;
288+ }
289+
290+ default :
291+ return null ;
292+ }
293+ } ;
0 commit comments