You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2022/10/13 08:43:52 UTC

[incubator-devlake] 03/03: fix(github): modify blueprint according to review

This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 3477db5439569f33199ae2b06c7a3fcd5cedffff
Author: Yingchu Chen <yi...@merico.dev>
AuthorDate: Thu Oct 13 12:05:02 2022 +0800

    fix(github): modify blueprint according to review
---
 plugins/github/api/blueprint.go      | 30 ++++++++++++++++--------------
 plugins/github/api/blueprint_test.go |  2 --
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/plugins/github/api/blueprint.go b/plugins/github/api/blueprint.go
index 40e334fc..e9dc5d1a 100644
--- a/plugins/github/api/blueprint.go
+++ b/plugins/github/api/blueprint.go
@@ -68,12 +68,6 @@ func MakePipelinePlan(subtaskMetas []core.SubTaskMeta, connectionId uint64, scop
 func makePipelinePlan(subtaskMetas []core.SubTaskMeta, scope []*core.BlueprintScopeV100, apiClient helper.ApiClientGetter, connection *models.GithubConnection) (core.PipelinePlan, errors.Error) {
 	var err errors.Error
 	var repo *tasks.GithubApiRepo
-	getApiRepoIfNil := func(op *tasks.GithubOptions) (*tasks.GithubApiRepo, errors.Error) {
-		if repo == nil {
-			repo, err = getApiRepo(op, apiClient)
-		}
-		return repo, err
-	}
 	plan := make(core.PipelinePlan, len(scope))
 	for i, scopeElem := range scope {
 		// handle taskOptions and transformationRules, by dumping them to taskOptions
@@ -113,6 +107,13 @@ func makePipelinePlan(subtaskMetas []core.SubTaskMeta, scope []*core.BlueprintSc
 		if err != nil {
 			return nil, err
 		}
+		memorizedGetApiRepo := func() (*tasks.GithubApiRepo, errors.Error) {
+			if repo == nil {
+				repo, err = getApiRepo(op, apiClient)
+			}
+			return repo, err
+		}
+
 		// construct subtasks
 		subtasks, err := helper.MakePipelinePlanSubtasks(subtaskMetas, scopeElem.Entities)
 		if err != nil {
@@ -131,7 +132,7 @@ func makePipelinePlan(subtaskMetas []core.SubTaskMeta, scope []*core.BlueprintSc
 		if utils.StringsContains(scopeElem.Entities, core.DOMAIN_TYPE_CODE) {
 			// here is the tricky part, we have to obtain the repo id beforehand
 			token := strings.Split(connection.Token, ",")[0]
-			repo, err = getApiRepoIfNil(op)
+			repo, err = memorizedGetApiRepo()
 			if err != nil {
 				return nil, err
 			}
@@ -165,21 +166,21 @@ func makePipelinePlan(subtaskMetas []core.SubTaskMeta, scope []*core.BlueprintSc
 			if err != nil {
 				return nil, err
 			}
-			repo, err = getApiRepoIfNil(op)
+			repo, err = memorizedGetApiRepo()
 			if err != nil {
 				return nil, err
 			}
 
-			doraOption := make(map[string]interface{})
-			doraOption["repoId"] = didgen.NewDomainIdGenerator(&models.GithubRepo{}).Generate(connection.ID, repo.GithubId)
-			doraRules := make(map[string]interface{})
-			doraRules["productionPattern"] = productionPattern
-			doraOption["transformationRules"] = doraRules
 			plan[j] = core.PipelineStage{
 				{
 					Plugin:   "dora",
 					Subtasks: []string{"EnrichTaskEnv"},
-					Options:  doraOption,
+					Options: map[string]interface{}{
+						"repoId": didgen.NewDomainIdGenerator(&models.GithubRepo{}).Generate(connection.ID, repo.GithubId),
+						"transformationRules": map[string]interface{}{
+							"productionPattern": productionPattern,
+						},
+					},
 				},
 			}
 			// remove it from github transformationRules
@@ -189,6 +190,7 @@ func makePipelinePlan(subtaskMetas []core.SubTaskMeta, scope []*core.BlueprintSc
 		if err != nil {
 			return nil, err
 		}
+		repo = nil
 	}
 	return plan, nil
 }
diff --git a/plugins/github/api/blueprint_test.go b/plugins/github/api/blueprint_test.go
index 08dd0390..c663e3ba 100644
--- a/plugins/github/api/blueprint_test.go
+++ b/plugins/github/api/blueprint_test.go
@@ -86,8 +86,6 @@ func TestProcessScope(t *testing.T) {
 	plan, err := makePipelinePlan(nil, scopes, mockApiCLient, connection)
 	assert.Nil(t, err)
 
-	//planJson, err1 := json.Marshal(plan)
-	//assert.Nil(t, err1)
 	expectPlan := core.PipelinePlan{
 		core.PipelineStage{
 			{