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

warren pushed a commit to branch release-v0.14
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/release-v0.14 by this push:
     new 5ab05dd38 fix(zentao): fix GetTotalPages (#3799)
5ab05dd38 is described below

commit 5ab05dd383f59448df109c214e153e0a01e0887b
Author: Warren Chen <[email protected]>
AuthorDate: Wed Nov 23 21:20:35 2022 +0800

    fix(zentao): fix GetTotalPages (#3799)
---
 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 +--
 6 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/plugins/zentao/tasks/api_client.go 
b/plugins/zentao/tasks/api_client.go
index aff7b4d69..07cac6406 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 8f6d2c6ae..6092b7995 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 cc1e9d8cb..68956cc9c 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 6d737a0b5..6b895b8a2 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 39fc86318..8c6099178 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 8094870cf..89b0aad96 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) {

Reply via email to