You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by kl...@apache.org on 2023/12/01 09:35:23 UTC
(incubator-devlake) 04/04: refactor: extract MakePipelinePlanTask function
This is an automated email from the ASF dual-hosted git repository.
klesh pushed a commit to branch kw-5519-jenkins
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit 1dcccdd3f2a213ac70e24723d6e9abe6a8ee214f
Author: Klesh Wong <zh...@merico.dev>
AuthorDate: Fri Dec 1 17:34:50 2023 +0800
refactor: extract MakePipelinePlanTask function
---
backend/helpers/pluginhelper/api/pipeline_plan.go | 31 ++++++++++++++++++++++
backend/plugins/github/api/blueprint_v200.go | 24 +++++------------
.../github/api/{remote.go => remote_api.go} | 0
backend/plugins/github/tasks/task_data.go | 9 -------
4 files changed, 37 insertions(+), 27 deletions(-)
diff --git a/backend/helpers/pluginhelper/api/pipeline_plan.go b/backend/helpers/pluginhelper/api/pipeline_plan.go
index ce920b168..4c11f6ef3 100644
--- a/backend/helpers/pluginhelper/api/pipeline_plan.go
+++ b/backend/helpers/pluginhelper/api/pipeline_plan.go
@@ -21,6 +21,7 @@ import (
"fmt"
"github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/core/models"
plugin "github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/core/utils"
)
@@ -52,3 +53,33 @@ func MakePipelinePlanSubtasks(subtaskMetas []plugin.SubTaskMeta, entities []stri
}
return subtasks, nil
}
+
+func MakePipelinePlanTask(
+ pluginName string,
+ subtaskMetas []plugin.SubTaskMeta,
+ entities []string,
+ options interface{},
+) (*models.PipelineTask, errors.Error) {
+ subtasks, err := MakePipelinePlanSubtasks(subtaskMetas, entities)
+ if err != nil {
+ return nil, err
+ }
+ op, err := encodeTaskOptions(options)
+ if err != nil {
+ return nil, err
+ }
+ return &models.PipelineTask{
+ Plugin: pluginName,
+ Subtasks: subtasks,
+ Options: op,
+ }, nil
+}
+
+func encodeTaskOptions(op interface{}) (map[string]interface{}, errors.Error) {
+ var result map[string]interface{}
+ err := Decode(op, &result, nil)
+ if err != nil {
+ return nil, err
+ }
+ return result, nil
+}
diff --git a/backend/plugins/github/api/blueprint_v200.go b/backend/plugins/github/api/blueprint_v200.go
index aaf85b147..156b10730 100644
--- a/backend/plugins/github/api/blueprint_v200.go
+++ b/backend/plugins/github/api/blueprint_v200.go
@@ -111,11 +111,7 @@ func makeDataSourcePipelinePlanV200(
GithubId: githubRepo.GithubId,
Name: githubRepo.FullName,
}
- options, err := tasks.EncodeTaskOptions(op)
- if err != nil {
- return nil, err
- }
- stage, err = addGithub(subtaskMetas, connection, scopeConfig.Entities, stage, options)
+ stage, err := addGithub(subtaskMetas, connection, scopeConfig.Entities, stage, op)
if err != nil {
return nil, err
}
@@ -196,7 +192,7 @@ func addGithub(
connection *models.GithubConnection,
entities []string,
stage coreModels.PipelineStage,
- options map[string]interface{},
+ options *tasks.GithubOptions,
) (coreModels.PipelineStage, errors.Error) {
// construct github(graphql) task
if connection.EnableGraphql {
@@ -206,28 +202,20 @@ func addGithub(
return nil, err
}
if pluginGq, ok := p.(plugin.PluginTask); ok {
- subtasks, err := helper.MakePipelinePlanSubtasks(pluginGq.SubTaskMetas(), entities)
+ task, err := helper.MakePipelinePlanTask("github_graphql", pluginGq.SubTaskMetas(), entities, options)
if err != nil {
return nil, err
}
- stage = append(stage, &coreModels.PipelineTask{
- Plugin: "github_graphql",
- Subtasks: subtasks,
- Options: options,
- })
+ stage = append(stage, task)
} else {
return nil, errors.BadInput.New("plugin github_graphql does not support SubTaskMetas")
}
} else {
- subtasks, err := helper.MakePipelinePlanSubtasks(subtaskMetas, entities)
+ task, err := helper.MakePipelinePlanTask("github", subtaskMetas, entities, options)
if err != nil {
return nil, err
}
- stage = append(stage, &coreModels.PipelineTask{
- Plugin: "github",
- Subtasks: subtasks,
- Options: options,
- })
+ stage = append(stage, task)
}
return stage, nil
}
diff --git a/backend/plugins/github/api/remote.go b/backend/plugins/github/api/remote_api.go
similarity index 100%
rename from backend/plugins/github/api/remote.go
rename to backend/plugins/github/api/remote_api.go
diff --git a/backend/plugins/github/tasks/task_data.go b/backend/plugins/github/tasks/task_data.go
index 714dbbd95..f87d57694 100644
--- a/backend/plugins/github/tasks/task_data.go
+++ b/backend/plugins/github/tasks/task_data.go
@@ -67,15 +67,6 @@ func DecodeTaskOptions(options map[string]interface{}) (*GithubOptions, errors.E
return &op, nil
}
-func EncodeTaskOptions(op *GithubOptions) (map[string]interface{}, errors.Error) {
- var result map[string]interface{}
- err := helper.Decode(op, &result, nil)
- if err != nil {
- return nil, err
- }
- return result, nil
-}
-
func ValidateTaskOptions(op *GithubOptions) errors.Error {
if op.Name == "" {
op.Name = strings.Trim(fmt.Sprintf("%s/%s", op.Owner, op.Repo), " ")