You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by wa...@apache.org on 2022/09/26 10:28:32 UTC

[incubator-devlake] 03/03: fix: type filed is nil in cicd_task table by jenkins-dora union plugin

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

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

commit 277e35ce605dd426a564d8041787ed4c2fe0e915
Author: abeizn <zi...@merico.dev>
AuthorDate: Mon Sep 26 16:33:40 2022 +0800

    fix: type filed is nil in cicd_task table by jenkins-dora union plugin
---
 plugins/dora/tasks/cicd_task_env_enricher.go | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/plugins/dora/tasks/cicd_task_env_enricher.go b/plugins/dora/tasks/cicd_task_env_enricher.go
index 0e21c136..c976b85b 100644
--- a/plugins/dora/tasks/cicd_task_env_enricher.go
+++ b/plugins/dora/tasks/cicd_task_env_enricher.go
@@ -37,15 +37,6 @@ var EnrichTaskEnvMeta = core.SubTaskMeta{
 	DomainTypes:      []string{core.DOMAIN_TYPE_CICD},
 }
 
-func Find(slice []string, val string) (int, bool) {
-	for i, item := range slice {
-		if item == val {
-			return i, true
-		}
-	}
-	return -1, false
-}
-
 func EnrichTasksEnv(taskCtx core.SubTaskContext) (err errors.Error) {
 	db := taskCtx.GetDal()
 	data := taskCtx.GetData().(*DoraTaskData)
@@ -70,21 +61,19 @@ func EnrichTasksEnv(taskCtx core.SubTaskContext) (err errors.Error) {
 	// if errRegexp != nil {
 	// 	return errors.Default.Wrap(errRegexp, "Regexp compile testingPattern failed")
 	// }
+
 	var cursor *sql.Rows
-	_, f1 := Find(dataSource, "jenkins")
-	if !f1 {
+	if len(dataSource) == 0 {
 		cursor, err = db.Cursor(
 			dal.From(&devops.CICDTask{}),
-			dal.Join("left join cicd_pipeline_commits cpr on cpr.repo_id = '' and cicd_tasks.pipeline_id = cpr.pipeline_id "),
-			dal.Where("status=?", devops.DONE))
-	}
-	_, f2 := Find(dataSource, "github")
-	_, f3 := Find(dataSource, "gitlab")
-	if f2 || f3 || len(dataSource) == 0 {
+			dal.Join("left join cicd_pipeline_commits cpr on cpr.repo_id = ? and cicd_tasks.pipeline_id = cpr.pipeline_id ", repoId),
+			dal.Where("status=? ", devops.DONE))
+	} else {
+
 		cursor, err = db.Cursor(
 			dal.From(&devops.CICDTask{}),
 			dal.Join("left join cicd_pipeline_commits cpr on cpr.repo_id = ? and cicd_tasks.pipeline_id = cpr.pipeline_id ", repoId),
-			dal.Where("status=?", devops.DONE))
+			dal.Where("status=? and SUBSTRING_INDEX(id, ':', 1) in ? ", devops.DONE, dataSource))
 	}
 	if err != nil {
 		return err