| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- package plane_v2
- import (
- "fmt"
- "go.uber.org/zap"
- )
- // ==================== Project API ====================
- // ListProjects 列出项目
- func ListProjects(slug string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/", slug)
- resp, err := planeWebGet(url)
- if err != nil {
- zap.L().Error("[PlaneWeb] ListProjects 请求失败", zap.Error(err))
- return nil, err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] ListProjects 返回错误", zap.String("status", resp.Status))
- return nil, fmt.Errorf("ListProjects 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // CreateProject 创建项目
- func CreateProject(slug string, data map[string]interface{}) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/", slug)
- resp, err := planeWebPost(url, data)
- if err != nil {
- zap.L().Error("[PlaneWeb] CreateProject 请求失败", zap.Error(err))
- return nil, err
- }
- if resp.StatusCode != 201 {
- zap.L().Error("[PlaneWeb] CreateProject 返回错误",
- zap.String("status", resp.Status),
- zap.String("body", string(resp.Body)),
- )
- return nil, fmt.Errorf("CreateProject 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // GetProject 获取项目详情
- func GetProject(slug, projectID string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/", slug, projectID)
- resp, err := planeWebGet(url)
- if err != nil {
- zap.L().Error("[PlaneWeb] GetProject 请求失败", zap.Error(err))
- return nil, err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] GetProject 返回错误", zap.String("status", resp.Status))
- return nil, fmt.Errorf("GetProject 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // UpdateProject 更新项目
- func UpdateProject(slug, projectID string, data map[string]interface{}) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/", slug, projectID)
- resp, err := planeWebPatch(url, data)
- if err != nil {
- zap.L().Error("[PlaneWeb] UpdateProject 请求失败", zap.Error(err))
- return nil, err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] UpdateProject 返回错误",
- zap.String("status", resp.Status),
- zap.String("body", string(resp.Body)),
- )
- return nil, fmt.Errorf("UpdateProject 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // DeleteProject 删除项目
- func DeleteProject(slug, projectID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/", slug, projectID)
- resp, err := planeWebDelete(url)
- if err != nil {
- zap.L().Error("[PlaneWeb] DeleteProject 请求失败", zap.Error(err))
- return err
- }
- if resp.StatusCode != 204 {
- zap.L().Error("[PlaneWeb] DeleteProject 返回错误", zap.String("status", resp.Status))
- return fmt.Errorf("DeleteProject 失败: %s", resp.Status)
- }
- return nil
- }
- // ArchiveProject 归档项目
- func ArchiveProject(slug, projectID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/archive/", slug, projectID)
- resp, err := planeWebPost(url, map[string]interface{}{})
- if err != nil {
- zap.L().Error("[PlaneWeb] ArchiveProject 请求失败", zap.Error(err))
- return err
- }
- if resp.StatusCode != 204 {
- zap.L().Error("[PlaneWeb] ArchiveProject 返回错误", zap.String("status", resp.Status))
- return fmt.Errorf("ArchiveProject 失败: %s", resp.Status)
- }
- return nil
- }
- // UnarchiveProject 取消归档项目
- func UnarchiveProject(slug, projectID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/archive/", slug, projectID)
- resp, err := planeWebDelete(url)
- if err != nil {
- zap.L().Error("[PlaneWeb] UnarchiveProject 请求失败", zap.Error(err))
- return err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] UnarchiveProject 返回错误", zap.String("status", resp.Status))
- return fmt.Errorf("UnarchiveProject 失败: %s", resp.Status)
- }
- return nil
- }
- // ListCurrentProjects 列出当前配置的工作空间下的项目
- func ListCurrentProjects() ([]byte, error) {
- return ListProjects(webWorkspaceSlug)
- }
- // GetCurrentProject 获取当前配置的项目详情
- func GetCurrentProject() ([]byte, error) {
- return GetProject(webWorkspaceSlug, webProjectId)
- }
|