plane_link.go 3.3 KB

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