| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- package plane_v2_api
- import (
- "fmt"
- plane "fwh-toolbox-server/repositories/api/plane_v2"
- )
- // ListComments 列出工作项评论
- func ListComments(c *plane.PlaneClient, slug, projectID, issueID string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/issues/%s/comments/", slug, projectID, issueID)
- resp, err := c.Get(url)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("ListComments 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // CreateComment 创建评论
- func CreateComment(c *plane.PlaneClient, 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 := c.Post(url, payload)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("CreateComment 失败: %s, body=%s", resp.Status, string(resp.Body))
- }
- return resp.Body, nil
- }
- // GetComment 获取评论详情
- func GetComment(c *plane.PlaneClient, 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 := c.Get(url)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("GetComment 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // UpdateComment 更新评论
- func UpdateComment(c *plane.PlaneClient, 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 := c.Patch(url, payload)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("UpdateComment 失败: %s, body=%s", resp.Status, string(resp.Body))
- }
- return resp.Body, nil
- }
- // DeleteComment 删除评论
- func DeleteComment(c *plane.PlaneClient, slug, projectID, issueID, commentID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/issues/%s/comments/%s/", slug, projectID, issueID, commentID)
- resp, err := c.Delete(url)
- if err != nil {
- return err
- }
- if resp.StatusCode != 204 {
- return fmt.Errorf("DeleteComment 失败: %s", resp.Status)
- }
- return nil
- }
|