This is an automated email from the ASF dual-hosted git repository.

likyh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 70969a5b fix(zentao): fix GetTotalPages (#3798)
70969a5b is described below

commit 70969a5ba9abecb528a3ae95d185529fa368f555
Author: Warren Chen <[email protected]>
AuthorDate: Fri Dec 2 13:05:54 2022 +0800

    fix(zentao): fix GetTotalPages (#3798)
    
    * fix(zentao): fix GetTotalPages
    
    * fix(zentao): delete executionid from zentaoTask
---
 plugins/zentao/e2e/snapshot_tables/_tool_zentao_tasks.csv | 8 ++++----
 plugins/zentao/models/archived/task.go                    | 1 -
 plugins/zentao/models/task.go                             | 1 -
 plugins/zentao/tasks/api_client.go                        | 3 ++-
 plugins/zentao/tasks/execution_collector.go               | 3 ---
 plugins/zentao/tasks/product_collector.go                 | 2 --
 plugins/zentao/tasks/project_collector.go                 | 3 ---
 plugins/zentao/tasks/shared.go                            | 7 +++++--
 plugins/zentao/tasks/task_collector.go                    | 3 +--
 plugins/zentao/tasks/task_extractor.go                    | 1 -
 10 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/plugins/zentao/e2e/snapshot_tables/_tool_zentao_tasks.csv 
b/plugins/zentao/e2e/snapshot_tables/_tool_zentao_tasks.csv
index 50c89887..5680ee34 100644
--- a/plugins/zentao/e2e/snapshot_tables/_tool_zentao_tasks.csv
+++ b/plugins/zentao/e2e/snapshot_tables/_tool_zentao_tasks.csv
@@ -1,4 +1,4 @@
-connection_id,id,execution_id,project,parent,execution,module,design,story,story_version,design_version,from_bug,feedback,from_issue,name,type,mode,pri,estimate,consumed,deadline,status,sub_status,color,description,version,opened_by_id,opened_by_name,opened_date,assigned_to_id,assigned_to_name,assigned_date,est_started,real_started,finished_id,finished_date,finished_list,canceled_id,canceled_date,closed_by_id,closed_date,plan_duration,real_duration,closed_reason,last_edited_id,last_edite
 [...]
-1,1,1,13,0,1,0,0,0,1,0,0,0,0,任务名称,devel,,3,0,0,2022-10-01,wait,,,任务描述<span> 
</span><br /><div><br 
/></div>,1,1,devlake,2022-09-19T01:50:37.000+00:00,5,开发乙,2022-09-19T01:50:37.000+00:00,2022-09-20,,0,,,0,,0,,0,0,,0,,,0,0,0,,,,,0,rnd,0,,0,0,,开发乙,3,0,21.11
-1,2,1,13,0,1,0,0,0,1,0,0,0,0,任务名称,devel,,3,12.1,2.1,2022-10-01,wait,,,任务描述<span>
 </span><br /><div><br 
/></div>,1,1,devlake,2022-09-19T01:50:37.000+00:00,5,开发乙,2022-09-19T01:50:37.000+00:00,2022-09-20,,0,,,0,,0,,0,0,,0,,,0,0,0,,,,,0,rnd,0,,0,0,,开发乙,3,0,3
-1,3,1,13,-1,1,0,0,0,1,0,0,0,0,任务名称,devel,,3,11.2,0,2022-10-01,wait,,,任务描述<span>
 </span><br /><div><br 
/></div>,1,1,devlake,2022-09-19T01:50:37.000+00:00,5,开发乙,2022-09-19T01:50:37.000+00:00,2022-09-20,,0,,,0,,0,,0,0,,0,,,0,0,0,,,,,0,rnd,0,,0,0,,开发乙,3,0,43.22121
+connection_id,id,project,parent,execution,module,design,story,story_version,design_version,from_bug,feedback,from_issue,name,type,mode,pri,estimate,consumed,deadline,status,sub_status,color,description,version,opened_by_id,opened_by_name,opened_date,assigned_to_id,assigned_to_name,assigned_date,est_started,real_started,finished_id,finished_date,finished_list,canceled_id,canceled_date,closed_by_id,closed_date,plan_duration,real_duration,closed_reason,last_edited_id,last_edited_date,activa
 [...]
+1,1,13,0,1,0,0,0,1,0,0,0,0,任务名称,devel,,3,0,0,2022-10-01,wait,,,任务描述<span> 
</span><br /><div><br 
/></div>,1,1,devlake,2022-09-19T01:50:37.000+00:00,5,开发乙,2022-09-19T01:50:37.000+00:00,2022-09-20,,0,,,0,,0,,0,0,,0,,,0,0,0,,,,,0,rnd,0,,0,0,,开发乙,3,0,21.11
+1,2,13,0,1,0,0,0,1,0,0,0,0,任务名称,devel,,3,12.1,2.1,2022-10-01,wait,,,任务描述<span> 
</span><br /><div><br 
/></div>,1,1,devlake,2022-09-19T01:50:37.000+00:00,5,开发乙,2022-09-19T01:50:37.000+00:00,2022-09-20,,0,,,0,,0,,0,0,,0,,,0,0,0,,,,,0,rnd,0,,0,0,,开发乙,3,0,3
+1,3,13,-1,1,0,0,0,1,0,0,0,0,任务名称,devel,,3,11.2,0,2022-10-01,wait,,,任务描述<span> 
</span><br /><div><br 
/></div>,1,1,devlake,2022-09-19T01:50:37.000+00:00,5,开发乙,2022-09-19T01:50:37.000+00:00,2022-09-20,,0,,,0,,0,,0,0,,0,,,0,0,0,,,,,0,rnd,0,,0,0,,开发乙,3,0,43.22121
diff --git a/plugins/zentao/models/archived/task.go 
b/plugins/zentao/models/archived/task.go
index 62c9db05..6423bf03 100644
--- a/plugins/zentao/models/archived/task.go
+++ b/plugins/zentao/models/archived/task.go
@@ -25,7 +25,6 @@ import (
 type ZentaoTask struct {
        archived.NoPKModel
        ConnectionId  uint64  `gorm:"primaryKey;type:BIGINT  NOT NULL"`
-       ExecutionId   int64   `json:"execution_id"`
        ID            int64   `json:"id" gorm:"primaryKey;type:BIGINT  NOT 
NULL"`
        Project       int64   `json:"project"`
        Parent        int64   `json:"parent"`
diff --git a/plugins/zentao/models/task.go b/plugins/zentao/models/task.go
index 47501a23..bcb21def 100644
--- a/plugins/zentao/models/task.go
+++ b/plugins/zentao/models/task.go
@@ -94,7 +94,6 @@ type ZentaoTaskRes struct {
 type ZentaoTask struct {
        common.NoPKModel
        ConnectionId  uint64  `gorm:"primaryKey;type:BIGINT  NOT NULL"`
-       ExecutionId   int64   `json:"execution_id"`
        ID            int64   `json:"id" gorm:"primaryKey;type:BIGINT  NOT 
NULL"`
        Project       int64   `json:"project"`
        Parent        int64   `json:"parent"`
diff --git a/plugins/zentao/tasks/api_client.go 
b/plugins/zentao/tasks/api_client.go
index aff7b4d6..07cac640 100644
--- a/plugins/zentao/tasks/api_client.go
+++ b/plugins/zentao/tasks/api_client.go
@@ -91,5 +91,6 @@ func NewZentaoApiClient(taskCtx core.TaskContext, connection 
*models.ZentaoConne
 }
 
 type ZentaoPagination struct {
-       Page int `json:"page"`
+       Total int `json:"total"`
+       Limit int `json:"limit"`
 }
diff --git a/plugins/zentao/tasks/execution_collector.go 
b/plugins/zentao/tasks/execution_collector.go
index 8f6d2c6a..6092b799 100644
--- a/plugins/zentao/tasks/execution_collector.go
+++ b/plugins/zentao/tasks/execution_collector.go
@@ -46,8 +46,6 @@ func CollectExecution(taskCtx core.SubTaskContext) 
errors.Error {
                        Table: RAW_EXECUTION_TABLE,
                },
                ApiClient: data.ApiClient,
-
-               PageSize: 100,
                // TODO write which api would you want request
                UrlTemplate: "executions/{{ .Params.ExecutionId }}",
                Query: func(reqData *helper.RequestData) (url.Values, 
errors.Error) {
@@ -56,7 +54,6 @@ func CollectExecution(taskCtx core.SubTaskContext) 
errors.Error {
                        query.Set("limit", fmt.Sprintf("%v", 
reqData.Pager.Size))
                        return query, nil
                },
-               GetTotalPages: GetTotalPagesFromResponse,
                ResponseParser: func(res *http.Response) ([]json.RawMessage, 
errors.Error) {
                        body, err := io.ReadAll(res.Body)
                        if err != nil {
diff --git a/plugins/zentao/tasks/product_collector.go 
b/plugins/zentao/tasks/product_collector.go
index cc1e9d8c..68956cc9 100644
--- a/plugins/zentao/tasks/product_collector.go
+++ b/plugins/zentao/tasks/product_collector.go
@@ -46,7 +46,6 @@ func CollectProduct(taskCtx core.SubTaskContext) errors.Error 
{
                        Table: RAW_PRODUCT_TABLE,
                },
                ApiClient: data.ApiClient,
-               PageSize:  100,
                // TODO write which api would you want request
                UrlTemplate: "products/{{ .Params.ProductId }}",
                Query: func(reqData *helper.RequestData) (url.Values, 
errors.Error) {
@@ -55,7 +54,6 @@ func CollectProduct(taskCtx core.SubTaskContext) errors.Error 
{
                        query.Set("limit", fmt.Sprintf("%v", 
reqData.Pager.Size))
                        return query, nil
                },
-               GetTotalPages: GetTotalPagesFromResponse,
                ResponseParser: func(res *http.Response) ([]json.RawMessage, 
errors.Error) {
                        body, err := io.ReadAll(res.Body)
                        if err != nil {
diff --git a/plugins/zentao/tasks/project_collector.go 
b/plugins/zentao/tasks/project_collector.go
index 6d737a0b..6b895b8a 100644
--- a/plugins/zentao/tasks/project_collector.go
+++ b/plugins/zentao/tasks/project_collector.go
@@ -45,8 +45,6 @@ func CollectProject(taskCtx core.SubTaskContext) errors.Error 
{
                        Table: RAW_PROJECT_TABLE,
                },
                ApiClient: data.ApiClient,
-
-               PageSize: 100,
                // TODO write which api would you want request
                UrlTemplate: "projects",
                Query: func(reqData *helper.RequestData) (url.Values, 
errors.Error) {
@@ -55,7 +53,6 @@ func CollectProject(taskCtx core.SubTaskContext) errors.Error 
{
                        query.Set("limit", fmt.Sprintf("%v", 
reqData.Pager.Size))
                        return query, nil
                },
-               GetTotalPages: GetTotalPagesFromResponse,
                ResponseParser: func(res *http.Response) ([]json.RawMessage, 
errors.Error) {
                        var data struct {
                                Projects []json.RawMessage `json:"projects"`
diff --git a/plugins/zentao/tasks/shared.go b/plugins/zentao/tasks/shared.go
index 39fc8631..8c609917 100644
--- a/plugins/zentao/tasks/shared.go
+++ b/plugins/zentao/tasks/shared.go
@@ -31,8 +31,11 @@ func GetTotalPagesFromResponse(res *http.Response, args 
*helper.ApiCollectorArgs
        if err != nil {
                return 0, err
        }
-       return body.Page, nil
-
+       pages := body.Total / args.PageSize
+       if body.Total%args.PageSize > 0 {
+               pages++
+       }
+       return pages, nil
 }
 
 func getAccountId(account *models.ZentaoAccount) int64 {
diff --git a/plugins/zentao/tasks/task_collector.go 
b/plugins/zentao/tasks/task_collector.go
index 8094870c..89b0aad9 100644
--- a/plugins/zentao/tasks/task_collector.go
+++ b/plugins/zentao/tasks/task_collector.go
@@ -45,8 +45,7 @@ func CollectTask(taskCtx core.SubTaskContext) errors.Error {
                        Table: RAW_TASK_TABLE,
                },
                ApiClient: data.ApiClient,
-
-               PageSize: 100,
+               PageSize:  100,
                // TODO write which api would you want request
                UrlTemplate: "/executions/{{ .Params.ExecutionId }}/tasks",
                Query: func(reqData *helper.RequestData) (url.Values, 
errors.Error) {
diff --git a/plugins/zentao/tasks/task_extractor.go 
b/plugins/zentao/tasks/task_extractor.go
index df131895..649fbadd 100644
--- a/plugins/zentao/tasks/task_extractor.go
+++ b/plugins/zentao/tasks/task_extractor.go
@@ -56,7 +56,6 @@ func ExtractTask(taskCtx core.SubTaskContext) errors.Error {
                        }
                        task := &models.ZentaoTask{
                                ConnectionId:       data.Options.ConnectionId,
-                               ExecutionId:        data.Options.ExecutionId,
                                ID:                 res.Id,
                                Project:            res.Project,
                                Parent:             res.Parent,

Reply via email to