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
The following commit(s) were added to refs/heads/main by this push:
new 5e28bc9f fix: add param datasource for dora enrichTasksEnv
5e28bc9f is described below
commit 5e28bc9f29f60baf4dc1d61aaca9f02c2af7d3ab
Author: abeizn <[email protected]>
AuthorDate: Wed Sep 21 11:26:50 2022 +0800
fix: add param datasource for dora enrichTasksEnv
---
plugins/dora/tasks/cicd_task_env_enricher.go | 20 +++++++++++++++-----
plugins/dora/tasks/task_data.go | 7 ++++---
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/plugins/dora/tasks/cicd_task_env_enricher.go
b/plugins/dora/tasks/cicd_task_env_enricher.go
index c1a1a5b2..d04d0bc7 100644
--- a/plugins/dora/tasks/cicd_task_env_enricher.go
+++ b/plugins/dora/tasks/cicd_task_env_enricher.go
@@ -18,6 +18,7 @@ limitations under the License.
package tasks
import (
+ "database/sql"
"reflect"
"regexp"
@@ -44,6 +45,7 @@ func EnrichTasksEnv(taskCtx core.SubTaskContext) (err
errors.Error) {
productionNamePattern := data.Options.ProductionPattern
stagingNamePattern := data.Options.StagingPattern
testingNamePattern := data.Options.TestingPattern
+ dataSource := data.Options.DataSoure
productionNameRegexp, errRegexp := regexp.Compile(productionNamePattern)
if errRegexp != nil {
@@ -57,14 +59,22 @@ func EnrichTasksEnv(taskCtx core.SubTaskContext) (err
errors.Error) {
if errRegexp != nil {
return errors.Default.Wrap(errRegexp, "Regexp compile
testingPattern failed")
}
-
- 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))
+ var cursor *sql.Rows
+ 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 ", 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 "),
+ dal.Where("status=?", devops.DONE))
+ }
if err != nil {
return err
}
+
defer cursor.Close()
converter, err := helper.NewDataConverter(helper.DataConverterArgs{
diff --git a/plugins/dora/tasks/task_data.go b/plugins/dora/tasks/task_data.go
index 57a5aa57..31de4300 100644
--- a/plugins/dora/tasks/task_data.go
+++ b/plugins/dora/tasks/task_data.go
@@ -26,9 +26,10 @@ type DoraApiParams struct {
}
type TransformationRules struct {
- ProductionPattern string `mapstructure:"productionPattern"
json:"productionPattern"`
- StagingPattern string `mapstructure:"stagingPattern"
json:"stagingPattern"`
- TestingPattern string `mapstructure:"testingPattern"
json:"testingPattern"`
+ ProductionPattern string `mapstructure:"productionPattern"
json:"productionPattern"`
+ StagingPattern string `mapstructure:"stagingPattern"
json:"stagingPattern"`
+ TestingPattern string `mapstructure:"testingPattern"
json:"testingPattern"`
+ DataSoure []string `mapstructure:"dataSoure" json:"dataSoure"`
}
type DoraOptions struct {