get_file_blobs
Retrieve file content from Alibaba Cloud Codeup repositories using organization ID, repository ID, file path, and branch reference for code management workflows.
Instructions
[Code Management] Get file content 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 | |
| ref | Yes | Reference name, usually branch name, can be branch name, tag name or commit SHA. If not provided, the default branch of the repository will be used, such as master |
Implementation Reference
- tool-handlers/code-management.ts:66-77 (handler)Handler case in handleCodeManagementTools function that validates input with GetFileBlobsSchema and invokes files.getFileBlobsFunc to retrieve file contents, then returns JSON stringified response.case "get_file_blobs": { const args = types.GetFileBlobsSchema.parse(request.params.arguments); const fileContent = await files.getFileBlobsFunc( args.organizationId, args.repositoryId, args.filePath, args.ref ); return { content: [{ type: "text", text: JSON.stringify(fileContent, null, 2) }], }; }
- operations/codeup/files.ts:46-87 (helper)Core implementation function getFileBlobsFunc that encodes paths, constructs API URL, makes GET request to Codeup API for file content, and parses response with FileContentSchema.export async function getFileBlobsFunc( organizationId: string, repositoryId: string, filePath: string, ref: string ): Promise<z.infer<typeof FileContentSchema>> { // 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("/")) { encodedFilePath = encodeURIComponent(filePath); } const baseUrl = `/oapi/v1/codeup/organizations/${organizationId}/repositories/${encodedRepoId}/files/${encodedFilePath}`; // 构建查询参数 const queryParams: Record<string, string | number | undefined> = { ref: ref }; // 使用buildUrl函数构建包含查询参数的URL const url = buildUrl(baseUrl, queryParams); const response = await yunxiaoRequest(url, { method: "GET", }); return FileContentSchema.parse(response); }
- tool-registry/code-management.ts:29-33 (registration)Tool registration entry in getCodeManagementTools array, specifying name, description, and input schema derived from GetFileBlobsSchema.{ name: "get_file_blobs", description: "[Code Management] Get file content from a Codeup repository", inputSchema: zodToJsonSchema(types.GetFileBlobsSchema), },
- operations/codeup/types.ts:264-269 (schema)Zod input schema definition for get_file_blobs tool parameters: organizationId, repositoryId, filePath, ref.export const GetFileBlobsSchema = 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"), ref: z.string().describe("Reference name, usually branch name, can be branch name, tag name or commit SHA. If not provided, the default branch of the repository will be used, such as master"), });