diff --git a/README.md b/README.md index 89ab952..43a8a57 100644 --- a/README.md +++ b/README.md @@ -63,10 +63,11 @@ Zentao API client enabling Go programs to interact with Zentao in a simple and u - [x] 激活需求 - [x] 关闭需求 - [x] 指派需求 - - [ ] 预估工时 + - [ ] 获取工时(开源版不支持) + - [ ] 预估工时(开源版不支持) - [ ] 子需求 - - [ ] 撤回评审 - - [ ] 评审需求 + - [x] 撤回评审 + - [x] 评审需求 - [x] 项目(Projects) - [x] 创建项目 - [x] 获取项目列表 diff --git a/example/stories/main.go b/example/stories/main.go index 0f933e6..21b41b7 100644 --- a/example/stories/main.go +++ b/example/stories/main.go @@ -104,4 +104,32 @@ func main() { panic(err) } log.Printf("assign story id: %v", p9.ID) + // p10, _, err := zt.Stories.GetEstimateByID(p9.ID) + // if err != nil { + // panic(err) + // } + // log.Printf("assign story id: %v", p10.ID) + // p10, _, err := zt.Stories.UpdateEstimateByID(p9.ID, zentao.StoriesEstimate{}) + // if err != nil { + // panic(err) + // } + // log.Printf("assign story id: %v", p10.ID) + _, _, err = zt.Stories.RecallByID(p9.ID) + if err != nil { + panic(err) + } + log.Printf("recall story id: %v", p9.ID) + p11, _, err := zt.Stories.ReviewByID(p9.ID, zentao.StoriesReview{ + Result: zentao.ReviewResultPass, + Estimate: 1.1, + Comment: "test review", + }) + if err != nil { + panic(err) + } + log.Printf("review story id: %v", p11.ID) + _, _, err = zt.Stories.DeleteByID(p9.ID) + if err != nil { + panic(err) + } } diff --git a/zentao/stories.go b/zentao/stories.go index 4002f33..fb93b10 100644 --- a/zentao/stories.go +++ b/zentao/stories.go @@ -123,6 +123,18 @@ type StoriesActive struct { Comment string `json:"comment,omitempty"` } +type StoriesEstimate struct { +} + +type StoriesReview struct { + ReviewedDate string `json:"reviewedDate,omitempty"` + Result StoriesReviewResult `json:"result,omitempty"` + ClosedReason StoriesCloseReason `json:"closedReason,omitempty"` + Pri int `json:"pri,omitempty"` + Estimate float64 `json:"estimate"` + Comment string `json:"comment,omitempty"` +} + // ProjectsList 获取项目需求列表 func (s *StoriesService) ProjectsList(id int) (*StoriesListMeta, *req.Response, error) { var u StoriesListMeta @@ -239,8 +251,18 @@ func (s *StoriesService) AssignByID(id int, story StoriesActive) (*StoriesMsg, * return &u, resp, err } -// EstimateByID 预估工时 -func (s *StoriesService) EstimateByID(id int, story StoriesMeta) (*StoriesMsg, *req.Response, error) { +// GetEstimateByID 获取工时, 开源版不支持 +func (s *StoriesService) GetEstimateByID(id int) (*StoriesMsg, *req.Response, error) { + var u StoriesMsg + resp, err := s.client.client.R(). + SetHeader("Token", s.client.token). + SetSuccessResult(&u). + Get(s.client.RequestURL(fmt.Sprintf("/stories/%d/estimate", id))) + return &u, resp, err +} + +// UpdateEstimateByID 更新工时 +func (s *StoriesService) UpdateEstimateByID(id int, story StoriesEstimate) (*StoriesMsg, *req.Response, error) { var u StoriesMsg resp, err := s.client.client.R(). SetHeader("Token", s.client.token). @@ -262,19 +284,22 @@ func (s *StoriesService) ChildByID(id int, story StoriesMeta) (*StoriesMsg, *req } // RecallByID 撤回评审 -func (s *StoriesService) RecallByID(id int, story StoriesMeta) (*StoriesMsg, *req.Response, error) { +func (s *StoriesService) RecallByID(id int) (*StoriesMsg, *req.Response, error) { var u StoriesMsg resp, err := s.client.client.R(). SetHeader("Token", s.client.token). - SetBody(&story). SetSuccessResult(&u). - Post(s.client.RequestURL(fmt.Sprintf("/stories/%d/recall", id))) + Delete(s.client.RequestURL(fmt.Sprintf("/stories/%d/recall", id))) return &u, resp, err } // ReviewByID 审核需求 -func (s *StoriesService) ReviewByID(id int, story StoriesMeta) (*StoriesMsg, *req.Response, error) { +func (s *StoriesService) ReviewByID(id int, story StoriesReview) (*StoriesMsg, *req.Response, error) { var u StoriesMsg + story.ClosedReason = CloseReasonDone + if story.Estimate <= 0 { + story.Estimate = 1.0 + } resp, err := s.client.client.R(). SetHeader("Token", s.client.token). SetBody(&story). diff --git a/zentao/types.go b/zentao/types.go index a85b9dd..a129662 100644 --- a/zentao/types.go +++ b/zentao/types.go @@ -94,6 +94,14 @@ var ( CloseReasonBydesign StoriesCloseReason = "bydesign" // 设计如此 ) +type StoriesReviewResult string // 需求评审结果 + +var ( + ReviewResultPass StoriesReviewResult = "pass" // 通过 + ReviewResultRevert StoriesReviewResult = "revert" // 退回 撤销变更 + ReviewResultClarify StoriesReviewResult = "clarify" // 有待明确 +) + // CustomResp 通用Resp type CustomResp struct { Message string `json:"message,omitempty"`