-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fetch execution information from the built-in page interface (#…
- Loading branch information
Showing
3 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
backend/plugins/zentao/tasks/execution_summary_dev_collector.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
73
backend/plugins/zentao/tasks/execution_summary_dev_extractor.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |