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

mintsweet pushed a commit to branch feat-dora-config
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 4e8bd5415047cd35cec94e21edb172e222044304
Author: abeizn <zikuan...@merico.dev>
AuthorDate: Sat Sep 14 15:43:18 2024 +0800

    fix: prod match when is nil (#8056)
---
 backend/plugins/bamboo/api/connection_api.go              |  6 +++---
 backend/plugins/bamboo/tasks/plan_build_extractor.go      |  2 +-
 backend/plugins/bitbucket/api/connection_api.go           |  6 +++---
 backend/plugins/circleci/api/connection_api.go            |  6 +++---
 backend/plugins/github/api/connection_api.go              |  6 +++---
 backend/plugins/gitlab/api/connection_api.go              |  6 +++---
 backend/plugins/gitlab/tasks/pipeline_detail_extractor.go |  2 +-
 backend/plugins/jenkins/api/connection_api.go             | 12 +++++++-----
 backend/server/services/remote/plugin/connection_api.go   |  6 +++---
 9 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/backend/plugins/bamboo/api/connection_api.go 
b/backend/plugins/bamboo/api/connection_api.go
index bf91cd5c2..bf35d5ac3 100644
--- a/backend/plugins/bamboo/api/connection_api.go
+++ b/backend/plugins/bamboo/api/connection_api.go
@@ -222,19 +222,19 @@ func GetConnectionTransformToDeployments(input 
*plugin.ApiResourceInput) (*plugi
                        SELECT plan_build_key, link_href, build_started_time
                        FROM _tool_bamboo_plan_builds
                        WHERE connection_id = ? 
-                           AND (? = '' OR plan_name REGEXP ?)
+                           AND (plan_name REGEXP ?)
                        AND (? = '' OR plan_name REGEXP ?)
                        UNION
                        SELECT p.plan_build_key, p.link_href, 
p.build_started_time
                        FROM _tool_bamboo_job_builds j
                        LEFT JOIN _tool_bamboo_plan_builds p on 
p.plan_build_key = j.plan_build_key
                        WHERE j.connection_id = ? 
-                           AND (? = '' OR j.job_name REGEXP ?)
+                           AND (j.job_name REGEXP ?)
                        AND (? = '' OR j.job_name REGEXP ?)
                        ORDER BY build_started_time DESC
                ) AS t
                ORDER BY build_started_time DESC
-       `, connectionId, deploymentPattern, deploymentPattern, 
productionPattern, productionPattern, connectionId, deploymentPattern, 
deploymentPattern, productionPattern, productionPattern)
+       `, connectionId, deploymentPattern, productionPattern, 
productionPattern, connectionId, deploymentPattern, productionPattern, 
productionPattern)
        if err != nil {
                return nil, errors.Default.Wrap(err, "error on get")
        }
