in operations/codeup/files.ts [273:324]
export async function listFilesFunc(
organizationId: string,
repositoryId: string,
path?: string,
ref?: string,
type?: string // Possible values: DIRECT, RECURSIVE, FLATTEN
): Promise<z.infer<typeof FileInfoSchema>[]> {
// 自动处理repositoryId中未编码的斜杠
let encodedRepoId = 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}`;
}
}
const baseUrl = `/oapi/v1/codeup/organizations/${organizationId}/repositories/${encodedRepoId}/files/tree`;
// 构建查询参数
const queryParams: Record<string, string | number | undefined> = {};
if (path) {
queryParams.path = path;
}
if (ref) {
queryParams.ref = ref;
}
if (type) {
queryParams.type = type;
}
// 使用buildUrl函数构建包含查询参数的URL
const url = buildUrl(baseUrl, queryParams);
const response = await yunxiaoRequest(url, {
method: "GET",
});
// 确保响应是数组
if (!Array.isArray(response)) {
return [];
}
// 解析每个文件信息对象
return response.map(fileInfo => FileInfoSchema.parse(fileInfo));
}