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

zhangliang2022 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 98fc6e9c feat(tapd): add story_bug relation (#2176)
98fc6e9c is described below

commit 98fc6e9cbcf643bc8cc0a6b038926f102cf02d9a
Author: Warren Chen <[email protected]>
AuthorDate: Mon Jun 13 15:12:41 2022 +0800

    feat(tapd): add story_bug relation (#2176)
    
    closes #2175
---
 .../models/migrationscripts/archived/story_bug.go  | 34 ++++++++++
 .../migrationscripts/update_schemas20220531.go     | 35 -----------
 .../migrationscripts/update_schemas20220613.go     | 45 +++++++++++++
 plugins/tapd/models/story_bug.go                   | 34 ++++++++++
 plugins/tapd/tapd.go                               |  8 ++-
 plugins/tapd/tasks/bug_changelog_collector.go      | 10 +--
 plugins/tapd/tasks/bug_collector.go                | 10 +--
 plugins/tapd/tasks/shared.go                       |  8 +++
 .../{bug_collector.go => story_bug_collector.go}   | 73 +++++++++-------------
 plugins/tapd/tasks/story_bug_extractor.go          | 65 +++++++++++++++++++
 plugins/tapd/tasks/story_changelog_collector.go    | 10 +--
 plugins/tapd/tasks/story_collector.go              | 10 +--
 plugins/tapd/tasks/task_changelog_collector.go     | 10 +--
 plugins/tapd/tasks/task_collector.go               | 10 +--
 plugins/tapd/tasks/worklog_collector.go            | 10 +--
 15 files changed, 228 insertions(+), 144 deletions(-)

diff --git a/plugins/tapd/models/migrationscripts/archived/story_bug.go 
b/plugins/tapd/models/migrationscripts/archived/story_bug.go
new file mode 100644
index 00000000..b46781b5
--- /dev/null
+++ b/plugins/tapd/models/migrationscripts/archived/story_bug.go
@@ -0,0 +1,34 @@
+/*
+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 archived
+
+import (
+       "github.com/apache/incubator-devlake/models/common"
+)
+
+type TapdStoryBug struct {
+       ConnectionId uint64 `gorm:"primaryKey"`
+       WorkspaceID  uint64 `gorm:"primaryKey" json:"workspace_id,string"`
+       StoryId      uint64 `gorm:"primaryKey" json:"story_id,string"`
+       BugId        uint64 `gorm:"primaryKey" json:"bug_id,string"`
+       common.NoPKModel
+}
+
+func (TapdStoryBug) TableName() string {
+       return "_tool_tapd_story_bugs"
+}
diff --git a/plugins/tapd/models/migrationscripts/update_schemas20220531.go 
b/plugins/tapd/models/migrationscripts/update_schemas20220531.go
index 0eb4f3a3..144dafc5 100644
--- a/plugins/tapd/models/migrationscripts/update_schemas20220531.go
+++ b/plugins/tapd/models/migrationscripts/update_schemas20220531.go
@@ -26,41 +26,6 @@ import (
 type UpdateSchemas20220531 struct{}
 
 func (*UpdateSchemas20220531) Up(ctx context.Context, db *gorm.DB) error {
-       //err := db.Migrator().DropTable(
-       //      &archived.TapdWorkspace{},
-       //      &archived.TapdWorklog{},
-       //      &archived.TapdWorkspaceIteration{},
-       //      &archived.TapdUser{},
-       //      &archived.TapdBugChangelog{},
-       //      &archived.TapdBugChangelogItem{},
-       //      &archived.TapdStoryChangelog{},
-       //      &archived.TapdStoryChangelogItem{},
-       //      &archived.TapdTaskChangelog{},
-       //      &archived.TapdTaskChangelogItem{},
-       //      &archived.TapdIssue{},
-       //      &archived.TapdIteration{},
-       //      &archived.TapdConnection{},
-       //      &archived.TapdBug{},
-       //      &archived.TapdStory{},
-       //      &archived.TapdTask{},
-       //      &archived.TapdTaskLabel{},
-       //      &archived.TapdBugLabel{},
-       //      &archived.TapdStoryLabel{},
-       //      &archived.TapdBugStatus{},
-       //      &archived.TapdStoryStatus{},
-       //      &archived.TapdBugCommit{},
-       //      &archived.TapdStoryCommit{},
-       //      &archived.TapdTaskCommit{},
-       //      &archived.TapdWorkSpaceBug{},
-       //      &archived.TapdWorkSpaceStory{},
-       //      &archived.TapdWorkSpaceTask{},
-       //      &archived.TapdIterationBug{},
-       //      &archived.TapdIterationStory{},
-       //      &archived.TapdIterationTask{},
-       //)
-       //if err != nil {
-       //      return err
-       //}
        err := db.Migrator().AutoMigrate(
                &archived.TapdWorkspace{},
                &archived.TapdWorklog{},
diff --git a/plugins/tapd/models/migrationscripts/update_schemas20220613.go 
b/plugins/tapd/models/migrationscripts/update_schemas20220613.go
new file mode 100644
index 00000000..c583c750
--- /dev/null
+++ b/plugins/tapd/models/migrationscripts/update_schemas20220613.go
@@ -0,0 +1,45 @@
+/*
+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 migrationscripts
+
+import (
+       "context"
+       
"github.com/apache/incubator-devlake/plugins/tapd/models/migrationscripts/archived"
+       "gorm.io/gorm"
+)
+
+type UpdateSchemas20220613 struct{}
+
+func (*UpdateSchemas20220613) Up(ctx context.Context, db *gorm.DB) error {
+       err := db.Migrator().AutoMigrate(
+               &archived.TapdStoryBug{},
+       )
+       return err
+}
+
+func (*UpdateSchemas20220613) Version() uint64 {
+       return 20220613132510
+}
+
+func (*UpdateSchemas20220613) Name() string {
+       return "add story bug"
+}
+
+func (*UpdateSchemas20220613) Owner() string {
+       return "tapd"
+}
diff --git a/plugins/tapd/models/story_bug.go b/plugins/tapd/models/story_bug.go
new file mode 100644
index 00000000..15f023ce
--- /dev/null
+++ b/plugins/tapd/models/story_bug.go
@@ -0,0 +1,34 @@
+/*
+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 models
+
+import (
+       "github.com/apache/incubator-devlake/models/common"
+)
+
+type TapdStoryBug struct {
+       ConnectionId uint64 `gorm:"primaryKey"`
+       WorkspaceID  uint64 `gorm:"primaryKey" json:"workspace_id,string"`
+       StoryId      uint64 `gorm:"primaryKey" json:"story_id,string"`
+       BugId        uint64 `gorm:"primaryKey" json:"bug_id,string"`
+       common.NoPKModel
+}
+
+func (TapdStoryBug) TableName() string {
+       return "_tool_tapd_story_bugs"
+}
diff --git a/plugins/tapd/tapd.go b/plugins/tapd/tapd.go
index 7f81e092..aa029332 100644
--- a/plugins/tapd/tapd.go
+++ b/plugins/tapd/tapd.go
@@ -97,6 +97,8 @@ func (plugin Tapd) SubTaskMetas() []core.SubTaskMeta {
                tasks.ExtractStoryCommitMeta,
                tasks.CollectTaskCommitMeta,
                tasks.ExtractTaskCommitMeta,
+               tasks.CollectStoryBugMeta,
+               tasks.ExtractStoryBugsMeta,
                tasks.ConvertWorkspaceMeta,
                tasks.ConvertUserMeta,
                tasks.ConvertIterationMeta,
@@ -163,7 +165,9 @@ func (plugin Tapd) RootPkgPath() string {
 }
 
 func (plugin Tapd) MigrationScripts() []migration.Script {
-       return []migration.Script{new(migrationscripts.InitSchemas)}
+       return []migration.Script{new(migrationscripts.InitSchemas),
+               new(migrationscripts.UpdateSchemas20220531),
+               new(migrationscripts.UpdateSchemas20220613)}
 }
 
 func (plugin Tapd) ApiResources() 
map[string]map[string]core.ApiResourceHandler {
@@ -217,7 +221,7 @@ func main() {
                        panic(err)
                }
                wsList := make([]*models.TapdWorkspace, 0)
-               err = db.First(&wsList, "parent_id = ?", 59169984).Error 
//nolint TODO: fix the unused err
+               err = db.Find(&wsList, "parent_id = ?", 59169984).Error 
//nolint TODO: fix the unused err
                if err != nil {
                        panic(err)
                }
diff --git a/plugins/tapd/tasks/bug_changelog_collector.go 
b/plugins/tapd/tasks/bug_changelog_collector.go
index 6c04011d..0af6454c 100644
--- a/plugins/tapd/tasks/bug_changelog_collector.go
+++ b/plugins/tapd/tasks/bug_changelog_collector.go
@@ -18,12 +18,10 @@ limitations under the License.
 package tasks
 
 import (
-       "encoding/json"
        "fmt"
        "github.com/apache/incubator-devlake/plugins/core"
        "github.com/apache/incubator-devlake/plugins/helper"
        "github.com/apache/incubator-devlake/plugins/tapd/models"
-       "net/http"
        "net/url"
        "time"
 )
@@ -77,13 +75,7 @@ func CollectBugChangelogs(taskCtx core.SubTaskContext) error 
{
                        }
                        return query, nil
                },
-               ResponseParser: func(res *http.Response) ([]json.RawMessage, 
error) {
-                       var data struct {
-                               Stories []json.RawMessage `json:"data"`
-                       }
-                       err := helper.UnmarshalResponse(res, &data)
-                       return data.Stories, err
-               },
+               ResponseParser: GetRawMessageArrayFromResponse,
        })
        if err != nil {
                logger.Error("collect story changelog error:", err)
diff --git a/plugins/tapd/tasks/bug_collector.go 
b/plugins/tapd/tasks/bug_collector.go
index 6f3cda30..b6fcfc56 100644
--- a/plugins/tapd/tasks/bug_collector.go
+++ b/plugins/tapd/tasks/bug_collector.go
@@ -18,12 +18,10 @@ limitations under the License.
 package tasks
 
 import (
-       "encoding/json"
        "fmt"
        "github.com/apache/incubator-devlake/plugins/core"
        "github.com/apache/incubator-devlake/plugins/helper"
        "github.com/apache/incubator-devlake/plugins/tapd/models"
-       "net/http"
        "net/url"
        "time"
 )
@@ -79,13 +77,7 @@ func CollectBugs(taskCtx core.SubTaskContext) error {
                        }
                        return query, nil
                },
-               ResponseParser: func(res *http.Response) ([]json.RawMessage, 
error) {
-                       var data struct {
-                               Stories []json.RawMessage `json:"data"`
-                       }
-                       err := helper.UnmarshalResponse(res, &data)
-                       return data.Stories, err
-               },
+               ResponseParser: GetRawMessageArrayFromResponse,
        })
        if err != nil {
                logger.Error("collect bug error:", err)
diff --git a/plugins/tapd/tasks/shared.go b/plugins/tapd/tasks/shared.go
index 2621ce40..bf90825e 100644
--- a/plugins/tapd/tasks/shared.go
+++ b/plugins/tapd/tasks/shared.go
@@ -90,3 +90,11 @@ func GetRawMessageDirectFromResponse(res *http.Response) 
([]json.RawMessage, err
        }
        return []json.RawMessage{body}, nil
 }
+
+func GetRawMessageArrayFromResponse(res *http.Response) ([]json.RawMessage, 
error) {
+       var data struct {
+               Data []json.RawMessage `json:"data"`
+       }
+       err := helper.UnmarshalResponse(res, &data)
+       return data.Data, err
+}
diff --git a/plugins/tapd/tasks/bug_collector.go 
b/plugins/tapd/tasks/story_bug_collector.go
similarity index 51%
copy from plugins/tapd/tasks/bug_collector.go
copy to plugins/tapd/tasks/story_bug_collector.go
index 6f3cda30..79322cf3 100644
--- a/plugins/tapd/tasks/bug_collector.go
+++ b/plugins/tapd/tasks/story_bug_collector.go
@@ -18,41 +18,38 @@ limitations under the License.
 package tasks
 
 import (
-       "encoding/json"
        "fmt"
        "github.com/apache/incubator-devlake/plugins/core"
+       "github.com/apache/incubator-devlake/plugins/core/dal"
        "github.com/apache/incubator-devlake/plugins/helper"
        "github.com/apache/incubator-devlake/plugins/tapd/models"
-       "net/http"
        "net/url"
-       "time"
+       "reflect"
 )
 
-const RAW_BUG_TABLE = "tapd_api_bugs"
+const RAW_STORY_BUG_TABLE = "tapd_api_story_bugs"
 
-var _ core.SubTaskEntryPoint = CollectBugs
+var _ core.SubTaskEntryPoint = CollectStoryBugs
 
-func CollectBugs(taskCtx core.SubTaskContext) error {
+func CollectStoryBugs(taskCtx core.SubTaskContext) error {
        data := taskCtx.GetData().(*TapdTaskData)
-       db := taskCtx.GetDb()
+       db := taskCtx.GetDal()
        logger := taskCtx.GetLogger()
-       logger.Info("collect bugs")
+       logger.Info("collect storyBugs")
 
-       since := data.Since
-       incremental := false
-       if since == nil {
-               // user didn't specify a time range to sync, try load from 
database
-               var latestUpdated models.TapdBug
-               err := db.Where("connection_id = ? and workspace_id = ?", 
data.Connection.ID, data.Options.WorkspaceID).Order("modified 
DESC").Limit(1).Find(&latestUpdated).Error
-               if err != nil {
-                       return fmt.Errorf("failed to get latest tapd changelog 
record: %w", err)
-               }
-               if latestUpdated.ID > 0 {
-                       since = (*time.Time)(&latestUpdated.Modified)
-                       incremental = true
-               }
+       clauses := []dal.Clause{
+               dal.From(&models.TapdStory{}),
+               dal.Where("connection_id = ? and workspace_id = ?", 
data.Options.ConnectionId, data.Options.WorkspaceID),
        }
 
+       cursor, err := db.Cursor(clauses...)
+       if err != nil {
+               return err
+       }
+       iterator, err := helper.NewDalCursorIterator(db, cursor, 
reflect.TypeOf(SimpleStory{}))
+       if err != nil {
+               return err
+       }
        collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
                RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
                        Ctx: taskCtx,
@@ -61,42 +58,30 @@ func CollectBugs(taskCtx core.SubTaskContext) error {
                                //CompanyId: data.Options.CompanyId,
                                WorkspaceID: data.Options.WorkspaceID,
                        },
-                       Table: RAW_BUG_TABLE,
+                       Table: RAW_STORY_BUG_TABLE,
                },
-               Incremental: incremental,
                ApiClient:   data.ApiClient,
-               PageSize:    100,
-               UrlTemplate: "bugs",
+               Input:       iterator,
+               UrlTemplate: "stories/get_related_bugs",
                Query: func(reqData *helper.RequestData) (url.Values, error) {
+                       input := reqData.Input.(*SimpleStory)
                        query := url.Values{}
                        query.Set("workspace_id", fmt.Sprintf("%v", 
data.Options.WorkspaceID))
-                       query.Set("page", fmt.Sprintf("%v", reqData.Pager.Page))
-                       query.Set("limit", fmt.Sprintf("%v", 
reqData.Pager.Size))
-                       query.Set("fields", "labels")
-                       query.Set("order", "created asc")
-                       if since != nil {
-                               query.Set("modified", fmt.Sprintf(">%v", 
since.Format("YYYY-MM-DD")))
-                       }
+                       query.Set("story_id", fmt.Sprintf("%v", input.Id))
                        return query, nil
                },
-               ResponseParser: func(res *http.Response) ([]json.RawMessage, 
error) {
-                       var data struct {
-                               Stories []json.RawMessage `json:"data"`
-                       }
-                       err := helper.UnmarshalResponse(res, &data)
-                       return data.Stories, err
-               },
+               ResponseParser: GetRawMessageArrayFromResponse,
        })
        if err != nil {
-               logger.Error("collect bug error:", err)
+               logger.Error("collect storyBug error:", err)
                return err
        }
        return collector.Execute()
 }
 
-var CollectBugMeta = core.SubTaskMeta{
-       Name:        "collectBugs",
-       EntryPoint:  CollectBugs,
+var CollectStoryBugMeta = core.SubTaskMeta{
+       Name:        "collectStoryBugs",
+       EntryPoint:  CollectStoryBugs,
        Required:    true,
-       Description: "collect Tapd bugs",
+       Description: "collect Tapd storyBugs",
 }
diff --git a/plugins/tapd/tasks/story_bug_extractor.go 
b/plugins/tapd/tasks/story_bug_extractor.go
new file mode 100644
index 00000000..c0ae213c
--- /dev/null
+++ b/plugins/tapd/tasks/story_bug_extractor.go
@@ -0,0 +1,65 @@
+/*
+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 (
+       "encoding/json"
+       "github.com/apache/incubator-devlake/plugins/core"
+       "github.com/apache/incubator-devlake/plugins/helper"
+       "github.com/apache/incubator-devlake/plugins/tapd/models"
+)
+
+var _ core.SubTaskEntryPoint = ExtractStoryBugs
+
+var ExtractStoryBugsMeta = core.SubTaskMeta{
+       Name:             "extractStoryBugs",
+       EntryPoint:       ExtractStoryBugs,
+       EnabledByDefault: true,
+       Description:      "Extract raw company data into tool layer table 
_tool_tapd_story_bugs",
+}
+
+func ExtractStoryBugs(taskCtx core.SubTaskContext) error {
+       data := taskCtx.GetData().(*TapdTaskData)
+       extractor, err := helper.NewApiExtractor(helper.ApiExtractorArgs{
+               RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+                       Ctx: taskCtx,
+                       Params: TapdApiParams{
+                               ConnectionId: data.Connection.ID,
+                               WorkspaceID:  data.Options.WorkspaceID,
+                       },
+                       Table: RAW_STORY_BUG_TABLE,
+               },
+               Extract: func(row *helper.RawData) ([]interface{}, error) {
+                       toolL := models.TapdStoryBug{}
+                       err := json.Unmarshal(row.Data, &toolL)
+                       if err != nil {
+                               return nil, err
+                       }
+                       toolL.ConnectionId = data.Connection.ID
+                       return []interface{}{
+                               &toolL,
+                       }, nil
+               },
+       })
+
+       if err != nil {
+               return err
+       }
+
+       return extractor.Execute()
+}
diff --git a/plugins/tapd/tasks/story_changelog_collector.go 
b/plugins/tapd/tasks/story_changelog_collector.go
index 4bc2b991..9ef44ef1 100644
--- a/plugins/tapd/tasks/story_changelog_collector.go
+++ b/plugins/tapd/tasks/story_changelog_collector.go
@@ -18,12 +18,10 @@ limitations under the License.
 package tasks
 
 import (
-       "encoding/json"
        "fmt"
        "github.com/apache/incubator-devlake/plugins/core"
        "github.com/apache/incubator-devlake/plugins/helper"
        "github.com/apache/incubator-devlake/plugins/tapd/models"
-       "net/http"
        "net/url"
        "time"
 )
@@ -77,13 +75,7 @@ func CollectStoryChangelogs(taskCtx core.SubTaskContext) 
error {
                        }
                        return query, nil
                },
-               ResponseParser: func(res *http.Response) ([]json.RawMessage, 
error) {
-                       var data struct {
-                               Stories []json.RawMessage `json:"data"`
-                       }
-                       err := helper.UnmarshalResponse(res, &data)
-                       return data.Stories, err
-               },
+               ResponseParser: GetRawMessageArrayFromResponse,
        })
        if err != nil {
                logger.Error("collect story changelog error:", err)
diff --git a/plugins/tapd/tasks/story_collector.go 
b/plugins/tapd/tasks/story_collector.go
index 6ada37a8..8511fd80 100644
--- a/plugins/tapd/tasks/story_collector.go
+++ b/plugins/tapd/tasks/story_collector.go
@@ -18,12 +18,10 @@ limitations under the License.
 package tasks
 
 import (
-       "encoding/json"
        "fmt"
        "github.com/apache/incubator-devlake/plugins/core"
        "github.com/apache/incubator-devlake/plugins/helper"
        "github.com/apache/incubator-devlake/plugins/tapd/models"
-       "net/http"
        "net/url"
        "time"
 )
@@ -77,13 +75,7 @@ func CollectStorys(taskCtx core.SubTaskContext) error {
                        }
                        return query, nil
                },
-               ResponseParser: func(res *http.Response) ([]json.RawMessage, 
error) {
-                       var data struct {
-                               Stories []json.RawMessage `json:"data"`
-                       }
-                       err := helper.UnmarshalResponse(res, &data)
-                       return data.Stories, err
-               },
+               ResponseParser: GetRawMessageArrayFromResponse,
        })
        if err != nil {
                logger.Error("collect story error:", err)
diff --git a/plugins/tapd/tasks/task_changelog_collector.go 
b/plugins/tapd/tasks/task_changelog_collector.go
index 87c8165d..0846f655 100644
--- a/plugins/tapd/tasks/task_changelog_collector.go
+++ b/plugins/tapd/tasks/task_changelog_collector.go
@@ -18,12 +18,10 @@ limitations under the License.
 package tasks
 
 import (
-       "encoding/json"
        "fmt"
        "github.com/apache/incubator-devlake/plugins/core"
        "github.com/apache/incubator-devlake/plugins/helper"
        "github.com/apache/incubator-devlake/plugins/tapd/models"
-       "net/http"
        "net/url"
        "time"
 )
@@ -77,13 +75,7 @@ func CollectTaskChangelogs(taskCtx core.SubTaskContext) 
error {
                        }
                        return query, nil
                },
-               ResponseParser: func(res *http.Response) ([]json.RawMessage, 
error) {
-                       var data struct {
-                               Stories []json.RawMessage `json:"data"`
-                       }
-                       err := helper.UnmarshalResponse(res, &data)
-                       return data.Stories, err
-               },
+               ResponseParser: GetRawMessageArrayFromResponse,
        })
        if err != nil {
                logger.Error("collect task changelog error:", err)
diff --git a/plugins/tapd/tasks/task_collector.go 
b/plugins/tapd/tasks/task_collector.go
index a69498b6..3beab585 100644
--- a/plugins/tapd/tasks/task_collector.go
+++ b/plugins/tapd/tasks/task_collector.go
@@ -18,12 +18,10 @@ limitations under the License.
 package tasks
 
 import (
-       "encoding/json"
        "fmt"
        "github.com/apache/incubator-devlake/plugins/core"
        "github.com/apache/incubator-devlake/plugins/helper"
        "github.com/apache/incubator-devlake/plugins/tapd/models"
-       "net/http"
        "net/url"
        "time"
 )
@@ -80,13 +78,7 @@ func CollectTasks(taskCtx core.SubTaskContext) error {
                        }
                        return query, nil
                },
-               ResponseParser: func(res *http.Response) ([]json.RawMessage, 
error) {
-                       var data struct {
-                               Stories []json.RawMessage `json:"data"`
-                       }
-                       err := helper.UnmarshalResponse(res, &data)
-                       return data.Stories, err
-               },
+               ResponseParser: GetRawMessageArrayFromResponse,
        })
        if err != nil {
                logger.Error("collect task error:", err)
diff --git a/plugins/tapd/tasks/worklog_collector.go 
b/plugins/tapd/tasks/worklog_collector.go
index 4987e17d..303e2b32 100644
--- a/plugins/tapd/tasks/worklog_collector.go
+++ b/plugins/tapd/tasks/worklog_collector.go
@@ -18,12 +18,10 @@ limitations under the License.
 package tasks
 
 import (
-       "encoding/json"
        "fmt"
        "github.com/apache/incubator-devlake/plugins/core"
        "github.com/apache/incubator-devlake/plugins/helper"
        "github.com/apache/incubator-devlake/plugins/tapd/models"
-       "net/http"
        "net/url"
        "time"
 )
@@ -76,13 +74,7 @@ func CollectWorklogs(taskCtx core.SubTaskContext) error {
                        }
                        return query, nil
                },
-               ResponseParser: func(res *http.Response) ([]json.RawMessage, 
error) {
-                       var data struct {
-                               Stories []json.RawMessage `json:"data"`
-                       }
-                       err := helper.UnmarshalResponse(res, &data)
-                       return data.Stories, err
-               },
+               ResponseParser: GetRawMessageArrayFromResponse,
        })
        if err != nil {
                logger.Error("collect worklog error:", err)

Reply via email to