diff --git a/backend/plugins/bamboo/tasks/plan_build_extractor.go 
b/backend/plugins/bamboo/tasks/plan_build_extractor.go
index 8832d9df1..2ce1eeb86 100644
--- a/backend/plugins/bamboo/tasks/plan_build_extractor.go
+++ b/backend/plugins/bamboo/tasks/plan_build_extractor.go
@@ -46,7 +46,7 @@ func ExtractPlanBuild(taskCtx plugin.SubTaskContext) 
errors.Error {
                        body.ConnectionId = data.Options.ConnectionId
                        body.PlanKey = data.Options.PlanKey
                        body.Type = 
data.RegexEnricher.ReturnNameIfMatched(devops.DEPLOYMENT, body.PlanName)
-                       body.Environment = 
data.RegexEnricher.ReturnNameIfMatched(devops.PRODUCTION, body.PlanName)
+                       body.Environment = 
data.RegexEnricher.ReturnNameIfOmittedOrMatched(devops.PRODUCTION, 
body.PlanName)
 
                        var url string
                        homepage, errGetHomePage := 
GetBambooHomePage(body.LinkHref)
diff --git a/backend/plugins/bitbucket/api/connection_api.go 
b/backend/plugins/bitbucket/api/connection_api.go
index 8d7199159..07c04c35a 100644
--- a/backend/plugins/bitbucket/api/connection_api.go
+++ b/backend/plugins/bitbucket/api/connection_api.go
@@ -205,18 +205,18 @@ func GetConnectionTransformToDeployments(input 
*plugin.ApiResourceInput) (*plugi
                        SELECT build_number, ref_name, repo_id, web_url, 
bitbucket_created_on
                        FROM _tool_bitbucket_pipelines
                        WHERE connection_id = ? 
-                           AND (? = '' OR ref_name REGEXP ?)
+                           AND (ref_name REGEXP ?)
                        AND (? = '' OR ref_name REGEXP ?)
                        UNION
                        SELECT build_number, ref_name, p.repo_id, 
web_url,bitbucket_created_on
                        FROM _tool_bitbucket_pipelines p
                        LEFT JOIN _tool_bitbucket_pipeline_steps s on 
s.pipeline_id = p.bitbucket_id
                        WHERE s.connection_id = ? AND 
-                               AND (? = '' OR s.name REGEXP ?)
+                               AND (s.name REGEXP ?)
                        AND (? = '' OR s.name REGEXP ?)
                ) AS t
                ORDER BY bitbucket_created_on DESC
-       `, connectionId, deploymentPattern, deploymentPattern, 
productionPattern, productionPattern, connectionId, deploymentPattern, 
deploymentPattern, productionPattern, productionPattern)
+       `, connectionId, deploymentPattern, productionPattern, 
productionPattern, connectionId, deploymentPattern, productionPattern, 
productionPattern)
        if err != nil {
                return nil, errors.Default.Wrap(err, "error on get")
        }
diff --git a/backend/plugins/circleci/api/connection_api.go 
b/backend/plugins/circleci/api/connection_api.go
index e3efd7f8a..b2a8c567a 100644
--- a/backend/plugins/circleci/api/connection_api.go
+++ b/backend/plugins/circleci/api/connection_api.go
@@ -198,18 +198,18 @@ func GetConnectionTransformToDeployments(input 
*plugin.ApiResourceInput) (*plugi
                        SELECT pipeline_number, name, project_slug, created_date
                        FROM _tool_circleci_workflows
                        WHERE connection_id = ? 
-                           AND (? = '' OR name REGEXP ?)
+                           AND (name REGEXP ?)
                        AND (? = '' OR name REGEXP ?)
                        UNION
                        SELECT w.pipeline_number, w.name, w.project_slug, 
w.created_date
                        FROM _tool_circleci_jobs j 
                        LEFT JOIN _tool_circleci_workflows w on w.id = 
j.workflow_id
                        WHERE j.connection_id = ? 
-                           AND (? = '' OR j.name REGEXP ?)
+                           AND (j.name REGEXP ?)
                        AND (? = '' OR j.name REGEXP ?)
                ) AS t
                ORDER BY created_date DESC
-       `, connectionId, deploymentPattern, deploymentPattern, 
productionPattern, productionPattern, connectionId, deploymentPattern, 
deploymentPattern, productionPattern, productionPattern)
+       `, connectionId, deploymentPattern, productionPattern, 
productionPattern, connectionId, deploymentPattern, productionPattern, 
productionPattern)
        if err != nil {
                return nil, errors.Default.Wrap(err, "error on get")
        }
