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 8f203bcc5459770001415f518c31a74370671eb1 Author: abeizn <zikuan...@merico.dev> AuthorDate: Wed Sep 18 11:41:27 2024 +0800 fix: update github trans-to-deployment scope config to pointer (#8060) --- backend/plugins/github/impl/impl.go | 12 ++++++++---- backend/plugins/github/models/scope_config.go | 4 ++-- backend/plugins/github/tasks/cicd_job_extractor.go | 7 +++++-- backend/plugins/github/tasks/cicd_run_extractor.go | 6 ++++-- backend/plugins/github_graphql/impl/impl.go | 15 ++++++++++----- backend/plugins/github_graphql/tasks/job_extractor.go | 6 ++++-- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/backend/plugins/github/impl/impl.go b/backend/plugins/github/impl/impl.go index 1c09a7afe..52a772cf6 100644 --- a/backend/plugins/github/impl/impl.go +++ b/backend/plugins/github/impl/impl.go @@ -158,11 +158,15 @@ func (p Github) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]i } regexEnricher := helper.NewRegexEnricher() - if err = regexEnricher.TryAdd(devops.DEPLOYMENT, op.ScopeConfig.DeploymentPattern); err != nil { - return nil, errors.BadInput.Wrap(err, "invalid value for `deploymentPattern`") + if op.ScopeConfig.DeploymentPattern != nil { + if err = regexEnricher.TryAdd(devops.DEPLOYMENT, *op.ScopeConfig.DeploymentPattern); err != nil { + return nil, errors.BadInput.Wrap(err, "invalid value for `deploymentPattern`") + } } - if err = regexEnricher.TryAdd(devops.PRODUCTION, op.ScopeConfig.ProductionPattern); err != nil { - return nil, errors.BadInput.Wrap(err, "invalid value for `productionPattern`") + if op.ScopeConfig.ProductionPattern != nil { + if err = regexEnricher.TryAdd(devops.PRODUCTION, *op.ScopeConfig.ProductionPattern); err != nil { + return nil, errors.BadInput.Wrap(err, "invalid value for `productionPattern`") + } } if len(op.ScopeConfig.EnvNameList) > 0 || (len(op.ScopeConfig.EnvNameList) == 0 && op.ScopeConfig.EnvNamePattern == "") { if err = regexEnricher.TryAddList(devops.ENV_NAME_PATTERN, op.ScopeConfig.EnvNameList...); err != nil { diff --git a/backend/plugins/github/models/scope_config.go b/backend/plugins/github/models/scope_config.go index e880d500e..2bd12cbc3 100644 --- a/backend/plugins/github/models/scope_config.go +++ b/backend/plugins/github/models/scope_config.go @@ -36,8 +36,8 @@ type GithubScopeConfig struct { IssueTypeBug string `mapstructure:"issueTypeBug,omitempty" json:"issueTypeBug" gorm:"type:varchar(255)"` IssueTypeIncident string `mapstructure:"issueTypeIncident,omitempty" json:"issueTypeIncident" gorm:"type:varchar(255)"` IssueTypeRequirement string `mapstructure:"issueTypeRequirement,omitempty" json:"issueTypeRequirement" gorm:"type:varchar(255)"` - DeploymentPattern string `mapstructure:"deploymentPattern,omitempty" json:"deploymentPattern" gorm:"type:varchar(255)"` - ProductionPattern string `mapstructure:"productionPattern,omitempty" json:"productionPattern" gorm:"type:varchar(255)"` + DeploymentPattern *string `mapstructure:"deploymentPattern,omitempty" json:"deploymentPattern" gorm:"type:varchar(255)"` + ProductionPattern *string `mapstructure:"productionPattern,omitempty" json:"productionPattern" gorm:"type:varchar(255)"` EnvNamePattern string `mapstructure:"envNamePattern,omitempty" json:"envNamePattern" gorm:"type:varchar(255)"` EnvNameList []string `gorm:"type:json;serializer:json" json:"envNameList" mapstructure:"envNameList"` Refdiff datatypes.JSONMap `mapstructure:"refdiff,omitempty" json:"refdiff" swaggertype:"object" format:"json"` diff --git a/backend/plugins/github/tasks/cicd_job_extractor.go b/backend/plugins/github/tasks/cicd_job_extractor.go index 5701476bc..bb57852a8 100644 --- a/backend/plugins/github/tasks/cicd_job_extractor.go +++ b/backend/plugins/github/tasks/cicd_job_extractor.go @@ -84,9 +84,12 @@ func ExtractJobs(taskCtx plugin.SubTaskContext) errors.Error { RunnerID: githubJob.RunID, RunnerName: githubJob.RunnerName, RunnerGroupID: githubJob.RunnerGroupID, - Type: data.RegexEnricher.ReturnNameIfMatched(devops.DEPLOYMENT, githubJob.Name), - Environment: data.RegexEnricher.ReturnNameIfOmittedOrMatched(devops.PRODUCTION, githubJob.Name), } + if data.Options.ScopeConfig.DeploymentPattern != nil || data.Options.ScopeConfig.ProductionPattern != nil { + githubJobResult.Type = data.RegexEnricher.ReturnNameIfMatched(devops.DEPLOYMENT, githubJob.Name) + githubJobResult.Environment = data.RegexEnricher.ReturnNameIfOmittedOrMatched(devops.PRODUCTION, githubJob.Name) + } + results = append(results, githubJobResult) return results, nil }, diff --git a/backend/plugins/github/tasks/cicd_run_extractor.go b/backend/plugins/github/tasks/cicd_run_extractor.go index 1e6a3f41a..95d7aca9a 100644 --- a/backend/plugins/github/tasks/cicd_run_extractor.go +++ b/backend/plugins/github/tasks/cicd_run_extractor.go @@ -62,8 +62,10 @@ func ExtractRuns(taskCtx plugin.SubTaskContext) errors.Error { } githubRun.RepoId = repoId githubRun.ConnectionId = data.Options.ConnectionId - githubRun.Type = data.RegexEnricher.ReturnNameIfMatched(devops.DEPLOYMENT, githubRun.Name) - githubRun.Environment = data.RegexEnricher.ReturnNameIfOmittedOrMatched(devops.PRODUCTION, githubRun.Name, githubRun.HeadBranch) + if data.Options.ScopeConfig.DeploymentPattern != nil || data.Options.ScopeConfig.ProductionPattern != nil { + githubRun.Type = data.RegexEnricher.ReturnNameIfMatched(devops.DEPLOYMENT, githubRun.Name) + githubRun.Environment = data.RegexEnricher.ReturnNameIfOmittedOrMatched(devops.PRODUCTION, githubRun.Name, githubRun.HeadBranch) + } return []interface{}{githubRun}, nil }, }) diff --git a/backend/plugins/github_graphql/impl/impl.go b/backend/plugins/github_graphql/impl/impl.go index d4953a18f..5b82c753c 100644 --- a/backend/plugins/github_graphql/impl/impl.go +++ b/backend/plugins/github_graphql/impl/impl.go @@ -20,13 +20,14 @@ package impl import ( "context" "fmt" - "github.com/apache/incubator-devlake/core/models/domainlayer/devops" "net/http" "net/url" "reflect" "strings" "time" + "github.com/apache/incubator-devlake/core/models/domainlayer/devops" + "github.com/apache/incubator-devlake/core/dal" "github.com/apache/incubator-devlake/core/errors" "github.com/apache/incubator-devlake/core/log" @@ -252,11 +253,15 @@ func (p GithubGraphql) PrepareTaskData(taskCtx plugin.TaskContext, options map[s } regexEnricher := helper.NewRegexEnricher() - if err = regexEnricher.TryAdd(devops.DEPLOYMENT, op.ScopeConfig.DeploymentPattern); err != nil { - return nil, errors.BadInput.Wrap(err, "invalid value for `deploymentPattern`") + if op.ScopeConfig.DeploymentPattern != nil { + if err = regexEnricher.TryAdd(devops.DEPLOYMENT, *op.ScopeConfig.DeploymentPattern); err != nil { + return nil, errors.BadInput.Wrap(err, "invalid value for `deploymentPattern`") + } } - if err = regexEnricher.TryAdd(devops.PRODUCTION, op.ScopeConfig.ProductionPattern); err != nil { - return nil, errors.BadInput.Wrap(err, "invalid value for `productionPattern`") + if op.ScopeConfig.ProductionPattern != nil { + if err = regexEnricher.TryAdd(devops.PRODUCTION, *op.ScopeConfig.ProductionPattern); err != nil { + return nil, errors.BadInput.Wrap(err, "invalid value for `productionPattern`") + } } if err = regexEnricher.TryAdd(devops.ENV_NAME_PATTERN, op.ScopeConfig.EnvNamePattern); err != nil { return nil, errors.BadInput.Wrap(err, "invalid value for `envNamePattern`") diff --git a/backend/plugins/github_graphql/tasks/job_extractor.go b/backend/plugins/github_graphql/tasks/job_extractor.go index 1bd035a7e..b60cb6b0e 100644 --- a/backend/plugins/github_graphql/tasks/job_extractor.go +++ b/backend/plugins/github_graphql/tasks/job_extractor.go @@ -75,8 +75,6 @@ func ExtractJobs(taskCtx plugin.SubTaskContext) errors.Error { CompletedAt: checkRun.CompletedAt, Name: checkRun.Name, Steps: paramsBytes, - Type: data.RegexEnricher.ReturnNameIfMatched(devops.DEPLOYMENT, checkRun.Name), - Environment: data.RegexEnricher.ReturnNameIfOmittedOrMatched(devops.PRODUCTION, checkRun.Name), // these columns can not fill by graphql //HeadSha: ``, // use _tool_github_runs //RunURL: ``, @@ -86,6 +84,10 @@ func ExtractJobs(taskCtx plugin.SubTaskContext) errors.Error { //RunnerName: ``, // not in use //RunnerGroupID: ``, // not in use } + if data.Options.ScopeConfig.DeploymentPattern != nil || data.Options.ScopeConfig.ProductionPattern != nil { + githubJob.Type = data.RegexEnricher.ReturnNameIfMatched(devops.DEPLOYMENT, checkRun.Name) + githubJob.Environment = data.RegexEnricher.ReturnNameIfOmittedOrMatched(devops.PRODUCTION, checkRun.Name) + } results = append(results, githubJob) } return results, nil