plane_comment.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package plane_v2
  2. import (
  3. "fmt"
  4. "go.uber.org/zap"
  5. )
  6. // ==================== Comment API ====================
  7. // ListComments 列出工作项评论
  8. func ListComments(slug, projectID, issueID string) ([]byte, error) {
  9. url := fmt.Sprintf("/api/workspaces/%s/projects/%s/issues/%s/comments/", slug, projectID, issueID)
  10. resp, err := planeWebGet(url)
  11. if err != nil {
  12. zap.L().Error("[PlaneWeb] ListComments 请求失败", zap.Error(err))
  13. return nil, err
  14. }
  15. if !isWebSuccess(resp.StatusCode) {
  16. zap.L().Error("[PlaneWeb] ListComments 返回错误", zap.String("status", resp.Status))
  17. return nil, fmt.Errorf("ListComments 失败: %s", resp.Status)
  18. }
  19. return resp.Body, nil
  20. }
  21. // CreateComment 创建评论
  22. func CreateComment(slug, projectID, issueID, commentHTML string) ([]byte, error) {
  23. url := fmt.Sprintf("/api/workspaces/%s/projects/%s/issues/%s/comments/", slug, projectID, issueID)
  24. payload := map[string]interface{}{
  25. "comment_html": commentHTML,
  26. }
  27. resp, err := planeWebPost(url, payload)
  28. if err != nil {
  29. zap.L().Error("[PlaneWeb] CreateComment 请求失败", zap.Error(err))
  30. return nil, err
  31. }
  32. if resp.StatusCode != 201 {
  33. zap.L().Error("[PlaneWeb] CreateComment 返回错误",
  34. zap.String("status", resp.Status),
  35. zap.String("body", string(resp.Body)),
  36. )
  37. return nil, fmt.Errorf("CreateComment 失败: %s", resp.Status)
  38. }
  39. return resp.Body, nil
  40. }
  41. // GetComment 获取评论详情
  42. func GetComment(slug, projectID, issueID, commentID string) ([]byte, error) {
  43. url := fmt.Sprintf("/api/workspaces/%s/projects/%s/issues/%s/comments/%s/", slug, projectID, issueID, commentID)
  44. resp, err := planeWebGet(url)
  45. if err != nil {
  46. zap.L().Error("[PlaneWeb] GetComment 请求失败", zap.Error(err))
  47. return nil, err
  48. }
  49. if !isWebSuccess(resp.StatusCode) {
  50. zap.L().Error("[PlaneWeb] GetComment 返回错误", zap.String("status", resp.Status))
  51. return nil, fmt.Errorf("GetComment 失败: %s", resp.Status)
  52. }
  53. return resp.Body, nil
  54. }
  55. // UpdateComment 更新评论
  56. func UpdateComment(slug, projectID, issueID, commentID, commentHTML string) ([]byte, error) {
  57. url := fmt.Sprintf("/api/workspaces/%s/projects/%s/issues/%s/comments/%s/", slug, projectID, issueID, commentID)
  58. payload := map[string]interface{}{
  59. "comment_html": commentHTML,
  60. }
  61. resp, err := planeWebPatch(url, payload)
  62. if err != nil {
  63. zap.L().Error("[PlaneWeb] UpdateComment 请求失败", zap.Error(err))
  64. return nil, err
  65. }
  66. if !isWebSuccess(resp.StatusCode) {
  67. zap.L().Error("[PlaneWeb] UpdateComment 返回错误",
  68. zap.String("status", resp.Status),
  69. zap.String("body", string(resp.Body)),
  70. )
  71. return nil, fmt.Errorf("UpdateComment 失败: %s", resp.Status)
  72. }
  73. return resp.Body, nil
  74. }
  75. // DeleteComment 删除评论
  76. func DeleteComment(slug, projectID, issueID, commentID string) error {
  77. url := fmt.Sprintf("/api/workspaces/%s/projects/%s/issues/%s/comments/%s/", slug, projectID, issueID, commentID)
  78. resp, err := planeWebDelete(url)
  79. if err != nil {
  80. zap.L().Error("[PlaneWeb] DeleteComment 请求失败", zap.Error(err))
  81. return err
  82. }
  83. if resp.StatusCode != 204 {
  84. zap.L().Error("[PlaneWeb] DeleteComment 返回错误", zap.String("status", resp.Status))
  85. return fmt.Errorf("DeleteComment 失败: %s", resp.Status)
  86. }
  87. return nil
  88. }