From 5aca590316e12f4ce1828b35c20b1c50b0cbd868 Mon Sep 17 00:00:00 2001 From: ysicing Date: Fri, 20 Sep 2024 15:34:16 +0800 Subject: [PATCH] * [execution] imp execution api --- README.md | 14 ++-- example/executions/main.go | 66 ++++++++++++++++ zentao/executions.go | 153 ++++++++++++++++++++----------------- zentao/types.go | 9 +++ 4 files changed, 163 insertions(+), 79 deletions(-) create mode 100644 example/executions/main.go diff --git a/README.md b/README.md index 43a8a57..793049f 100644 --- a/README.md +++ b/README.md @@ -74,13 +74,6 @@ Zentao API client enabling Go programs to interact with Zentao in a simple and u - [x] 获取项目详情 - [x] 修改项目 - [x] 删除项目 -- [x] 版本(Builds) - - [x] 获取项目版本列表 - - [x] 获取执行版本详情 - - [x] 修改版本 - - [x] 创建版本 - - [x] 获取版本详情 - - [x] 删除版本 - [x] 执行(Executions) - [x] 获取项目的执行列表 - [x] 创建执行 @@ -99,6 +92,13 @@ Zentao API client enabling Go programs to interact with Zentao in a simple and u - [x] 创建Bug - [x] 删除Bug - [x] 修改Bug +- [x] 版本(Builds) + - [x] 获取项目版本列表 + - [x] 获取执行版本详情 + - [x] 修改版本 + - [x] 创建版本 + - [x] 获取版本详情 + - [x] 删除版本 - [x] 用例 - [x] 获取产品用例列表 - [x] 获取用例详情 diff --git a/example/executions/main.go b/example/executions/main.go new file mode 100644 index 0000000..ff8174f --- /dev/null +++ b/example/executions/main.go @@ -0,0 +1,66 @@ +// +// Copyright 2022, easysoft +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package main + +import ( + "fmt" + "log" + "time" + + "github.com/easysoft/go-zentao/v20/zentao" +) + +func main() { + zt, err := zentao.NewBasicAuthClient( + "admin", + "jaege1ugh4ooYip7", + zentao.WithBaseURL("http://127.0.0.1"), + zentao.WithDevMode(), + zentao.WithDumpAll(), + zentao.WithoutProxy(), + ) + if err != nil { + panic(err) + } + p1, _, err := zt.Executions.ListByProject(2) + if err != nil { + panic(err) + } + log.Printf("Executions count: %v", len(p1.Executions)) + p2, _, err := zt.Executions.Create(2, zentao.ExecutionsCreateMeta{ + Project: 2, + Name: fmt.Sprintf("gosdk_p4_%s", time.Now().Format("20060102150405")), + Code: fmt.Sprintf("gosdk_p4_%s", time.Now().Format("20060102150405")), + Begin: time.Now().Format("2006-01-02"), + End: time.Now().AddDate(0, 0, 7).Format("2006-01-02"), + // Plans: []int{2}, + Products: []int{1}, + }) + if err != nil { + panic(err) + } + log.Printf("created Execution: %v", p2.ID) + ztExec := zentao.ExecutionsUpdateMeta{} + ztExec.Name = fmt.Sprintf("gosdk_p4_%s", time.Now().Format("20060102150405")) + ztExec.Begin = time.Now().Format("2006-01-02") + ztExec.End = time.Now().AddDate(0, 0, 7).Format("2006-01-02") + p3, _, err := zt.Executions.UpdateByID(2, ztExec) + if err != nil { + panic(err) + } + log.Printf("updated Execution: %v", p3.ID) +} diff --git a/zentao/executions.go b/zentao/executions.go index 93d0d77..8754c29 100644 --- a/zentao/executions.go +++ b/zentao/executions.go @@ -18,8 +18,8 @@ package zentao import ( "fmt" - "time" + "github.com/davecgh/go-spew/spew" "github.com/imroc/req/v3" ) @@ -35,18 +35,19 @@ type ProjectExecutions struct { } type Execution struct { - ID int `json:"id"` - Name string `json:"name"` - Project int `json:"project"` - Code string `json:"code"` - Type string `json:"type"` - Parent int `json:"parent"` - Begin string `json:"begin"` - End string `json:"end"` - Status string `json:"status"` - OpenedBy UserMeta `json:"openedBy"` - OpenedDate time.Time `json:"openedDate"` - Progress int `json:"progress"` + ID int `json:"id"` + Name string `json:"name"` + Project int `json:"project"` + Code string `json:"code"` + Type string `json:"type"` + Parent int `json:"parent"` + Begin string `json:"begin"` + End string `json:"end"` + Status string `json:"status"` + OpenedBy any `json:"openedBy"` + OpenedDate string `json:"openedDate"` + Delay int `json:"delay"` + Progress any `json:"progress"` } type ExecutionsCreateMeta struct { @@ -55,75 +56,82 @@ type ExecutionsCreateMeta struct { Code string `json:"code"` Begin string `json:"begin"` End string `json:"end"` - Days int `json:"days"` - Lifetime string `json:"lifetime,omitempty"` - P0 string `json:"PO,omitempty"` - PM string `json:"PM,omitempty"` - QD string `json:"QD,omitempty"` - RD string `json:"RD,omitempty"` + Plans []int `json:"plans,omitempty"` + Products []int `json:"products,omitempty"` + + Days int `json:"days,omitempty"` + Lifetime ExecutionLifeTime `json:"lifetime,omitempty"` + P0 string `json:"PO,omitempty"` + PM string `json:"PM,omitempty"` + QD string `json:"QD,omitempty"` + RD string `json:"RD,omitempty"` + TeamMembers []string `json:"teamMembers,omitempty"` + Desc string `json:"desc,omitempty"` + Acl ACL `json:"acl,omitempty"` + // Whitelist []string `json:"whitelist,omitempty"` } type ExecutionsCreateMsg struct { - ID int `json:"id"` - Project int `json:"project"` - Model string `json:"model"` - Type string `json:"type"` - Lifetime string `json:"lifetime"` - Budget string `json:"budget"` - Budgetunit string `json:"budgetUnit"` - Attribute string `json:"attribute"` - Percent int `json:"percent"` - Milestone string `json:"milestone"` - Output string `json:"output"` - Auth string `json:"auth"` - Parent int `json:"parent"` - Path string `json:"path"` - Grade int `json:"grade"` - Name string `json:"name"` - Code string `json:"code"` - Begin string `json:"begin"` - End string `json:"end"` - Realbegan string `json:"realBegan"` - Realend string `json:"realEnd"` - Days int `json:"days"` - Status string `json:"status"` - Substatus string `json:"subStatus"` - Pri string `json:"pri"` - Desc string `json:"desc"` - Version int `json:"version"` - Parentversion int `json:"parentVersion"` - Planduration int `json:"planDuration"` - Realduration int `json:"realDuration"` - Openedby UserMeta `json:"openedBy"` - Openeddate time.Time `json:"openedDate"` - Openedversion string `json:"openedVersion"` - Lasteditedby string `json:"lastEditedBy"` - Lastediteddate time.Time `json:"lastEditedDate"` - Closedby string `json:"closedBy"` - Closeddate interface{} `json:"closedDate"` - Canceledby string `json:"canceledBy"` - Canceleddate interface{} `json:"canceledDate"` - Po string `json:"PO"` - Pm string `json:"PM"` - Qd string `json:"QD"` - Rd string `json:"RD"` - Team string `json:"team"` - ACL string `json:"acl"` - Whitelist string `json:"whitelist"` - Order int `json:"order"` - Deleted string `json:"deleted"` - Totalhours int `json:"totalHours"` - Totalestimate int `json:"totalEstimate"` - Totalconsumed int `json:"totalConsumed"` - Totalleft int `json:"totalLeft"` + ID int `json:"id"` + Project int `json:"project"` + Model string `json:"model"` + Type string `json:"type"` + Lifetime ExecutionLifeTime `json:"lifetime"` + Budget string `json:"budget"` + Budgetunit string `json:"budgetUnit"` + Attribute string `json:"attribute"` + Percent int `json:"percent"` + Milestone string `json:"milestone"` + Output string `json:"output"` + Auth string `json:"auth"` + Parent int `json:"parent"` + Path string `json:"path"` + Grade int `json:"grade"` + Name string `json:"name"` + Code string `json:"code"` + Begin string `json:"begin"` + End string `json:"end"` + Realbegan string `json:"realBegan"` + Realend string `json:"realEnd"` + Days int `json:"days"` + Status string `json:"status"` + Substatus string `json:"subStatus"` + Pri string `json:"pri"` + Desc string `json:"desc"` + Version int `json:"version"` + Parentversion int `json:"parentVersion"` + Planduration int `json:"planDuration"` + Realduration int `json:"realDuration"` + Openedby any `json:"openedBy"` + Openeddate string `json:"openedDate"` + Openedversion string `json:"openedVersion"` + Lasteditedby any `json:"lastEditedBy"` + Lastediteddate string `json:"lastEditedDate"` + Closedby any `json:"closedBy"` + Closeddate string `json:"closedDate"` + Canceledby any `json:"canceledBy"` + Canceleddate string `json:"canceledDate"` + Po any `json:"PO"` + Pm any `json:"PM"` + Qd any `json:"QD"` + Rd any `json:"RD"` + Team string `json:"team"` + ACL ACL `json:"acl"` + Whitelist any `json:"whitelist"` + Order int `json:"order"` + Deleted bool `json:"deleted"` + Totalhours int `json:"totalHours"` + Totalestimate int `json:"totalEstimate"` + Totalconsumed int `json:"totalConsumed"` + Totalleft int `json:"totalLeft"` } type ExecutionsUpdateMeta struct { ExecutionsCreateMeta TeamMembers []string `json:"teamMembers,omitempty"` Desc string `json:"desc,omitempty"` - ACL string `json:"acl,omitempty"` + ACL ACL `json:"acl,omitempty"` Whitelist []string `json:"whitelist,omitempty"` } @@ -139,6 +147,7 @@ func (s *ExecutionsService) ListByProject(id int64) (*ProjectExecutions, *req.Re // Create 创建执行 func (s *ExecutionsService) Create(id int, build ExecutionsCreateMeta) (*ExecutionsCreateMsg, *req.Response, error) { var u ExecutionsCreateMsg + spew.Dump(build) resp, err := s.client.client.R(). SetHeader("Token", s.client.token). SetBody(&build). diff --git a/zentao/types.go b/zentao/types.go index 9997ba3..416b527 100644 --- a/zentao/types.go +++ b/zentao/types.go @@ -109,6 +109,15 @@ var ( ProjectReset ProjectAuth = "reset" // 重新定义 ) +type ExecutionLifeTime string // 生命周期 + +var ( + LifeTimeShort ExecutionLifeTime = "short" // 短期 + LifeTimeLong ExecutionLifeTime = "long" // 长期 + LifeTimeOps ExecutionLifeTime = "ops" // 运维 + LifeTimeNull ExecutionLifeTime = "" // 未定义 +) + // CustomResp 通用Resp type CustomResp struct { Message string `json:"message,omitempty"`