package plane_v2 import ( "fmt" "go.uber.org/zap" ) // ==================== Comment API ==================== // ListComments 列出工作项评论 func ListComments(slug, projectID, issueID string) ([]byte, error) { url := fmt.Sprintf("/api/workspaces/%s/projects/%s/issues/%s/comments/", slug, projectID, issueID) resp, err := planeWebGet(url) if err != nil { zap.L().Error("[PlaneWeb] ListComments 请求失败", zap.Error(err)) return nil, err } if !isWebSuccess(resp.StatusCode) { zap.L().Error("[PlaneWeb] ListComments 返回错误", zap.String("status", resp.Status)) return nil, fmt.Errorf("ListComments 失败: %s", resp.Status) } return resp.Body, nil } // CreateComment 创建评论 func CreateComment(slug, projectID, issueID, commentHTML string) ([]byte, error) { url := fmt.Sprintf("/api/workspaces/%s/projects/%s/issues/%s/comments/", slug, projectID, issueID) payload := map[string]interface{}{ "comment_html": commentHTML, } resp, err := planeWebPost(url, payload) if err != nil { zap.L().Error("[PlaneWeb] CreateComment 请求失败", zap.Error(err)) return nil, err } if resp.StatusCode != 201 { zap.L().Error("[PlaneWeb] CreateComment 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body)), ) return nil, fmt.Errorf("CreateComment 失败: %s", resp.Status) } return resp.Body, nil } // GetComment 获取评论详情 func GetComment(slug, projectID, issueID, commentID string) ([]byte, error) { url := fmt.Sprintf("/api/workspaces/%s/projects/%s/issues/%s/comments/%s/", slug, projectID, issueID, commentID) resp, err := planeWebGet(url) if err != nil { zap.L().Error("[PlaneWeb] GetComment 请求失败", zap.Error(err)) return nil, err } if !isWebSuccess(resp.StatusCode) { zap.L().Error("[PlaneWeb] GetComment 返回错误", zap.String("status", resp.Status)) return nil, fmt.Errorf("GetComment 失败: %s", resp.Status) } return resp.Body, nil } // UpdateComment 更新评论 func UpdateComment(slug, projectID, issueID, commentID, commentHTML string) ([]byte, error) { url := fmt.Sprintf("/api/workspaces/%s/projects/%s/issues/%s/comments/%s/", slug, projectID, issueID, commentID) payload := map[string]interface{}{ "comment_html": commentHTML, } resp, err := planeWebPatch(url, payload) if err != nil { zap.L().Error("[PlaneWeb] UpdateComment 请求失败", zap.Error(err)) return nil, err } if !isWebSuccess(resp.StatusCode) { zap.L().Error("[PlaneWeb] UpdateComment 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body)), ) return nil, fmt.Errorf("UpdateComment 失败: %s", resp.Status) } return resp.Body, nil } // DeleteComment 删除评论 func DeleteComment(slug, projectID, issueID, commentID string) error { url := fmt.Sprintf("/api/workspaces/%s/projects/%s/issues/%s/comments/%s/", slug, projectID, issueID, commentID) resp, err := planeWebDelete(url) if err != nil { zap.L().Error("[PlaneWeb] DeleteComment 请求失败", zap.Error(err)) return err } if resp.StatusCode != 204 { zap.L().Error("[PlaneWeb] DeleteComment 返回错误", zap.String("status", resp.Status)) return fmt.Errorf("DeleteComment 失败: %s", resp.Status) } return nil }