package plane_v1 import ( "fmt" "go.uber.org/zap" ) // ==================== Label API ==================== // ListLabels 列出标签 func ListLabels() ([]byte, error) { path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/labels/", planeWorkspaceSlug, planeProjectId) resp, err := planeHttpGet(path) if err != nil { zap.L().Error("[Plane] ListLabels 请求失败", zap.Error(err)) return nil, err } if !isSuccess(resp.StatusCode) { zap.L().Error("[Plane] ListLabels 返回错误", zap.String("status", resp.Status)) return nil, fmt.Errorf("ListLabels 失败: %s", resp.Status) } return resp.Body, nil } // CreateLabel 创建标签 func CreateLabel(name, color string) ([]byte, error) { path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/labels/", planeWorkspaceSlug, planeProjectId) payload := map[string]interface{}{"name": name, "color": color} resp, err := planeHttpPost(path, payload) if err != nil { zap.L().Error("[Plane] CreateLabel 请求失败", zap.Error(err)) return nil, err } if resp.StatusCode != 201 { zap.L().Error("[Plane] CreateLabel 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body))) return nil, fmt.Errorf("CreateLabel 失败: %s", resp.Status) } return resp.Body, nil } // GetLabel 获取标签详情 func GetLabel(labelID string) ([]byte, error) { path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/labels/%s/", planeWorkspaceSlug, planeProjectId, labelID) resp, err := planeHttpGet(path) if err != nil { zap.L().Error("[Plane] GetLabel 请求失败", zap.Error(err)) return nil, err } if !isSuccess(resp.StatusCode) { zap.L().Error("[Plane] GetLabel 返回错误", zap.String("status", resp.Status)) return nil, fmt.Errorf("GetLabel 失败: %s", resp.Status) } return resp.Body, nil } // UpdateLabel 更新标签 func UpdateLabel(labelID string, data map[string]interface{}) ([]byte, error) { path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/labels/%s/", planeWorkspaceSlug, planeProjectId, labelID) resp, err := planeHttpPatch(path, data) if err != nil { zap.L().Error("[Plane] UpdateLabel 请求失败", zap.Error(err)) return nil, err } if !isSuccess(resp.StatusCode) { zap.L().Error("[Plane] UpdateLabel 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body))) return nil, fmt.Errorf("UpdateLabel 失败: %s", resp.Status) } return resp.Body, nil } // DeleteLabel 删除标签 func DeleteLabel(labelID string) error { path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/labels/%s/", planeWorkspaceSlug, planeProjectId, labelID) resp, err := planeHttpDelete(path) if err != nil { zap.L().Error("[Plane] DeleteLabel 请求失败", zap.Error(err)) return err } if resp.StatusCode != 204 { zap.L().Error("[Plane] DeleteLabel 返回错误", zap.String("status", resp.Status)) return fmt.Errorf("DeleteLabel 失败: %s", resp.Status) } return nil }