This is an automated email from the ASF dual-hosted git repository.

abeizn 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 d7c0a2017 fix(bitbucket): add build number to pipeline's name (#6330)
d7c0a2017 is described below

commit d7c0a20177dbe878cd146e34ae7bb9cc7553f3d8
Author: Lynwee <[email protected]>
AuthorDate: Wed Oct 25 21:06:46 2023 +0800

    fix(bitbucket): add build number to pipeline's name (#6330)
    
    * fix(bitbucket): add build number to pipeline's name
    
    * fix(bitbucket): fix e2e test
---
 .../e2e/snapshot_tables/cicd_pipelines.csv         | 20 +++++-----
 ...o => 20231025_add_build_number_to_pipelines.go} | 44 ++++++++++++----------
 .../bitbucket/models/migrationscripts/register.go  |  1 +
 backend/plugins/bitbucket/models/pipeline.go       |  1 +
 .../plugins/bitbucket/tasks/pipeline_collector.go  |  2 +-
 .../plugins/bitbucket/tasks/pipeline_convertor.go  |  2 +-
 .../plugins/bitbucket/tasks/pipeline_extractor.go  |  2 +
 7 files changed, 41 insertions(+), 31 deletions(-)

diff --git a/backend/plugins/bitbucket/e2e/snapshot_tables/cicd_pipelines.csv 
b/backend/plugins/bitbucket/e2e/snapshot_tables/cicd_pipelines.csv
index 7f9578744..a590150bf 100644
--- a/backend/plugins/bitbucket/e2e/snapshot_tables/cicd_pipelines.csv
+++ b/backend/plugins/bitbucket/e2e/snapshot_tables/cicd_pipelines.csv
@@ -1,11 +1,11 @@
 id,name,result,status,type,duration_sec,environment
