delete_file
Remove files from Alibaba Cloud Codeup repositories to manage code changes and maintain repository organization.
Instructions
[Code Management] Delete a file from a Codeup repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| organizationId | Yes | Organization ID, can be found in the basic information page of the organization admin console | |
| repositoryId | Yes | Repository ID or a combination of organization ID and repository name, for example: 2835387 or organizationId%2Frepo-name (Note: slashes need to be URL encoded as %2F) | |
| filePath | Yes | File path, needs to be URL encoded, for example: /src/main/java/com/aliyun/test.java | |
| commitMessage | Yes | Commit message | |
| branch | Yes | Branch name |
Implementation Reference
- tool-handlers/code-management.ts:111-123 (handler)Handler for the 'delete_file' tool: parses input arguments using DeleteFileSchema and calls the deleteFileFunc helper to perform the deletion, then returns the result as JSON.case "delete_file": { const args = types.DeleteFileSchema.parse(request.params.arguments); const result = await files.deleteFileFunc( args.organizationId, args.repositoryId, args.filePath, args.commitMessage, args.branch ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }
- tool-registry/code-management.ts:44-48 (registration)Registers the 'delete_file' tool in the code management tools array, specifying name, description, and input schema.{ name: "delete_file", description: "[Code Management] Delete a file from a Codeup repository", inputSchema: zodToJsonSchema(types.DeleteFileSchema), },
- operations/codeup/files.ts:211-253 (helper)Core helper function that encodes parameters, constructs the API URL, sends DELETE request to Codeup API to delete the file, and parses the response.export async function deleteFileFunc( organizationId: string, repositoryId: string, filePath: string, commitMessage: string, branch: string ): Promise<z.infer<typeof DeleteFileResponseSchema>> { let encodedRepoId = repositoryId; let encodedFilePath = filePath; if (repositoryId.includes("/")) { // 发现未编码的斜杠,自动进行URL编码 const parts = repositoryId.split("/", 2); if (parts.length === 2) { const encodedRepoName = encodeURIComponent(parts[1]); // 移除编码中的+号(空格被编码为+,但我们需要%20) const formattedEncodedName = encodedRepoName.replace(/\+/g, "%20"); encodedRepoId = `${parts[0]}%2F${formattedEncodedName}`; } } // 确保filePath已被URL编码 if (filePath.includes("/")) { encodedFilePath = encodeURIComponent(filePath); } const baseUrl = `/oapi/v1/codeup/organizations/${organizationId}/repositories/${encodedRepoId}/files/${encodedFilePath}`; // 构建查询参数 const queryParams: Record<string, string | number | undefined> = { branch: branch, commitMessage: commitMessage }; // 使用buildUrl函数构建包含查询参数的URL const url = buildUrl(baseUrl, queryParams); const response = await yunxiaoRequest(url, { method: "DELETE", }); return DeleteFileResponseSchema.parse(response); }
- operations/codeup/types.ts:291-297 (schema)Zod schema defining the input parameters for the delete_file tool: organizationId, repositoryId, filePath, commitMessage, branch.export const DeleteFileSchema = z.object({ organizationId: z.string().describe("Organization ID, can be found in the basic information page of the organization admin console"), repositoryId: z.string().describe("Repository ID or a combination of organization ID and repository name, for example: 2835387 or organizationId%2Frepo-name (Note: slashes need to be URL encoded as %2F)"), filePath: z.string().describe("File path, needs to be URL encoded, for example: /src/main/java/com/aliyun/test.java"), commitMessage: z.string().describe("Commit message"), branch: z.string().describe("Branch name"), });