Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fetch execution information from the built-in page interface #7513

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
Loading