-bitbucket:BitbucketPipeline:1:{01fad871-cd21-4a80-bd59-74148dd5be8e},bitbucket:BitbucketPipeline:1:{01fad871-cd21-4a80-bd59-74148dd5be8e}/{01fad871-cd21-4a80-bd59-74148dd5be8e},FAILURE,COMPLETED,DEPLOYMENT,14,
-bitbucket:BitbucketPipeline:1:{02c4dfe8-70a6-442c-8bd8-19061979c2cf},bitbucket:BitbucketPipeline:1:{02c4dfe8-70a6-442c-8bd8-19061979c2cf}/{02c4dfe8-70a6-442c-8bd8-19061979c2cf},MANUAL,IN_PROGRESS,,0,
-bitbucket:BitbucketPipeline:1:{1e20072e-b22a-443f-ad92-3d9435393d5b},bitbucket:BitbucketPipeline:1:{1e20072e-b22a-443f-ad92-3d9435393d5b}/{1e20072e-b22a-443f-ad92-3d9435393d5b},SUCCESS,COMPLETED,,21,
-bitbucket:BitbucketPipeline:1:{2d91d69f-d84b-423d-ae4d-c1d3f2c27166},bitbucket:BitbucketPipeline:1:{2d91d69f-d84b-423d-ae4d-c1d3f2c27166}/{2d91d69f-d84b-423d-ae4d-c1d3f2c27166},SUCCESS,COMPLETED,DEPLOYMENT,16,
-bitbucket:BitbucketPipeline:1:{5decbbb2-f4e6-4f3a-aab0-f74c40497c51},bitbucket:BitbucketPipeline:1:{5decbbb2-f4e6-4f3a-aab0-f74c40497c51}/{5decbbb2-f4e6-4f3a-aab0-f74c40497c51},SUCCESS,COMPLETED,,15,
-bitbucket:BitbucketPipeline:1:{5fb099c8-ebdd-4d3e-97d8-a12ebfca5446},bitbucket:BitbucketPipeline:1:{5fb099c8-ebdd-4d3e-97d8-a12ebfca5446}/{5fb099c8-ebdd-4d3e-97d8-a12ebfca5446},MANUAL,IN_PROGRESS,,0,
-bitbucket:BitbucketPipeline:1:{8b417a17-72e6-4e16-ae4a-97f6e279f68e},bitbucket:BitbucketPipeline:1:{8b417a17-72e6-4e16-ae4a-97f6e279f68e}/{8b417a17-72e6-4e16-ae4a-97f6e279f68e},MANUAL,IN_PROGRESS,,0,
-bitbucket:BitbucketPipeline:1:{b5d2ab02-2013-415e-b146-61ff3bf19502},bitbucket:BitbucketPipeline:1:{b5d2ab02-2013-415e-b146-61ff3bf19502}/{b5d2ab02-2013-415e-b146-61ff3bf19502},ABORT,COMPLETED,,0,PRODUCTION
-bitbucket:BitbucketPipeline:1:{d7bf8394-6e18-42c4-b3a3-70514fc4079f},bitbucket:BitbucketPipeline:1:{d7bf8394-6e18-42c4-b3a3-70514fc4079f}/{d7bf8394-6e18-42c4-b3a3-70514fc4079f},SUCCESS,COMPLETED,,18,PRODUCTION
-bitbucket:BitbucketPipeline:1:{ee91b6d3-7736-482c-892f-ad1e923d145e},bitbucket:BitbucketPipeline:1:{ee91b6d3-7736-482c-892f-ad1e923d145e}/{ee91b6d3-7736-482c-892f-ad1e923d145e},FAILURE,COMPLETED,,0,
+bitbucket:BitbucketPipeline:1:{01fad871-cd21-4a80-bd59-74148dd5be8e},bitbucket:BitbucketPipeline:1:{01fad871-cd21-4a80-bd59-74148dd5be8e}/0,FAILURE,COMPLETED,DEPLOYMENT,14,
+bitbucket:BitbucketPipeline:1:{02c4dfe8-70a6-442c-8bd8-19061979c2cf},bitbucket:BitbucketPipeline:1:{02c4dfe8-70a6-442c-8bd8-19061979c2cf}/0,MANUAL,IN_PROGRESS,,0,
+bitbucket:BitbucketPipeline:1:{1e20072e-b22a-443f-ad92-3d9435393d5b},bitbucket:BitbucketPipeline:1:{1e20072e-b22a-443f-ad92-3d9435393d5b}/0,SUCCESS,COMPLETED,,21,
+bitbucket:BitbucketPipeline:1:{2d91d69f-d84b-423d-ae4d-c1d3f2c27166},bitbucket:BitbucketPipeline:1:{2d91d69f-d84b-423d-ae4d-c1d3f2c27166}/0,SUCCESS,COMPLETED,DEPLOYMENT,16,
+bitbucket:BitbucketPipeline:1:{5decbbb2-f4e6-4f3a-aab0-f74c40497c51},bitbucket:BitbucketPipeline:1:{5decbbb2-f4e6-4f3a-aab0-f74c40497c51}/0,SUCCESS,COMPLETED,,15,
+bitbucket:BitbucketPipeline:1:{5fb099c8-ebdd-4d3e-97d8-a12ebfca5446},bitbucket:BitbucketPipeline:1:{5fb099c8-ebdd-4d3e-97d8-a12ebfca5446}/0,MANUAL,IN_PROGRESS,,0,
+bitbucket:BitbucketPipeline:1:{8b417a17-72e6-4e16-ae4a-97f6e279f68e},bitbucket:BitbucketPipeline:1:{8b417a17-72e6-4e16-ae4a-97f6e279f68e}/0,MANUAL,IN_PROGRESS,,0,
+bitbucket:BitbucketPipeline:1:{b5d2ab02-2013-415e-b146-61ff3bf19502},bitbucket:BitbucketPipeline:1:{b5d2ab02-2013-415e-b146-61ff3bf19502}/0,ABORT,COMPLETED,,0,PRODUCTION
+bitbucket:BitbucketPipeline:1:{d7bf8394-6e18-42c4-b3a3-70514fc4079f},bitbucket:BitbucketPipeline:1:{d7bf8394-6e18-42c4-b3a3-70514fc4079f}/0,SUCCESS,COMPLETED,,18,PRODUCTION
+bitbucket:BitbucketPipeline:1:{ee91b6d3-7736-482c-892f-ad1e923d145e},bitbucket:BitbucketPipeline:1:{ee91b6d3-7736-482c-892f-ad1e923d145e}/0,FAILURE,COMPLETED,,0,
diff --git a/backend/plugins/bitbucket/models/migrationscripts/register.go 
b/backend/plugins/bitbucket/models/migrationscripts/20231025_add_build_number_to_pipelines.go
similarity index 51%
copy from backend/plugins/bitbucket/models/migrationscripts/register.go
copy to 
backend/plugins/bitbucket/models/migrationscripts/20231025_add_build_number_to_pipelines.go
index f7d84de0a..e6447b668 100644
--- a/backend/plugins/bitbucket/models/migrationscripts/register.go
+++ 
b/backend/plugins/bitbucket/models/migrationscripts/20231025_add_build_number_to_pipelines.go
@@ -18,25 +18,31 @@ limitations under the License.
 package migrationscripts
 
 import (
-       plugin "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/plugin"
 )
 
-// All return all the migration scripts
-func All() []plugin.MigrationScript {
-       return []plugin.MigrationScript{
-               new(addInitTables20220803),
-               new(addPipeline20220914),
-               new(addPrCommits20221008),
-               new(addDeployment20221013),
-               new(addRepoIdAndCommitShaField20221014),
-               new(addScope20230206),
-               new(addPipelineStep20230215),
-               new(addConnectionIdToTransformationRule),
-               new(addTypeEnvToPipelineAndStep),
-               new(addRepoIdField20230411),
-               new(addRepoIdToPr),
-               new(addBitbucketCommitAuthorInfo),
-               new(renameTr2ScopeConfig),
-               new(addRawParamTableForScope),
-       }
+var _ plugin.MigrationScript = (*addBuildNumberToPipelines)(nil)
+
+type pipeline20231025 struct {
+       BuildNumber int
+}
+
+func (pipeline20231025) TableName() string {
+       return "_tool_bitbucket_pipelines"
+}
+
+type addBuildNumberToPipelines struct{}
+
+func (script *addBuildNumberToPipelines) Up(basicRes context.BasicRes) 
errors.Error {
+       return basicRes.GetDal().AutoMigrate(&pipeline20231025{})
+}
+
+func (*addBuildNumberToPipelines) Version() uint64 {
+       return 20231025170900
+}
+
+func (script *addBuildNumberToPipelines) Name() string {
+       return "add build_number field to table _tool_bitbucket_pipelines"
 }
diff --git a/backend/plugins/bitbucket/models/migrationscripts/register.go 
b/backend/plugins/bitbucket/models/migrationscripts/register.go
index f7d84de0a..22c7aa7fc 100644
--- a/backend/plugins/bitbucket/models/migrationscripts/register.go
+++ b/backend/plugins/bitbucket/models/migrationscripts/register.go
@@ -38,5 +38,6 @@ func All() []plugin.MigrationScript {
                new(addBitbucketCommitAuthorInfo),
                new(renameTr2ScopeConfig),
                new(addRawParamTableForScope),
+               new(addBuildNumberToPipelines),
        }
 }