diff --git a/backend/plugins/github/api/connection_api.go 
b/backend/plugins/github/api/connection_api.go
index c2da93afb..a4b9dd663 100644
--- a/backend/plugins/github/api/connection_api.go
+++ b/backend/plugins/github/api/connection_api.go
@@ -461,18 +461,18 @@ func GetConnectionTransformToDeployments(input 
*plugin.ApiResourceInput) (*plugi
                        SELECT id, run_number, name, head_branch, html_url, 
run_started_at
                        FROM _tool_github_runs
                        WHERE connection_id = ? 
-                               AND (? = '' OR name REGEXP ?)
+                               AND (name REGEXP ?)
                                AND (? = '' OR name REGEXP ? OR head_branch 
REGEXP ?)
                        UNION
                        SELECT r.id, r.run_number, r.name, r.head_branch, 
r.html_url, r.run_started_at
                        FROM _tool_github_jobs j
                        LEFT JOIN _tool_github_runs r ON j.run_id = r.id
                        WHERE j.connection_id = ?
-                           AND (? = '' OR j.name REGEXP ?)
+                           AND (j.name REGEXP ?)
                        AND (? = '' OR j.name REGEXP ?)
                ) r
                ORDER BY r.run_started_at DESC
-       `, connectionId, deploymentPattern, deploymentPattern, 
productionPattern, productionPattern, productionPattern, connectionId, 
deploymentPattern, deploymentPattern, productionPattern, productionPattern)
+       `, connectionId, deploymentPattern, productionPattern, 
productionPattern, productionPattern, connectionId, deploymentPattern, 
productionPattern, productionPattern)
        if err != nil {
                return nil, errors.Default.Wrap(err, "error on get")
        }
diff --git a/backend/plugins/gitlab/api/connection_api.go 
b/backend/plugins/gitlab/api/connection_api.go
index f84ad9a46..ca557a2b8 100644
--- a/backend/plugins/gitlab/api/connection_api.go
+++ b/backend/plugins/gitlab/api/connection_api.go
@@ -234,7 +234,7 @@ func GetConnectionTransformToDeployments(input 
*plugin.ApiResourceInput) (*plugi
                        FROM _tool_gitlab_pipelines p
                        LEFT JOIN _tool_gitlab_projects r on r.gitlab_id = 
p.project_id
                        WHERE p.connection_id = ? 
-                               AND (? = '' OR ref REGEXP ?)
+                               AND (ref REGEXP ?)
                                AND (? = '' OR ref REGEXP ?)
                        UNION
                        SELECT r.name, p.gitlab_id, p.web_url, p.started_at
@@ -242,11 +242,11 @@ func GetConnectionTransformToDeployments(input 
*plugin.ApiResourceInput) (*plugi
                        LEFT JOIN _tool_gitlab_projects r on r.gitlab_id = 
p.project_id
                        LEFT JOIN _tool_gitlab_jobs j on j.pipeline_id = 
p.gitlab_id
                        WHERE j.connection_id = ? 
-                               AND (? = '' OR j.name REGEXP ?)
+                               AND (j.name REGEXP ?)
                        AND (? = '' OR j.name REGEXP ?)
                ) r
                ORDER BY r.started_at DESC
-       `, connectionId, deploymentPattern, deploymentPattern, 
productionPattern, productionPattern, connectionId, deploymentPattern, 
deploymentPattern, productionPattern, productionPattern)
+       `, connectionId, deploymentPattern, productionPattern, 
productionPattern, connectionId, deploymentPattern, productionPattern, 
productionPattern)
        if err != nil {
                return nil, errors.Default.Wrap(err, "error on get")
        }
diff --git a/backend/plugins/gitlab/tasks/pipeline_detail_extractor.go 
b/backend/plugins/gitlab/tasks/pipeline_detail_extractor.go
index 1b78362a1..94d45a4f2 100644
--- a/backend/plugins/gitlab/tasks/pipeline_detail_extractor.go
+++ b/backend/plugins/gitlab/tasks/pipeline_detail_extractor.go
@@ -68,7 +68,7 @@ func ExtractApiPipelineDetails(taskCtx plugin.SubTaskContext) 
errors.Error {
                                QueuedDuration:  
gitlabApiPipeline.QueuedDuration,
                                ConnectionId:    data.Options.ConnectionId,
                                Type:            
data.RegexEnricher.ReturnNameIfMatched(devops.DEPLOYMENT, 
gitlabApiPipeline.Ref),
-                               Environment:     
data.RegexEnricher.ReturnNameIfMatched(devops.PRODUCTION, 
gitlabApiPipeline.Ref),
+                               Environment:     
data.RegexEnricher.ReturnNameIfOmittedOrMatched(devops.PRODUCTION, 
gitlabApiPipeline.Ref),
                                Source:          gitlabApiPipeline.Source,
                        }
 
