From 472797c7bae25c8c037abf1f7dd27bb03390ae68 Mon Sep 17 00:00:00 2001 From: Lynwee <1507509064@qq.com> Date: Fri, 6 Sep 2024 15:07:40 +0800 Subject: [PATCH] feat(domain): add is_child field to table cicd_pipelines (#8006) * feat(domain): add is_child field to table cicd_pipelines * fix(test): fix e2e * fix(test): fix e2e --- .../domainlayer/devops/cicd_pipeline.go | 1 + ...20240906_add_is_child_to_cicd_pipelines.go | 52 +++++++++++++++++++ .../core/models/migrationscripts/register.go | 1 + backend/plugins/bamboo/e2e/plan_build_test.go | 5 +- backend/plugins/circleci/e2e/workflow_test.go | 2 +- backend/plugins/github/e2e/cicd_run_test.go | 5 +- .../gitlab/e2e/pipelines_detail_test.go | 5 +- 7 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 backend/core/models/migrationscripts/20240906_add_is_child_to_cicd_pipelines.go diff --git a/backend/core/models/domainlayer/devops/cicd_pipeline.go b/backend/core/models/domainlayer/devops/cicd_pipeline.go index e05d573b620..3a0a34f466a 100644 --- a/backend/core/models/domainlayer/devops/cicd_pipeline.go +++ b/backend/core/models/domainlayer/devops/cicd_pipeline.go @@ -40,6 +40,7 @@ type CICDPipeline struct { Environment string `gorm:"type:varchar(255)"` TaskDatesInfo CicdScopeId string `gorm:"index;type:varchar(255)"` + IsChild bool } func (CICDPipeline) TableName() string { diff --git a/backend/core/models/migrationscripts/20240906_add_is_child_to_cicd_pipelines.go b/backend/core/models/migrationscripts/20240906_add_is_child_to_cicd_pipelines.go new file mode 100644 index 00000000000..3cf14e8d90f --- /dev/null +++ b/backend/core/models/migrationscripts/20240906_add_is_child_to_cicd_pipelines.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" +) + +var _ plugin.MigrationScript = (*addIsChildToCicdPipeline)(nil) + +type cicdPipeline20240906 struct { + IsChild bool +} + +func (cicdPipeline20240906) TableName() string { + return "cicd_pipelines" +} + +type addIsChildToCicdPipeline struct{} + +func (*addIsChildToCicdPipeline) Up(basicRes context.BasicRes) errors.Error { + db := basicRes.GetDal() + if err := db.AutoMigrate(&cicdPipeline20240906{}); err != nil { + return err + } + return nil +} + +func (*addIsChildToCicdPipeline) Version() uint64 { + return 20240906120000 +} + +func (*addIsChildToCicdPipeline) Name() string { + return "add is_child to cicd_pipelines" +} diff --git a/backend/core/models/migrationscripts/register.go b/backend/core/models/migrationscripts/register.go index 1a220e496e5..3a5bb5ec486 100644 --- a/backend/core/models/migrationscripts/register.go +++ b/backend/core/models/migrationscripts/register.go @@ -132,5 +132,6 @@ func All() []plugin.MigrationScript { new(addTableScopeIdToIncident), new(addAssigneeToIncident), new(addIsSubtaskToIssue), + new(addIsChildToCicdPipeline), } } diff --git a/backend/plugins/bamboo/e2e/plan_build_test.go b/backend/plugins/bamboo/e2e/plan_build_test.go index 7c3ea69eca7..67584f8f166 100644 --- a/backend/plugins/bamboo/e2e/plan_build_test.go +++ b/backend/plugins/bamboo/e2e/plan_build_test.go @@ -107,7 +107,8 @@ func TestBambooPlanBuildDataFlow(t *testing.T) { dataflowTester.Subtask(tasks.ConvertPlanBuildsMeta, taskData) dataflowTester.VerifyTableWithOptions(&devops.CICDPipeline{}, e2ehelper.TableOptions{ - CSVRelPath: "./snapshot_tables/cicd_pipelines.csv", - IgnoreTypes: []interface{}{common.NoPKModel{}}, + CSVRelPath: "./snapshot_tables/cicd_pipelines.csv", + IgnoreTypes: []interface{}{common.NoPKModel{}}, + IgnoreFields: []string{"is_child"}, }) } diff --git a/backend/plugins/circleci/e2e/workflow_test.go b/backend/plugins/circleci/e2e/workflow_test.go index e4418f2e34b..cc542fdb27f 100644 --- a/backend/plugins/circleci/e2e/workflow_test.go +++ b/backend/plugins/circleci/e2e/workflow_test.go @@ -72,7 +72,7 @@ func TestCircleciWorkflow(t *testing.T) { devops.CICDPipeline{}, e2ehelper.TableOptions{ CSVRelPath: "./snapshot_tables/cicd_pipelines.csv", - IgnoreFields: []string{"finished_date", "created_date"}, + IgnoreFields: []string{"finished_date", "created_date", "is_child"}, IgnoreTypes: []interface{}{domainlayer.DomainEntity{}}, }, ) diff --git a/backend/plugins/github/e2e/cicd_run_test.go b/backend/plugins/github/e2e/cicd_run_test.go index 0d7d01df66e..750b22e5eab 100644 --- a/backend/plugins/github/e2e/cicd_run_test.go +++ b/backend/plugins/github/e2e/cicd_run_test.go @@ -70,8 +70,9 @@ func TestGithubCICDRunDataFlow(t *testing.T) { dataflowTester.FlushTabler(&devops.CiCDPipelineCommit{}) dataflowTester.Subtask(tasks.ConvertRunsMeta, taskData) dataflowTester.VerifyTableWithOptions(&devops.CICDPipeline{}, e2ehelper.TableOptions{ - CSVRelPath: "./snapshot_tables/cicd_pipelines.csv", - IgnoreTypes: []interface{}{common.NoPKModel{}}, + CSVRelPath: "./snapshot_tables/cicd_pipelines.csv", + IgnoreTypes: []interface{}{common.NoPKModel{}}, + IgnoreFields: []string{"is_child"}, }) dataflowTester.VerifyTableWithOptions(&devops.CiCDPipelineCommit{}, e2ehelper.TableOptions{ diff --git a/backend/plugins/gitlab/e2e/pipelines_detail_test.go b/backend/plugins/gitlab/e2e/pipelines_detail_test.go index 33c8b2862c9..ea1c3dc2c93 100644 --- a/backend/plugins/gitlab/e2e/pipelines_detail_test.go +++ b/backend/plugins/gitlab/e2e/pipelines_detail_test.go @@ -84,8 +84,9 @@ func TestGitlabPipelineDetailDataFlow(t *testing.T) { dataflowTester.Subtask(tasks.ConvertDetailPipelineMeta, taskData) dataflowTester.Subtask(tasks.ConvertPipelineCommitMeta, taskData) dataflowTester.VerifyTableWithOptions(&devops.CICDPipeline{}, e2ehelper.TableOptions{ - CSVRelPath: "./snapshot_tables/cicd_pipelines.csv", - IgnoreTypes: []interface{}{common.NoPKModel{}}, + CSVRelPath: "./snapshot_tables/cicd_pipelines.csv", + IgnoreTypes: []interface{}{common.NoPKModel{}}, + IgnoreFields: []string{"is_child"}, }) dataflowTester.VerifyTableWithOptions(&devops.CiCDPipelineCommit{}, e2ehelper.TableOptions{