| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package plane_v2_api
- import (
- "fmt"
- plane "fwh-toolbox-server/repositories/api/plane_v2"
- )
- // ListLabels 列出项目标签
- func ListLabels(c *plane.PlaneClient, slug, projectID string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/labels/", slug, projectID)
- resp, err := c.Get(url)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("ListLabels 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // CreateLabel 创建标签
- func CreateLabel(c *plane.PlaneClient, slug, projectID, name, color string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/labels/", slug, projectID)
- payload := map[string]interface{}{
- "name": name,
- "color": color,
- }
- resp, err := c.Post(url, payload)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("CreateLabel 失败: %s, body=%s", resp.Status, string(resp.Body))
- }
- return resp.Body, nil
- }
- // GetLabel 获取标签详情
- func GetLabel(c *plane.PlaneClient, slug, projectID, labelID string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/labels/%s/", slug, projectID, labelID)
- resp, err := c.Get(url)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("GetLabel 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // UpdateLabel 更新标签
- func UpdateLabel(c *plane.PlaneClient, slug, projectID, labelID string, data map[string]interface{}) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/labels/%s/", slug, projectID, labelID)
- resp, err := c.Patch(url, data)
- if err != nil {
- return nil, err
- }
- if !plane.IsSuccess(resp.StatusCode) {
- return nil, fmt.Errorf("UpdateLabel 失败: %s, body=%s", resp.Status, string(resp.Body))
- }
- return resp.Body, nil
- }
- // DeleteLabel 删除标签
- func DeleteLabel(c *plane.PlaneClient, slug, projectID, labelID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/labels/%s/", slug, projectID, labelID)
- resp, err := c.Delete(url)
- if err != nil {
- return err
- }
- if resp.StatusCode != 204 {
- return fmt.Errorf("DeleteLabel 失败: %s", resp.Status)
- }
- return nil
- }
|