diff --git a/backend/plugins/bitbucket/models/pipeline.go 
b/backend/plugins/bitbucket/models/pipeline.go
index a8f63c67a..fbd4a25bb 100644
--- a/backend/plugins/bitbucket/models/pipeline.go
+++ b/backend/plugins/bitbucket/models/pipeline.go
@@ -34,6 +34,7 @@ type BitbucketPipeline struct {
        WebUrl            string `gorm:"type:varchar(255)"`
        Type              string `gorm:"type:varchar(255)"`
        Environment       string `gorm:"type:varchar(255)"`
+       BuildNumber       int
        DurationInSeconds uint64
 
        BitbucketCreatedOn  *time.Time
diff --git a/backend/plugins/bitbucket/tasks/pipeline_collector.go 
b/backend/plugins/bitbucket/tasks/pipeline_collector.go
index d11a7f243..8998add3c 100644
--- a/backend/plugins/bitbucket/tasks/pipeline_collector.go
+++ b/backend/plugins/bitbucket/tasks/pipeline_collector.go
@@ -47,7 +47,7 @@ func CollectApiPipelines(taskCtx plugin.SubTaskContext) 
errors.Error {
                Query: GetQueryCreatedAndUpdated(
                        
`values.uuid,values.type,values.state.name,values.state.result.name,values.state.result.type,values.state.stage.name,values.state.stage.type,`+
                                
`values.target.ref_name,values.target.commit.hash,`+
-                               
`values.created_on,values.completed_on,values.duration_in_seconds,values.links.self,`+
+                               
`values.created_on,values.completed_on,values.duration_in_seconds,values.build_number,values.links.self,`+
                                `page,pagelen,size`,
                        collectorWithState),
                ResponseParser: GetRawMessageFromResponse,
diff --git a/backend/plugins/bitbucket/tasks/pipeline_convertor.go 
b/backend/plugins/bitbucket/tasks/pipeline_convertor.go
index d8dddcbc5..860c9ca6c 100644
--- a/backend/plugins/bitbucket/tasks/pipeline_convertor.go
+++ b/backend/plugins/bitbucket/tasks/pipeline_convertor.go
@@ -86,7 +86,7 @@ func ConvertPipelines(taskCtx plugin.SubTaskContext) 
errors.Error {
                                DomainEntity: domainlayer.DomainEntity{
                                        Id: domainEntityId,
                                },
-                               Name: fmt.Sprintf("%s/%s", domainEntityId, 
bitbucketPipeline.BitbucketId),
+                               Name: fmt.Sprintf("%s/%d", domainEntityId, 
bitbucketPipeline.BuildNumber),
                                Result: devops.GetResult(&devops.ResultRule{
                                        Failed:  []string{models.FAILED, 
models.ERROR},
                                        Abort:   []string{models.STOPPED},
diff --git a/backend/plugins/bitbucket/tasks/pipeline_extractor.go 
b/backend/plugins/bitbucket/tasks/pipeline_extractor.go
index d3bbb03a9..34322f15c 100644
--- a/backend/plugins/bitbucket/tasks/pipeline_extractor.go
+++ b/backend/plugins/bitbucket/tasks/pipeline_extractor.go
@@ -60,6 +60,7 @@ type BitbucketApiPipeline struct {
        } `json:"state"`
        Target            *bitbucketApiPipelineTarget `json:"target"`
        CreatedOn         *common.Iso8601Time         `json:"created_on"`
+       BuildNumber       int                         `json:"build_number"`
        CompletedOn       *common.Iso8601Time         `json:"completed_on"`
        DurationInSeconds uint64                      
`json:"duration_in_seconds"`
        Links             struct {
@@ -98,6 +99,7 @@ func ExtractApiPipelines(taskCtx plugin.SubTaskContext) 
errors.Error {
                                RefName:             
bitbucketApiPipeline.Target.RefName,
                                CommitSha:           
bitbucketApiPipeline.Target.Commit.Hash,
                                RepoId:              data.Options.FullName,
+                               BuildNumber:         
bitbucketApiPipeline.BuildNumber,
                                DurationInSeconds:   
bitbucketApiPipeline.DurationInSeconds,
                                BitbucketCreatedOn:  
common.Iso8601TimeToTime(bitbucketApiPipeline.CreatedOn),
                                BitbucketCompleteOn: 
common.Iso8601TimeToTime(bitbucketApiPipeline.CompletedOn),

Reply via email to