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

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


The following commit(s) were added to refs/heads/release-v0.18 by this push:
     new eb1248677 fix(zentao): update zentao project's progres field's type, 
make it more cpmpatible with zentao 18.1 (#6073)
eb1248677 is described below

commit eb1248677baaac35b1e22e0c96b94846e4579f9a
Author: Lynwee <[email protected]>
AuthorDate: Wed Sep 13 15:02:16 2023 +0800

    fix(zentao): update zentao project's progres field's type, make it more 
cpmpatible with zentao 18.1 (#6073)
---
 backend/plugins/zentao/api/init.go       | 21 ++++++---------------
 backend/plugins/zentao/api/remote.go     |  2 ++
 backend/plugins/zentao/models/project.go | 28 +++++++++++++++++++++-------
 3 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/backend/plugins/zentao/api/init.go 
b/backend/plugins/zentao/api/init.go
index 2e7abfd49..ea1839d03 100644
--- a/backend/plugins/zentao/api/init.go
+++ b/backend/plugins/zentao/api/init.go
@@ -19,6 +19,7 @@ package api
 
 import (
        "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/log"
        "github.com/apache/incubator-devlake/core/plugin"
        "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
        "github.com/apache/incubator-devlake/plugins/zentao/models"
@@ -30,6 +31,7 @@ type MixScopes struct {
        ZentaoProject *models.ZentaoProject `json:"project"`
 }
 
+var logger log.Logger
 var vld *validator.Validate
 var connectionHelper *api.ConnectionApiHelper
 var projectScopeHelper *api.ScopeApiHelper[models.ZentaoConnection, 
models.ZentaoProject, models.ZentaoScopeConfig]
@@ -41,12 +43,9 @@ var scHelper *api.ScopeConfigHelper[models.ZentaoScopeConfig]
 func Init(br context.BasicRes, p plugin.PluginMeta) {
 
        basicRes = br
+       logger = basicRes.GetLogger()
        vld = validator.New()
-       connectionHelper = api.NewConnectionHelper(
-               basicRes,
-               vld,
-               p.Name(),
-       )
+       connectionHelper = api.NewConnectionHelper(basicRes, vld, p.Name())
 
        projectParams := &api.ReflectionParameters{
                ScopeIdFieldName:  "Id",
@@ -63,14 +62,6 @@ func Init(br context.BasicRes, p plugin.PluginMeta) {
                nil,
        )
 
-       projectRemoteHelper = api.NewRemoteHelper[models.ZentaoConnection, 
models.ZentaoProject, models.ZentaoProject, api.BaseRemoteGroupResponse](
-               basicRes,
-               vld,
-               connectionHelper,
-       )
-       scHelper = api.NewScopeConfigHelper[models.ZentaoScopeConfig](
-               basicRes,
-               vld,
-               p.Name(),
-       )
+       projectRemoteHelper = api.NewRemoteHelper[models.ZentaoConnection, 
models.ZentaoProject, models.ZentaoProject, 
api.BaseRemoteGroupResponse](basicRes, vld, connectionHelper)
+       scHelper = api.NewScopeConfigHelper[models.ZentaoScopeConfig](basicRes, 
vld, p.Name())
 }
diff --git a/backend/plugins/zentao/api/remote.go 
b/backend/plugins/zentao/api/remote.go
index 8e613004d..46965821f 100644
--- a/backend/plugins/zentao/api/remote.go
+++ b/backend/plugins/zentao/api/remote.go
@@ -90,12 +90,14 @@ func RemoteScopes(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, er
                                // list projects part
                                res, err := apiClient.Get("/projects", query, 
nil)
                                if err != nil {
+                                       logger.Error(err, "call projects api")
                                        return nil, err
                                }
 
                                resBody := &ProjectResponse{}
                                err = api.UnmarshalResponse(res, resBody)
                                if err != nil {
+                                       logger.Error(err, "unmarshal projects 
response")
                                        return nil, err
                                }
 
diff --git a/backend/plugins/zentao/models/project.go 
b/backend/plugins/zentao/models/project.go
index 241fbf494..7ab66b527 100644
--- a/backend/plugins/zentao/models/project.go
+++ b/backend/plugins/zentao/models/project.go
@@ -19,6 +19,7 @@ package models
 
 import (
        "fmt"
+       "github.com/spf13/cast"
        "strconv"
 
        "github.com/apache/incubator-devlake/core/models/common"
@@ -89,12 +90,13 @@ type ZentaoProject struct {
        TeamCount      int    `json:"teamCount" mapstructure:"teamCount"`
        LeftTasks      string `json:"leftTasks" mapstructure:"leftTasks"`
        //TeamMembers   []interface{} `json:"teamMembers" gorm:"-"`
-       TotalEstimate float64 `json:"totalEstimate" 
mapstructure:"totalEstimate"`
-       TotalConsumed float64 `json:"totalConsumed" 
mapstructure:"totalConsumed"`
-       TotalLeft     float64 `json:"totalLeft" mapstructure:"totalLeft"`
-       Progress      float64 `json:"progress" mapstructure:"progress"`
-       ScopeConfigId uint64  `json:"scopeConfigId,omitempty" 
mapstructure:"scopeConfigId"`
+       TotalEstimate float64     `json:"totalEstimate" 
mapstructure:"totalEstimate"`
+       TotalConsumed float64     `json:"totalConsumed" 
mapstructure:"totalConsumed"`
+       TotalLeft     float64     `json:"totalLeft" mapstructure:"totalLeft"`
+       Progress      interface{} `json:"progress" mapstructure:"progress"`
+       ScopeConfigId uint64      `json:"scopeConfigId,omitempty" 
mapstructure:"scopeConfigId"`
 }
+
 type PM struct {
        PmId       int64  `json:"id" mapstructure:"id"`
        PmAccount  string `json:"account" mapstructure:"account"`
@@ -115,7 +117,11 @@ type Hours struct {
        HoursTotalReal     float64 `json:"totalReal" mapstructure:"totalReal"`
 }
 
-func (p *ZentaoProject) ConvertFix() {
+func (p *ZentaoProject) fixProgressField() {
+       p.Progress = cast.ToFloat64(p.Progress)
+}
+
+func (p *ZentaoProject) fixClosedByResField() {
        switch cb := p.ClosedByRes.(type) {
        case string:
                p.ClosedBy = cb
@@ -127,7 +133,9 @@ func (p *ZentaoProject) ConvertFix() {
                }
        }
        p.ClosedByRes = p.ClosedBy
+}
 
+func (p *ZentaoProject) fixCanceledByResField() {
        switch cb := p.CanceledByRes.(type) {
        case string:
                p.CanceledBy = cb
@@ -141,7 +149,13 @@ func (p *ZentaoProject) ConvertFix() {
        p.CanceledByRes = p.CanceledBy
 }
 
-func (ZentaoProject) TableName() string {
+func (p *ZentaoProject) ConvertFix() {
+       p.fixProgressField()
+       p.fixClosedByResField()
+       p.fixCanceledByResField()
+}
+
+func (p ZentaoProject) TableName() string {
        return "_tool_zentao_projects"
 }
 

Reply via email to