plane_comment.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package plane_v1
  2. import (
  3. "fmt"
  4. "go.uber.org/zap"
  5. )
  6. // ==================== Work Item Comment API ====================
  7. // ListWorkItemComments 列出工作项评论
  8. func ListWorkItemComments(workItemID string) ([]byte, error) {
  9. path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/work-items/%s/comments/", planeWorkspaceSlug, planeProjectId, workItemID)
  10. resp, err := planeHttpGet(path)
  11. if err != nil {
  12. zap.L().Error("[Plane] ListWorkItemComments 请求失败", zap.Error(err))
  13. return nil, err
  14. }
  15. if !isSuccess(resp.StatusCode) {
  16. zap.L().Error("[Plane] ListWorkItemComments 返回错误", zap.String("status", resp.Status))
  17. return nil, fmt.Errorf("ListWorkItemComments 失败: %s", resp.Status)
  18. }
  19. return resp.Body, nil
  20. }
  21. // CreateWorkItemComment 创建评论
  22. func CreateWorkItemComment(workItemID, commentHTML string) ([]byte, error) {
  23. path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/work-items/%s/comments/", planeWorkspaceSlug, planeProjectId, workItemID)
  24. payload := map[string]interface{}{"comment_html": commentHTML}
  25. resp, err := planeHttpPost(path, payload)
  26. if err != nil {
  27. zap.L().Error("[Plane] CreateWorkItemComment 请求失败", zap.Error(err))
  28. return nil, err
  29. }
  30. if resp.StatusCode != 201 {
  31. zap.L().Error("[Plane] CreateWorkItemComment 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body)))
  32. return nil, fmt.Errorf("CreateWorkItemComment 失败: %s", resp.Status)
  33. }
  34. return resp.Body, nil
  35. }
  36. // GetWorkItemComment 获取评论详情
  37. func GetWorkItemComment(workItemID, commentID string) ([]byte, error) {
  38. path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/work-items/%s/comments/%s/", planeWorkspaceSlug, planeProjectId, workItemID, commentID)
  39. resp, err := planeHttpGet(path)
  40. if err != nil {
  41. zap.L().Error("[Plane] GetWorkItemComment 请求失败", zap.Error(err))
  42. return nil, err
  43. }
  44. if !isSuccess(resp.StatusCode) {
  45. zap.L().Error("[Plane] GetWorkItemComment 返回错误", zap.String("status", resp.Status))
  46. return nil, fmt.Errorf("GetWorkItemComment 失败: %s", resp.Status)
  47. }
  48. return resp.Body, nil
  49. }
  50. // UpdateWorkItemComment 更新评论
  51. func UpdateWorkItemComment(workItemID, commentID, commentHTML string) ([]byte, error) {
  52. path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/work-items/%s/comments/%s/", planeWorkspaceSlug, planeProjectId, workItemID, commentID)
  53. payload := map[string]interface{}{"comment_html": commentHTML}
  54. resp, err := planeHttpPatch(path, payload)
  55. if err != nil {
  56. zap.L().Error("[Plane] UpdateWorkItemComment 请求失败", zap.Error(err))
  57. return nil, err
  58. }
  59. if !isSuccess(resp.StatusCode) {
  60. zap.L().Error("[Plane] UpdateWorkItemComment 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body)))
  61. return nil, fmt.Errorf("UpdateWorkItemComment 失败: %s", resp.Status)
  62. }
  63. return resp.Body, nil
  64. }
  65. // DeleteWorkItemComment 删除评论
  66. func DeleteWorkItemComment(workItemID, commentID string) error {
  67. path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/work-items/%s/comments/%s/", planeWorkspaceSlug, planeProjectId, workItemID, commentID)
  68. resp, err := planeHttpDelete(path)
  69. if err != nil {
  70. zap.L().Error("[Plane] DeleteWorkItemComment 请求失败", zap.Error(err))
  71. return err
  72. }
  73. if resp.StatusCode != 204 {
  74. zap.L().Error("[Plane] DeleteWorkItemComment 返回错误", zap.String("status", resp.Status))
  75. return fmt.Errorf("DeleteWorkItemComment 失败: %s", resp.Status)
  76. }
  77. return nil
  78. }