Skip to content

Commit eb12486

Browse files
authored
fix(zentao): update zentao project's progres field's type, make it more cpmpatible with zentao 18.1 (#6073)
1 parent 47451b7 commit eb12486

3 files changed

Lines changed: 29 additions & 22 deletions

File tree

backend/plugins/zentao/api/init.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package api
1919

2020
import (
2121
"github.com/apache/incubator-devlake/core/context"
22+
"github.com/apache/incubator-devlake/core/log"
2223
"github.com/apache/incubator-devlake/core/plugin"
2324
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
2425
"github.com/apache/incubator-devlake/plugins/zentao/models"
@@ -30,6 +31,7 @@ type MixScopes struct {
3031
ZentaoProject *models.ZentaoProject `json:"project"`
3132
}
3233

34+
var logger log.Logger
3335
var vld *validator.Validate
3436
var connectionHelper *api.ConnectionApiHelper
3537
var projectScopeHelper *api.ScopeApiHelper[models.ZentaoConnection, models.ZentaoProject, models.ZentaoScopeConfig]
@@ -41,12 +43,9 @@ var scHelper *api.ScopeConfigHelper[models.ZentaoScopeConfig]
4143
func Init(br context.BasicRes, p plugin.PluginMeta) {
4244

4345
basicRes = br
46+
logger = basicRes.GetLogger()
4447
vld = validator.New()
45-
connectionHelper = api.NewConnectionHelper(
46-
basicRes,
47-
vld,
48-
p.Name(),
49-
)
48+
connectionHelper = api.NewConnectionHelper(basicRes, vld, p.Name())
5049

5150
projectParams := &api.ReflectionParameters{
5251
ScopeIdFieldName: "Id",
@@ -63,14 +62,6 @@ func Init(br context.BasicRes, p plugin.PluginMeta) {
6362
nil,
6463
)
6564

66-
projectRemoteHelper = api.NewRemoteHelper[models.ZentaoConnection, models.ZentaoProject, models.ZentaoProject, api.BaseRemoteGroupResponse](
67-
basicRes,
68-
vld,
69-
connectionHelper,
70-
)
71-
scHelper = api.NewScopeConfigHelper[models.ZentaoScopeConfig](
72-
basicRes,
73-
vld,
74-
p.Name(),
75-
)
65+
projectRemoteHelper = api.NewRemoteHelper[models.ZentaoConnection, models.ZentaoProject, models.ZentaoProject, api.BaseRemoteGroupResponse](basicRes, vld, connectionHelper)
66+
scHelper = api.NewScopeConfigHelper[models.ZentaoScopeConfig](basicRes, vld, p.Name())
7667
}

backend/plugins/zentao/api/remote.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ func RemoteScopes(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, er
9090
// list projects part
9191
res, err := apiClient.Get("/projects", query, nil)
9292
if err != nil {
93+
logger.Error(err, "call projects api")
9394
return nil, err
9495
}
9596

9697
resBody := &ProjectResponse{}
9798
err = api.UnmarshalResponse(res, resBody)
9899
if err != nil {
100+
logger.Error(err, "unmarshal projects response")
99101
return nil, err
100102
}
101103

backend/plugins/zentao/models/project.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package models
1919

2020
import (
2121
"fmt"
22+
"github.com/spf13/cast"
2223
"strconv"
2324

2425
"github.com/apache/incubator-devlake/core/models/common"
@@ -89,12 +90,13 @@ type ZentaoProject struct {
8990
TeamCount int `json:"teamCount" mapstructure:"teamCount"`
9091
LeftTasks string `json:"leftTasks" mapstructure:"leftTasks"`
9192
//TeamMembers []interface{} `json:"teamMembers" gorm:"-"`
92-
TotalEstimate float64 `json:"totalEstimate" mapstructure:"totalEstimate"`
93-
TotalConsumed float64 `json:"totalConsumed" mapstructure:"totalConsumed"`
94-
TotalLeft float64 `json:"totalLeft" mapstructure:"totalLeft"`
95-
Progress float64 `json:"progress" mapstructure:"progress"`
96-
ScopeConfigId uint64 `json:"scopeConfigId,omitempty" mapstructure:"scopeConfigId"`
93+
TotalEstimate float64 `json:"totalEstimate" mapstructure:"totalEstimate"`
94+
TotalConsumed float64 `json:"totalConsumed" mapstructure:"totalConsumed"`
95+
TotalLeft float64 `json:"totalLeft" mapstructure:"totalLeft"`
96+
Progress interface{} `json:"progress" mapstructure:"progress"`
97+
ScopeConfigId uint64 `json:"scopeConfigId,omitempty" mapstructure:"scopeConfigId"`
9798
}
99+
98100
type PM struct {
99101
PmId int64 `json:"id" mapstructure:"id"`
100102
PmAccount string `json:"account" mapstructure:"account"`
@@ -115,7 +117,11 @@ type Hours struct {
115117
HoursTotalReal float64 `json:"totalReal" mapstructure:"totalReal"`
116118
}
117119

118-
func (p *ZentaoProject) ConvertFix() {
120+
func (p *ZentaoProject) fixProgressField() {
121+
p.Progress = cast.ToFloat64(p.Progress)
122+
}
123+
124+
func (p *ZentaoProject) fixClosedByResField() {
119125
switch cb := p.ClosedByRes.(type) {
120126
case string:
121127
p.ClosedBy = cb
@@ -127,7 +133,9 @@ func (p *ZentaoProject) ConvertFix() {
127133
}
128134
}
129135
p.ClosedByRes = p.ClosedBy
136+
}
130137

138+
func (p *ZentaoProject) fixCanceledByResField() {
131139
switch cb := p.CanceledByRes.(type) {
132140
case string:
133141
p.CanceledBy = cb
@@ -141,7 +149,13 @@ func (p *ZentaoProject) ConvertFix() {
141149
p.CanceledByRes = p.CanceledBy
142150
}
143151

144-
func (ZentaoProject) TableName() string {
152+
func (p *ZentaoProject) ConvertFix() {
153+
p.fixProgressField()
154+
p.fixClosedByResField()
155+
p.fixCanceledByResField()
156+
}
157+
158+
func (p ZentaoProject) TableName() string {
145159
return "_tool_zentao_projects"
146160
}
147161

0 commit comments

Comments
 (0)