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 4eb626375aa2fffec34e2e2b75a200925cba8b77
Author: abeizn <[email protected]>
AuthorDate: Mon Sep 26 15:20:47 2022 +0800

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

diff --git a/plugins/dora/tasks/cicd_task_env_enricher.go 
b/plugins/dora/tasks/cicd_task_env_enricher.go
index f571b80f..0e21c136 100644
--- a/plugins/dora/tasks/cicd_task_env_enricher.go
+++ b/plugins/dora/tasks/cicd_task_env_enricher.go
@@ -37,6 +37,15 @@ 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)
@@ -62,15 +71,19 @@ func EnrichTasksEnv(taskCtx core.SubTaskContext) (err 
errors.Error) {
        //      return errors.Default.Wrap(errRegexp, "Regexp compile 
testingPattern failed")
        // }
        var cursor *sql.Rows
-       if len(dataSource) == 0 {
+       _, f1 := Find(dataSource, "jenkins")
+       if !f1 {
                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.Join("left join cicd_pipeline_commits cpr on 
cpr.repo_id = '' and cicd_tasks.pipeline_id = cpr.pipeline_id "),
                        dal.Where("status=?", devops.DONE))
-       } else {
+       }
+       _, f2 := Find(dataSource, "github")
+       _, f3 := Find(dataSource, "gitlab")
+       if f2 || f3 || 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.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))
        }
        if err != nil {

Reply via email to