diff --git a/backend/plugins/jenkins/api/connection_api.go 
b/backend/plugins/jenkins/api/connection_api.go
index 79dd87e53..6f5e3ab44 100644
--- a/backend/plugins/jenkins/api/connection_api.go
+++ b/backend/plugins/jenkins/api/connection_api.go
@@ -207,17 +207,19 @@ func GetConnectionTransformToDeployments(input 
*plugin.ApiResourceInput) (*plugi
                FROM(
                        SELECT number, job_name, full_name, url, start_time
                        FROM _tool_jenkins_builds
-                       WHERE connection_id = ? AND full_name REGEXP ?
-                       AND full_name REGEXP ?
+                       WHERE connection_id = ? 
+                               AND (full_name REGEXP ?)
+                               AND (? = '' OR full_name REGEXP ?)
                        UNION
                        SELECT number, job_name, full_name, url, start_time
                        FROM _tool_jenkins_stages s 
                        LEFT JOIN _tool_jenkins_builds b ON b.full_name = 
s.build_name 
-                       WHERE s.connection_id = ? AND s.name REGEXP ?
-                       AND s.name REGEXP ?
+                       WHERE s.connection_id = ? 
+                               AND s.name REGEXP ?
+                               AND (? = '' OR s.name REGEXP ?)
                ) AS t
                ORDER BY start_time DESC
-       `, connectionId, deploymentPattern, productionPattern, connectionId, 
deploymentPattern, productionPattern)
+       `, connectionId, deploymentPattern, productionPattern, 
productionPattern, connectionId, deploymentPattern, productionPattern, 
productionPattern)
        if err != nil {
                return nil, errors.Default.Wrap(err, "error on get")
        }
diff --git a/backend/server/services/remote/plugin/connection_api.go 
b/backend/server/services/remote/plugin/connection_api.go
index 7b8b185cb..dff907304 100644
--- a/backend/server/services/remote/plugin/connection_api.go
+++ b/backend/server/services/remote/plugin/connection_api.go
@@ -205,18 +205,18 @@ func (pa *pluginAPI) 
GetConnectionTransformToDeployments(input *plugin.ApiResour
                        SELECT id, name, url, start_time
                        FROM _tool_azuredevops_builds
                WHERE connection_id = ?
-                       AND (? = '' OR name REGEXP ?)
+                       AND (name REGEXP ?)
                        AND (? = '' OR name REGEXP ?)
                UNION
                        SELECT b.id, b.name, b.url, b.start_time
                        FROM _tool_azuredevops_jobs j
                        LEFT JOIN _tool_azuredevops_builds b on 
CONCAT('azuredevops:Build:', b.connection_id, ':', b.id) = j.build_id
                        WHERE j.connection_id = ?
-                           AND (? = '' OR j.name REGEXP ?)
+                           AND (j.name REGEXP ?)
                        AND (? = '' OR j.name REGEXP ?)
                ) AS t
                ORDER BY start_time DESC
-       `, connectionId, deploymentPattern, deploymentPattern, 
productionPattern, productionPattern, connectionId, deploymentPattern, 
deploymentPattern, productionPattern, productionPattern)
+       `, connectionId, deploymentPattern, productionPattern, 
productionPattern, connectionId, deploymentPattern, productionPattern, 
productionPattern)
        if err != nil {
                return nil, errors.Default.Wrap(err, "error on get")
        }

Reply via email to