package plane_v1 import ( "fmt" "go.uber.org/zap" ) // ==================== Work Item Comment API ==================== // ListWorkItemComments 列出工作项评论 func ListWorkItemComments(workItemID string) ([]byte, error) { path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/work-items/%s/comments/", planeWorkspaceSlug, planeProjectId, workItemID) resp, err := planeHttpGet(path) if err != nil { zap.L().Error("[Plane] ListWorkItemComments 请求失败", zap.Error(err)) return nil, err } if !isSuccess(resp.StatusCode) { zap.L().Error("[Plane] ListWorkItemComments 返回错误", zap.String("status", resp.Status)) return nil, fmt.Errorf("ListWorkItemComments 失败: %s", resp.Status) } return resp.Body, nil } // CreateWorkItemComment 创建评论 func CreateWorkItemComment(workItemID, commentHTML string) ([]byte, error) { path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/work-items/%s/comments/", planeWorkspaceSlug, planeProjectId, workItemID) payload := map[string]interface{}{"comment_html": commentHTML} resp, err := planeHttpPost(path, payload) if err != nil { zap.L().Error("[Plane] CreateWorkItemComment 请求失败", zap.Error(err)) return nil, err } if resp.StatusCode != 201 { zap.L().Error("[Plane] CreateWorkItemComment 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body))) return nil, fmt.Errorf("CreateWorkItemComment 失败: %s", resp.Status) } return resp.Body, nil } // GetWorkItemComment 获取评论详情 func GetWorkItemComment(workItemID, commentID string) ([]byte, error) { path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/work-items/%s/comments/%s/", planeWorkspaceSlug, planeProjectId, workItemID, commentID) resp, err := planeHttpGet(path) if err != nil { zap.L().Error("[Plane] GetWorkItemComment 请求失败", zap.Error(err)) return nil, err } if !isSuccess(resp.StatusCode) { zap.L().Error("[Plane] GetWorkItemComment 返回错误", zap.String("status", resp.Status)) return nil, fmt.Errorf("GetWorkItemComment 失败: %s", resp.Status) } return resp.Body, nil } // UpdateWorkItemComment 更新评论 func UpdateWorkItemComment(workItemID, commentID, commentHTML string) ([]byte, error) { path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/work-items/%s/comments/%s/", planeWorkspaceSlug, planeProjectId, workItemID, commentID) payload := map[string]interface{}{"comment_html": commentHTML} resp, err := planeHttpPatch(path, payload) if err != nil { zap.L().Error("[Plane] UpdateWorkItemComment 请求失败", zap.Error(err)) return nil, err } if !isSuccess(resp.StatusCode) { zap.L().Error("[Plane] UpdateWorkItemComment 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body))) return nil, fmt.Errorf("UpdateWorkItemComment 失败: %s", resp.Status) } return resp.Body, nil } // DeleteWorkItemComment 删除评论 func DeleteWorkItemComment(workItemID, commentID string) error { path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/work-items/%s/comments/%s/", planeWorkspaceSlug, planeProjectId, workItemID, commentID) resp, err := planeHttpDelete(path) if err != nil { zap.L().Error("[Plane] DeleteWorkItemComment 请求失败", zap.Error(err)) return err } if resp.StatusCode != 204 { zap.L().Error("[Plane] DeleteWorkItemComment 返回错误", zap.String("status", resp.Status)) return fmt.Errorf("DeleteWorkItemComment 失败: %s", resp.Status) } return nil }