Skip to content

Commit

Permalink
feat: fetch execution information from the built-in page interface (#…
Browse files Browse the repository at this point in the history
…7513) (#7514)

Co-authored-by: abeizn <zikuan.an@merico.dev>
  • Loading branch information
github-actions[bot] and abeizn authored May 27, 2024
1 parent 8e464b4 commit f16c5df
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 1 deletion.
6 changes: 5 additions & 1 deletion backend/plugins/zentao/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
72 changes: 72 additions & 0 deletions backend/plugins/zentao/tasks/execution_summary_dev_collector.go
Original file line number Diff line number Diff line change
@@ -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},
}
73 changes: 73 additions & 0 deletions backend/plugins/zentao/tasks/execution_summary_dev_extractor.go
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit f16c5df

Please sign in to comment.