in operations/codeup/changeRequestComments.ts [27:79]
export async function createChangeRequestCommentFunc(
organizationId: string,
repositoryId: string,
localId: string,
comment_type: string, // Possible values: GLOBAL_COMMENT, INLINE_COMMENT
content: string,
draft: boolean,
resolved: boolean,
patchset_biz_id: string,
file_path?: string,
line_number?: number,
from_patchset_biz_id?: string,
to_patchset_biz_id?: string,
parent_comment_biz_id?: string
): Promise<z.infer<typeof ChangeRequestCommentSchema>> {
const encodedRepoId = handleRepositoryIdEncoding(repositoryId);
const url = `/oapi/v1/codeup/organizations/${organizationId}/repositories/${encodedRepoId}/changeRequests/${localId}/comments`;
// 准备payload
const payload: Record<string, any> = {
comment_type: comment_type,
content: content,
draft: draft,
resolved: resolved,
patchset_biz_id: patchset_biz_id,
};
// 根据评论类型添加必要参数
if (comment_type === "INLINE_COMMENT") {
// 检查INLINE_COMMENT必需的参数
if (!file_path || line_number === undefined || !from_patchset_biz_id || !to_patchset_biz_id) {
throw new Error("For INLINE_COMMENT, file_path, line_number, from_patchset_biz_id, and to_patchset_biz_id are required");
}
payload.file_path = file_path;
payload.line_number = line_number;
payload.from_patchset_biz_id = from_patchset_biz_id;
payload.to_patchset_biz_id = to_patchset_biz_id;
}
// 添加可选参数
if (parent_comment_biz_id) {
payload.parent_comment_biz_id = parent_comment_biz_id;
}
const response = await yunxiaoRequest(url, {
method: "POST",
body: payload,
});
return ChangeRequestCommentSchema.parse(response);
}