This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch fix-zentao-dev-api
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/fix-zentao-dev-api by this
push:
new 6c7172d1b feat: fetch execution information from the built-in page
interface
6c7172d1b is described below
commit 6c7172d1b3765c6da9a6c9ff861596e68f21edbd
Author: abeizn <[email protected]>
AuthorDate: Mon May 27 13:52:41 2024 +0800
feat: fetch execution information from the built-in page interface
---
backend/plugins/zentao/impl/impl.go | 6 +-
.../tasks/execution_summary_dev_collector.go | 72 +++++++++++++++++++++
.../tasks/execution_summary_dev_extractor.go | 73 ++++++++++++++++++++++
3 files changed, 150 insertions(+), 1 deletion(-)
diff --git a/backend/plugins/zentao/impl/impl.go
b/backend/plugins/zentao/impl/impl.go
index b3fe6bafb..e46f8a107 100644
--- a/backend/plugins/zentao/impl/impl.go
+++ b/backend/plugins/zentao/impl/impl.go
@@ -118,9 +118,13 @@ func (p Zentao) SubTaskMetas() []plugin.SubTaskMeta {
tasks.CollectDepartmentMeta,
tasks.ExtractDepartmentMeta,
- // project
+ //project
tasks.CollectExecutionSummaryMeta,
tasks.ExtractExecutionSummaryMeta,
+
+ tasks.CollectExecutionSummaryDevMeta,
+ tasks.ExtractExecutionSummaryDevMeta,
+
tasks.CollectExecutionMeta,
tasks.ExtractExecutionMeta,
tasks.ConvertExecutionMeta,
diff --git a/backend/plugins/zentao/tasks/execution_summary_dev_collector.go
b/backend/plugins/zentao/tasks/execution_summary_dev_collector.go
new file mode 100644
index 000000000..257f14ead
--- /dev/null
+++ b/backend/plugins/zentao/tasks/execution_summary_dev_collector.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"
+ "fmt"
+ "net/http"
+
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/core/plugin"
+ "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+)
+
+const RAW_EXECUTION_SUMMARY_DEV_TABLE = "zentao_api_execution_summary_dev"
+
+var _ plugin.SubTaskEntryPoint = CollectExecutionSummaryDev
+
+func CollectExecutionSummaryDev(taskCtx plugin.SubTaskContext) errors.Error {
+ data := taskCtx.GetData().(*ZentaoTaskData)
+ collector, err := api.NewApiCollector(api.ApiCollectorArgs{
+ RawDataSubTaskArgs: api.RawDataSubTaskArgs{
+ Ctx: taskCtx,
+ Options: data.Options,
+ Table: RAW_EXECUTION_SUMMARY_DEV_TABLE,
+ },
+ ApiClient: data.ApiClient,
+ UrlTemplate:
fmt.Sprintf("../../project-execution-0-%d-0-0.json", data.Options.ProjectId),
+ ResponseParser: func(res *http.Response) ([]json.RawMessage,
errors.Error) {
+ var responseData struct {
+ Data json.RawMessage `json:"data"`
+ }
+ err := api.UnmarshalResponse(res, &responseData)
+ if err != nil {
+ return nil, nil
+ }
+ if responseData.Data == nil {
+ return nil, nil
+ }
+
+ return []json.RawMessage{responseData.Data}, nil
+ },
+ })
+ if err != nil {
+ return err
+ }
+
+ return collector.Execute()
+}
+
+var CollectExecutionSummaryDevMeta = plugin.SubTaskMeta{
+ Name: "collectExecutionSummaryDev",
+ EntryPoint: CollectExecutionSummaryDev,
+ EnabledByDefault: true,
+ Description: "Collect Execution summary index data from Zentao
built-in page api",
+ DomainTypes: []string{plugin.DOMAIN_TYPE_TICKET},
+}
diff --git a/backend/plugins/zentao/tasks/execution_summary_dev_extractor.go
b/backend/plugins/zentao/tasks/execution_summary_dev_extractor.go
new file mode 100644
index 000000000..7d3fd24a3
--- /dev/null
+++ b/backend/plugins/zentao/tasks/execution_summary_dev_extractor.go
@@ -0,0 +1,73 @@
+/*
+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 (
+ "strconv"
+ "strings"
+
+ "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 = ExtractExecutionSummaryDev
+
+var ExtractExecutionSummaryDevMeta = plugin.SubTaskMeta{
+ Name: "extractExecutionSummaryDev",
+ EntryPoint: ExtractExecutionSummaryDev,
+ EnabledByDefault: true,
+ Description: "extract Zentao execution summary from build-in page
api",
+ DomainTypes: []string{plugin.DOMAIN_TYPE_TICKET},
+}
+
+func ExtractExecutionSummaryDev(taskCtx plugin.SubTaskContext) errors.Error {
+ data := taskCtx.GetData().(*ZentaoTaskData)
+
+ extractor, err := api.NewApiExtractor(api.ApiExtractorArgs{
+ RawDataSubTaskArgs: api.RawDataSubTaskArgs{
+ Ctx: taskCtx,
+ Options: data.Options,
+ Table: RAW_EXECUTION_SUMMARY_DEV_TABLE,
+ },
+ Extract: func(row *api.RawData) ([]interface{}, errors.Error) {
+ executionSummary := &models.ZentaoExecutionSummary{}
+ executionSummary.ConnectionId =
data.Options.ConnectionId
+ executionSummary.Project = data.Options.ProjectId
+ // for example:
+ //
"{\"locate\":\"http:\\\/\\\/*.*.*.*\\\/zentao\\\/execution-task-259.json\"}"
+ parts := strings.Split(string(row.Data), "-")
+ value := strings.Split(parts[len(parts)-1], ".")[0]
+ id, err := strconv.ParseInt(value, 10, 64)
+ if err != nil {
+ // does not meet the format, skip it
+ return nil, nil
+ }
+ executionSummary.Id = id
+
+ return []interface{}{executionSummary}, nil
+ },
+ })
+
+ if err != nil {
+ return err
+ }
+
+ return extractor.Execute()
+}