Skip to content

Commit

Permalink
fix(github): add envNamePattern (apache#6340)
Browse files Browse the repository at this point in the history
  • Loading branch information
d4x1 committed Oct 26, 2023
1 parent 03ea25c commit ca43963
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 6 deletions.
2 changes: 2 additions & 0 deletions backend/core/models/domainlayer/devops/cicd_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"`
Expand Down
2 changes: 1 addition & 1 deletion backend/plugins/bamboo/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 0 additions & 2 deletions backend/plugins/bamboo/models/scope_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion backend/plugins/bamboo/tasks/deploy_build_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions backend/plugins/github/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions backend/plugins/github/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ func All() []plugin.MigrationScript {
new(addRawParamTableForScope),
new(addDeploymentTable),
new(modifyGithubMilestone),
new(addEnvNamePattern),
}
}
1 change: 1 addition & 0 deletions backend/plugins/github/models/scope_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
3 changes: 3 additions & 0 deletions backend/plugins/github_graphql/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion backend/plugins/github_graphql/tasks/deployment_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ca43963

Please sign in to comment.