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 3e597f15 feat(tapd): add task and bug custom fields (#2009)
3e597f15 is described below

commit 3e597f15ca82bd2b73a3044dc7c6d39ba40b281a
Author: Warren Chen <[email protected]>
AuthorDate: Fri May 27 16:06:42 2022 +0800

    feat(tapd): add task and bug custom fields (#2009)
---
 plugins/tapd/tapd.go                               |  4 ++
 plugins/tapd/tasks/bug_custom_fields_collector.go  | 74 ++++++++++++++++++++++
 plugins/tapd/tasks/bug_custom_fields_extractor.go  | 72 +++++++++++++++++++++
 plugins/tapd/tasks/task_custom_fields_collector.go | 74 ++++++++++++++++++++++
 plugins/tapd/tasks/task_custom_fields_extractor.go | 72 +++++++++++++++++++++
 5 files changed, 296 insertions(+)

diff --git a/plugins/tapd/tapd.go b/plugins/tapd/tapd.go
index f0ffcded..9fdc24b5 100644
--- a/plugins/tapd/tapd.go
+++ b/plugins/tapd/tapd.go
@@ -60,6 +60,10 @@ func (plugin Tapd) SubTaskMetas() []core.SubTaskMeta {
                //tasks.ExtractWorkspaceMeta,
                tasks.CollectStoryCustomFieldsMeta,
                tasks.ExtractStoryCustomFieldsMeta,
+               tasks.CollectTaskCustomFieldsMeta,
+               tasks.ExtractTaskCustomFieldsMeta,
+               tasks.CollectBugCustomFieldsMeta,
+               tasks.ExtractBugCustomFieldsMeta,
                //tasks.CollectBugStatusMeta,
                //tasks.ExtractBugStatusMeta,
                //tasks.CollectUserMeta,
diff --git a/plugins/tapd/tasks/bug_custom_fields_collector.go 
b/plugins/tapd/tasks/bug_custom_fields_collector.go
new file mode 100644
index 00000000..c3347b6a
--- /dev/null
+++ b/plugins/tapd/tasks/bug_custom_fields_collector.go
@@ -0,0 +1,74 @@
+/*
+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"
+       "fmt"
+       "github.com/apache/incubator-devlake/plugins/core"
+       "github.com/apache/incubator-devlake/plugins/helper"
+       "net/http"
+       "net/url"
+)
+
+const RAW_BUG_CUSTOM_FIELDS_TABLE = "tapd_api_bug_bug_custom_fields"
+
+var _ core.SubTaskEntryPoint = CollectBugCustomFields
+
+func CollectBugCustomFields(taskCtx core.SubTaskContext) error {
+       data := taskCtx.GetData().(*TapdTaskData)
+       logger := taskCtx.GetLogger()
+       logger.Info("collect bug_custom_fields")
+       collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
+               RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+                       Ctx: taskCtx,
+                       Params: TapdApiParams{
+                               ConnectionId: data.Connection.ID,
+                               WorkspaceID:  data.Options.WorkspaceID,
+                       },
+                       Table: RAW_BUG_CUSTOM_FIELDS_TABLE,
+               },
+               ApiClient: data.ApiClient,
+               //PageSize:    100,
+               UrlTemplate: "bugs/custom_fields_settings",
+               Query: func(reqData *helper.RequestData) (url.Values, error) {
+                       query := url.Values{}
+                       query.Set("workspace_id", fmt.Sprintf("%v", 
data.Options.WorkspaceID))
+                       return query, nil
+               },
+               ResponseParser: func(res *http.Response) ([]json.RawMessage, 
error) {
+                       var data struct {
+                               BugCustomFields []json.RawMessage `json:"data"`
+                       }
+                       err := helper.UnmarshalResponse(res, &data)
+                       return data.BugCustomFields, err
+               },
+       })
+       if err != nil {
+               logger.Error("collect bug_custom_fields error:", err)
+               return err
+       }
+       return collector.Execute()
+}
+
+var CollectBugCustomFieldsMeta = core.SubTaskMeta{
+       Name:        "collectBugCustomFields",
+       EntryPoint:  CollectBugCustomFields,
+       Required:    true,
+       Description: "collect Tapd BugCustomFields",
+}
diff --git a/plugins/tapd/tasks/bug_custom_fields_extractor.go 
b/plugins/tapd/tasks/bug_custom_fields_extractor.go
new file mode 100644
index 00000000..c4f01950
--- /dev/null
+++ b/plugins/tapd/tasks/bug_custom_fields_extractor.go
@@ -0,0 +1,72 @@
+/*
+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 = ExtractBugCustomFields
+
+var ExtractBugCustomFieldsMeta = core.SubTaskMeta{
+       Name:             "extractBugCustomFields",
+       EntryPoint:       ExtractBugCustomFields,
+       EnabledByDefault: true,
+       Description:      "Extract raw company data into tool layer table 
_tool_tapd_bug_custom_fields",
+}
+
+type TapdBugCustomFieldsRes struct {
+       CustomFieldConfig models.TapdBugCustomFields
+}
+
+func ExtractBugCustomFields(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_BUG_CUSTOM_FIELDS_TABLE,
+               },
+               Extract: func(row *helper.RawData) ([]interface{}, error) {
+                       var customFields TapdBugCustomFieldsRes
+                       err := json.Unmarshal(row.Data, &customFields)
+                       if err != nil {
+                               return nil, err
+                       }
+
+                       toolL := customFields.CustomFieldConfig
+
+                       toolL.ConnectionId = data.Connection.ID
+                       return []interface{}{
+                               &toolL,
+                       }, nil
+               },
+       })
+
+       if err != nil {
+               return err
+       }
+
+       return extractor.Execute()
+}
diff --git a/plugins/tapd/tasks/task_custom_fields_collector.go 
b/plugins/tapd/tasks/task_custom_fields_collector.go
new file mode 100644
index 00000000..976375ac
--- /dev/null
+++ b/plugins/tapd/tasks/task_custom_fields_collector.go
@@ -0,0 +1,74 @@
+/*
+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"
+       "fmt"
+       "github.com/apache/incubator-devlake/plugins/core"
+       "github.com/apache/incubator-devlake/plugins/helper"
+       "net/http"
+       "net/url"
+)
+
+const RAW_TASK_CUSTOM_FIELDS_TABLE = "tapd_api_task_task_custom_fields"
+
+var _ core.SubTaskEntryPoint = CollectTaskCustomFields
+
+func CollectTaskCustomFields(taskCtx core.SubTaskContext) error {
+       data := taskCtx.GetData().(*TapdTaskData)
+       logger := taskCtx.GetLogger()
+       logger.Info("collect task_custom_fields")
+       collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
+               RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+                       Ctx: taskCtx,
+                       Params: TapdApiParams{
+                               ConnectionId: data.Connection.ID,
+                               WorkspaceID:  data.Options.WorkspaceID,
+                       },
+                       Table: RAW_TASK_CUSTOM_FIELDS_TABLE,
+               },
+               ApiClient: data.ApiClient,
+               //PageSize:    100,
+               UrlTemplate: "tasks/custom_fields_settings",
+               Query: func(reqData *helper.RequestData) (url.Values, error) {
+                       query := url.Values{}
+                       query.Set("workspace_id", fmt.Sprintf("%v", 
data.Options.WorkspaceID))
+                       return query, nil
+               },
+               ResponseParser: func(res *http.Response) ([]json.RawMessage, 
error) {
+                       var data struct {
+                               TaskCustomFields []json.RawMessage `json:"data"`
+                       }
+                       err := helper.UnmarshalResponse(res, &data)
+                       return data.TaskCustomFields, err
+               },
+       })
+       if err != nil {
+               logger.Error("collect task_custom_fields error:", err)
+               return err
+       }
+       return collector.Execute()
+}
+
+var CollectTaskCustomFieldsMeta = core.SubTaskMeta{
+       Name:        "collectTaskCustomFields",
+       EntryPoint:  CollectTaskCustomFields,
+       Required:    true,
+       Description: "collect Tapd TaskCustomFields",
+}
diff --git a/plugins/tapd/tasks/task_custom_fields_extractor.go 
b/plugins/tapd/tasks/task_custom_fields_extractor.go
new file mode 100644
index 00000000..46c9879a
--- /dev/null
+++ b/plugins/tapd/tasks/task_custom_fields_extractor.go
@@ -0,0 +1,72 @@
+/*
+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 = ExtractTaskCustomFields
+
+var ExtractTaskCustomFieldsMeta = core.SubTaskMeta{
+       Name:             "extractTaskCustomFields",
+       EntryPoint:       ExtractTaskCustomFields,
+       EnabledByDefault: true,
+       Description:      "Extract raw company data into tool layer table 
_tool_tapd_task_custom_fields",
+}
+
+type TapdTaskCustomFieldsRes struct {
+       CustomFieldConfig models.TapdTaskCustomFields
+}
+
+func ExtractTaskCustomFields(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_TASK_CUSTOM_FIELDS_TABLE,
+               },
+               Extract: func(row *helper.RawData) ([]interface{}, error) {
+                       var customFields TapdTaskCustomFieldsRes
+                       err := json.Unmarshal(row.Data, &customFields)
+                       if err != nil {
+                               return nil, err
+                       }
+
+                       toolL := customFields.CustomFieldConfig
+
+                       toolL.ConnectionId = data.Connection.ID
+                       return []interface{}{
+                               &toolL,
+                       }, nil
+               },
+       })
+
+       if err != nil {
+               return err
+       }
+
+       return extractor.Execute()
+}

Reply via email to