| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- 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
- }
|