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