klesh commented on code in PR #5257:
URL: 
https://github.com/apache/incubator-devlake/pull/5257#discussion_r1205423284


##########
backend/plugins/zentao/tasks/changelog_dbget.go:
##########
@@ -0,0 +1,122 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package tasks
+
+import (
+       "fmt"
+       "reflect"
+
+       "github.com/apache/incubator-devlake/core/dal"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+       "github.com/apache/incubator-devlake/plugins/zentao/models"
+)
+
+var _ plugin.SubTaskEntryPoint = DBGetActionHistory
+
+func DBGetActionHistory(taskCtx plugin.SubTaskContext) errors.Error {
+       data := taskCtx.GetData().(*ZentaoTaskData)
+
+       // skip if no RemoteDb
+       if data.RemoteDb == nil {
+               return nil
+       }
+
+       divider := api.NewBatchSaveDivider(taskCtx, 500, "", "")
+       defer func() {
+               err1 := divider.Close()
+               if err1 != nil {
+                       panic(err1)
+               }
+       }()
+
+       return dBGetActionHistory(data, func(zcc *models.ZentaoChangelogCom) 
errors.Error {
+               batch, err := divider.ForType(reflect.TypeOf(zcc.Changelog))
+               if err != nil {
+                       return err
+               }
+               zcc.Changelog.ConnectionId = data.Options.ConnectionId
+               zcc.Changelog.Product = int(data.Options.ProductId)
+               err = batch.Add(zcc.Changelog)
+               if err != nil {
+                       return err
+               }
+               if zcc.ChangelogDetail.Id != 0 {
+                       batch, err = 
divider.ForType(reflect.TypeOf(zcc.ChangelogDetail))
+                       if err != nil {
+                               return err
+                       }
+                       zcc.ChangelogDetail.ConnectionId = 
data.Options.ConnectionId
+                       err = batch.Add(zcc.ChangelogDetail)
+                       if err != nil {
+                               return err
+                       }
+               }
+               return nil
+       })
+}
+
+var DBGetChangelogMeta = plugin.SubTaskMeta{
+       Name:             "DBGetChangelog",
+       EntryPoint:       DBGetActionHistory,
+       EnabledByDefault: true,
+       Description:      "get action and history data to be changelog from 
Zentao databases",
+       DomainTypes:      []string{plugin.DOMAIN_TYPE_TICKET},
+}
+
+// it is work for zentao version 18.3
+func dBGetActionHistory(data *ZentaoTaskData, callback 
func(*models.ZentaoChangelogCom) errors.Error) errors.Error {

Review Comment:
   Why creating a function which used once?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to