diff --git a/backend/core/models/domainlayer/devops/cicd_task.go b/backend/core/models/domainlayer/devops/cicd_task.go index 86847c1464e..6c925355fb3 100644 --- a/backend/core/models/domainlayer/devops/cicd_task.go +++ b/backend/core/models/domainlayer/devops/cicd_task.go @@ -35,6 +35,8 @@ const ( TESTING = "TESTING" ) +const ENV_NAME_PATTERN = "ENV_NAME_PATTERN" + type CICDTask struct { domainlayer.DomainEntity Name string `gorm:"type:varchar(255)"` diff --git a/backend/plugins/bamboo/impl/impl.go b/backend/plugins/bamboo/impl/impl.go index a5e16d592a3..05965c4569b 100644 --- a/backend/plugins/bamboo/impl/impl.go +++ b/backend/plugins/bamboo/impl/impl.go @@ -182,7 +182,7 @@ func (p Bamboo) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]i if err := regexEnricher.TryAdd(devops.PRODUCTION, op.ProductionPattern); err != nil { return nil, errors.BadInput.Wrap(err, "invalid value for `productionPattern`") } - if err := regexEnricher.TryAdd(models.ENV_NAME_PATTERN, op.EnvNamePattern); err != nil { + if err := regexEnricher.TryAdd(devops.ENV_NAME_PATTERN, op.EnvNamePattern); err != nil { return nil, errors.BadInput.Wrap(err, "invalid value for `envNamePattern`") } return &tasks.BambooTaskData{ diff --git a/backend/plugins/bamboo/models/migrationscripts/20230807_add_plan_result_key.go b/backend/plugins/bamboo/models/migrationscripts/20230807_add_plan_result_key.go index e2c3241fe17..545c39dd9fc 100644 --- a/backend/plugins/bamboo/models/migrationscripts/20230807_add_plan_result_key.go +++ b/backend/plugins/bamboo/models/migrationscripts/20230807_add_plan_result_key.go @@ -24,7 +24,7 @@ import ( "github.com/apache/incubator-devlake/helpers/migrationhelper" ) -var _ plugin.MigrationScript = (*addEnvNamePattern)(nil) +var _ plugin.MigrationScript = (*addPlanResultKey)(nil) type deployBuild20220807 struct { PlanResultKey string `gorm:"primaryKey"` diff --git a/backend/plugins/bamboo/models/scope_config.go b/backend/plugins/bamboo/models/scope_config.go index 35c816a4461..abbb008fb70 100644 --- a/backend/plugins/bamboo/models/scope_config.go +++ b/backend/plugins/bamboo/models/scope_config.go @@ -21,8 +21,6 @@ import ( "github.com/apache/incubator-devlake/core/models/common" ) -const ENV_NAME_PATTERN = "ENV_NAME_PATTERN" - type BambooScopeConfig struct { common.ScopeConfig `mapstructure:",squash" json:",inline" gorm:"embedded"` ConnectionId uint64 `mapstructure:"connectionId" json:"connectionId"` diff --git a/backend/plugins/bamboo/tasks/deploy_build_convertor.go b/backend/plugins/bamboo/tasks/deploy_build_convertor.go index 052c197e37e..cad5c5b2fc1 100644 --- a/backend/plugins/bamboo/tasks/deploy_build_convertor.go +++ b/backend/plugins/bamboo/tasks/deploy_build_convertor.go @@ -115,7 +115,7 @@ func ConvertDeployBuilds(taskCtx plugin.SubTaskContext) errors.Error { if input.QueuedDate != nil { deploymentCommit.CreatedDate = *input.QueuedDate } - if data.RegexEnricher.ReturnNameIfMatched(models.ENV_NAME_PATTERN, input.Environment) != "" { + if data.RegexEnricher.ReturnNameIfMatched(devops.ENV_NAME_PATTERN, input.Environment) != "" { deploymentCommit.Environment = devops.PRODUCTION } if input.FinishedDate != nil && input.StartedDate != nil { diff --git a/backend/plugins/github/impl/impl.go b/backend/plugins/github/impl/impl.go index 77ac52f1dcd..51ed55dcdd4 100644 --- a/backend/plugins/github/impl/impl.go +++ b/backend/plugins/github/impl/impl.go @@ -152,6 +152,9 @@ func (p Github) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]i 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`") + } taskData := &tasks.GithubTaskData{ Options: op, diff --git a/backend/plugins/github/models/migrationscripts/20231026_add_env_name_pattern_to_tool_github_scope_configs.go b/backend/plugins/github/models/migrationscripts/20231026_add_env_name_pattern_to_tool_github_scope_configs.go new file mode 100644 index 00000000000..43bc2efc828 --- /dev/null +++ b/backend/plugins/github/models/migrationscripts/20231026_add_env_name_pattern_to_tool_github_scope_configs.go @@ -0,0 +1,52 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package migrationscripts + +import ( + "github.com/apache/incubator-devlake/core/context" + "github.com/apache/incubator-devlake/core/errors" + "github.com/apache/incubator-devlake/core/plugin" + "github.com/apache/incubator-devlake/helpers/migrationhelper" +) + +var _ plugin.MigrationScript = (*addEnvNamePattern)(nil) + +type scopeConfig20231026 struct { + EnvNamePattern string `mapstructure:"envNamePattern,omitempty" json:"envNamePattern" gorm:"type:varchar(255)"` +} + +func (scopeConfig20231026) TableName() string { + return "_tool_github_scope_configs" +} + +type addEnvNamePattern struct{} + +func (script *addEnvNamePattern) Up(basicRes context.BasicRes) errors.Error { + return migrationhelper.AutoMigrateTables( + basicRes, + &scopeConfig20231026{}, + ) +} + +func (*addEnvNamePattern) Version() uint64 { + return 20231026094400 +} + +func (script *addEnvNamePattern) Name() string { + return "add env_name_pattern to _tool_github_scope_configs" +} diff --git a/backend/plugins/github/models/migrationscripts/register.go b/backend/plugins/github/models/migrationscripts/register.go index c101043bd43..deac0d93dc7 100644 --- a/backend/plugins/github/models/migrationscripts/register.go +++ b/backend/plugins/github/models/migrationscripts/register.go @@ -45,5 +45,6 @@ func All() []plugin.MigrationScript { new(addRawParamTableForScope), new(addDeploymentTable), new(modifyGithubMilestone), + new(addEnvNamePattern), } } diff --git a/backend/plugins/github/models/scope_config.go b/backend/plugins/github/models/scope_config.go index 625b094e1af..16e1ad8759a 100644 --- a/backend/plugins/github/models/scope_config.go +++ b/backend/plugins/github/models/scope_config.go @@ -39,6 +39,7 @@ type GithubScopeConfig struct { 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)"` + EnvNamePattern string `mapstructure:"envNamePattern,omitempty" json:"envNamePattern" gorm:"type:varchar(255)"` Refdiff datatypes.JSONMap `mapstructure:"refdiff,omitempty" json:"refdiff" swaggertype:"object" format:"json"` } diff --git a/backend/plugins/github_graphql/impl/impl.go b/backend/plugins/github_graphql/impl/impl.go index a1c46d626c1..0b1fef529c2 100644 --- a/backend/plugins/github_graphql/impl/impl.go +++ b/backend/plugins/github_graphql/impl/impl.go @@ -231,6 +231,9 @@ func (p GithubGraphql) PrepareTaskData(taskCtx plugin.TaskContext, options map[s 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`") + } taskData := &githubTasks.GithubTaskData{ Options: &op, diff --git a/backend/plugins/github_graphql/tasks/deployment_convertor.go b/backend/plugins/github_graphql/tasks/deployment_convertor.go index fbfd33277ed..118f20ce81b 100644 --- a/backend/plugins/github_graphql/tasks/deployment_convertor.go +++ b/backend/plugins/github_graphql/tasks/deployment_convertor.go @@ -96,7 +96,9 @@ func ConvertDeployment(taskCtx plugin.SubTaskContext) errors.Error { deploymentCommit.DurationSec = &durationSec if data.RegexEnricher != nil { - deploymentCommit.Environment = data.RegexEnricher.ReturnNameIfMatched(devops.PRODUCTION, githubDeployment.Environment) + if data.RegexEnricher.ReturnNameIfMatched(devops.ENV_NAME_PATTERN, githubDeployment.Environment) != "" { + deploymentCommit.Environment = devops.PRODUCTION + } } deploymentCommit.CicdDeploymentId = deploymentCommit.Id