| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package plane_v1
- import (
- "fmt"
- "go.uber.org/zap"
- )
- // ==================== State API ====================
- // ListStates 列出状态
- func ListStates() ([]byte, error) {
- path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/states/", planeWorkspaceSlug, planeProjectId)
- resp, err := planeHttpGet(path)
- if err != nil {
- zap.L().Error("[Plane] ListStates 请求失败", zap.Error(err))
- return nil, err
- }
- if !isSuccess(resp.StatusCode) {
- zap.L().Error("[Plane] ListStates 返回错误", zap.String("status", resp.Status))
- return nil, fmt.Errorf("ListStates 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // CreateState 创建状态
- // group: backlog / unstarted / started / completed / cancelled
- func CreateState(name, color, group string) ([]byte, error) {
- path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/states/", planeWorkspaceSlug, planeProjectId)
- payload := map[string]interface{}{
- "name": name,
- "color": color,
- "group": group,
- }
- resp, err := planeHttpPost(path, payload)
- if err != nil {
- zap.L().Error("[Plane] CreateState 请求失败", zap.Error(err))
- return nil, err
- }
- if resp.StatusCode != 201 {
- zap.L().Error("[Plane] CreateState 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body)))
- return nil, fmt.Errorf("CreateState 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // GetState 获取状态详情
- func GetState(stateID string) ([]byte, error) {
- path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/states/%s/", planeWorkspaceSlug, planeProjectId, stateID)
- resp, err := planeHttpGet(path)
- if err != nil {
- zap.L().Error("[Plane] GetState 请求失败", zap.Error(err))
- return nil, err
- }
- if !isSuccess(resp.StatusCode) {
- zap.L().Error("[Plane] GetState 返回错误", zap.String("status", resp.Status))
- return nil, fmt.Errorf("GetState 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // UpdateState 更新状态
- func UpdateState(stateID string, data map[string]interface{}) ([]byte, error) {
- path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/states/%s/", planeWorkspaceSlug, planeProjectId, stateID)
- resp, err := planeHttpPatch(path, data)
- if err != nil {
- zap.L().Error("[Plane] UpdateState 请求失败", zap.Error(err))
- return nil, err
- }
- if !isSuccess(resp.StatusCode) {
- zap.L().Error("[Plane] UpdateState 返回错误", zap.String("status", resp.Status), zap.String("body", string(resp.Body)))
- return nil, fmt.Errorf("UpdateState 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // DeleteState 删除状态
- func DeleteState(stateID string) error {
- path := fmt.Sprintf("/api/v1/workspaces/%s/projects/%s/states/%s/", planeWorkspaceSlug, planeProjectId, stateID)
- resp, err := planeHttpDelete(path)
- if err != nil {
- zap.L().Error("[Plane] DeleteState 请求失败", zap.Error(err))
- return err
- }
- if resp.StatusCode != 204 {
- zap.L().Error("[Plane] DeleteState 返回错误", zap.String("status", resp.Status))
- return fmt.Errorf("DeleteState 失败: %s", resp.Status)
- }
- return nil
- }
|