| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- package plane_v1
- import (
- "fmt"
- "go.uber.org/zap"
- )
- // ==================== Work Item Link API ====================
- // ListWorkItemLinks 列出工作项链接
- func ListWorkItemLinks(workItemID string) ([]byte, error) {
- path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/work-items/%s/links/", planeWorkspaceSlug, planeProjectId, workItemID)
- resp, err := planeHttpGet(path)
- if err != nil {
- zap.L().Error("[Plane] ListWorkItemLinks 请求失败", zap.Error(err))
- return nil, err
- }
- if !isSuccess(resp.StatusCode) {
- zap.L().Error("[Plane] ListWorkItemLinks 返回错误", zap.String("status", resp.Status))
- return nil, fmt.Errorf("ListWorkItemLinks 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // CreateWorkItemLink 创建工作项链接
- func CreateWorkItemLink(workItemID, linkURL, title string) ([]byte, error) {
- path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/work-items/%s/links/", planeWorkspaceSlug, planeProjectId, workItemID)
- payload := map[string]interface{}{"url": linkURL, "title": title}
- resp, err := planeHttpPost(path, payload)
- if err != nil {
- zap.L().Error("[Plane] CreateWorkItemLink 请求失败", zap.Error(err))
- return nil, err
- }
- if resp.StatusCode != 201 {
- zap.L().Error("[Plane] CreateWorkItemLink 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body)))
- return nil, fmt.Errorf("CreateWorkItemLink 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // GetWorkItemLink 获取链接详情
- func GetWorkItemLink(workItemID, linkID string) ([]byte, error) {
- path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/work-items/%s/links/%s/", planeWorkspaceSlug, planeProjectId, workItemID, linkID)
- resp, err := planeHttpGet(path)
- if err != nil {
- zap.L().Error("[Plane] GetWorkItemLink 请求失败", zap.Error(err))
- return nil, err
- }
- if !isSuccess(resp.StatusCode) {
- zap.L().Error("[Plane] GetWorkItemLink 返回错误", zap.String("status", resp.Status))
- return nil, fmt.Errorf("GetWorkItemLink 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // UpdateWorkItemLink 更新链接
- func UpdateWorkItemLink(workItemID, linkID string, data map[string]interface{}) ([]byte, error) {
- path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/work-items/%s/links/%s/", planeWorkspaceSlug, planeProjectId, workItemID, linkID)
- resp, err := planeHttpPatch(path, data)
- if err != nil {
- zap.L().Error("[Plane] UpdateWorkItemLink 请求失败", zap.Error(err))
- return nil, err
- }
- if !isSuccess(resp.StatusCode) {
- zap.L().Error("[Plane] UpdateWorkItemLink 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body)))
- return nil, fmt.Errorf("UpdateWorkItemLink 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // DeleteWorkItemLink 删除链接
- func DeleteWorkItemLink(workItemID, linkID string) error {
- path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/work-items/%s/links/%s/", planeWorkspaceSlug, planeProjectId, workItemID, linkID)
- resp, err := planeHttpDelete(path)
- if err != nil {
- zap.L().Error("[Plane] DeleteWorkItemLink 请求失败", zap.Error(err))
- return err
- }
- if resp.StatusCode != 204 {
- zap.L().Error("[Plane] DeleteWorkItemLink 返回错误", zap.String("status", resp.Status))
- return fmt.Errorf("DeleteWorkItemLink 失败: %s", resp.Status)
- }
- return nil
- }
|