update_file
Modify existing files in Codeup repositories by providing new content, commit messages, and branch specifications for version-controlled code updates.
Instructions
[Code Management] Update an existing file in 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 | |
| content | Yes | File content | |
| commitMessage | Yes | Commit message, not empty, no more than 102400 characters | |
| branch | Yes | Branch name | |
| encoding | No | Encoding rule, options {text, base64}, default is text | text |
Implementation Reference
- tool-handlers/code-management.ts:95-108 (handler)Handler case for 'update_file' tool that parses arguments with UpdateFileSchema and calls the updateFileFunc helper.case "update_file": { const args = types.UpdateFileSchema.parse(request.params.arguments); const result = await files.updateFileFunc( args.organizationId, args.repositoryId, args.filePath, args.content, args.commitMessage, args.branch, args.encoding ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], };
- operations/codeup/files.ts:155-201 (helper)Core implementation of updateFileFunc that performs the PUT request to update the file content in Codeup repository.export async function updateFileFunc( organizationId: string, repositoryId: string, filePath: string, content: string, commitMessage: string, branch: string, encoding?: string ): Promise<z.infer<typeof CreateFileResponseSchema>> { //const { encodedRepoId, encodedFilePath } = handlePathEncoding(repositoryId, filePath); let encodedRepoId = repositoryId; let encodedFilePath = filePath; // 自动处理repositoryId中未编码的斜杠 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("/")) { const pathToEncode = filePath.startsWith("/") ? filePath.substring(1) : filePath; encodedFilePath = encodeURIComponent(pathToEncode); } const url = `/oapi/v1/codeup/organizations/${organizationId}/repositories/${encodedRepoId}/files/${encodedFilePath}`; const body = { branch: branch, commitMessage: commitMessage, content: content, encoding: encoding || "text" // 默认使用text编码 }; const response = await yunxiaoRequest(url, { method: "PUT", body: body }); return CreateFileResponseSchema.parse(response); }
- operations/codeup/types.ts:281-289 (schema)Zod schema definition for UpdateFileSchema used for input validation of the update_file tool.export const UpdateFileSchema = 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"), content: z.string().describe("File content"), commitMessage: z.string().describe("Commit message, not empty, no more than 102400 characters"), branch: z.string().describe("Branch name"), encoding: z.string().default("text").optional().describe("Encoding rule, options {text, base64}, default is text"), });
- tool-registry/code-management.ts:39-43 (registration)Tool registration for 'update_file' including name, description, and input schema reference.{ name: "update_file", description: "[Code Management] Update an existing file in a Codeup repository", inputSchema: zodToJsonSchema(types.UpdateFileSchema), },