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

zhangliang2022 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 cdbd54b2 feat: add cicd commits for bitbucket (#3440)
cdbd54b2 is described below

commit cdbd54b2e58632ebc567b878a9f346fb9fc8e373
Author: tsoc <[email protected]>
AuthorDate: Fri Oct 14 13:08:24 2022 +0800

    feat: add cicd commits for bitbucket (#3440)
    
    * feat: add bitbucket cicd commits
    
    * fix: add apache license header
---
 ...4_add_RepoId_CommitSha_field_pipeline_tables.go | 68 ++++++++++++++++++++++
 .../bitbucket/models/migrationscripts/register.go  |  1 +
 plugins/bitbucket/models/pipeline.go               |  2 +
 plugins/bitbucket/tasks/pipeline_convertor.go      | 16 +++--
 plugins/bitbucket/tasks/pipeline_extractor.go      |  4 +-
 5 files changed, 85 insertions(+), 6 deletions(-)

diff --git 
a/plugins/bitbucket/models/migrationscripts/20221014_add_RepoId_CommitSha_field_pipeline_tables.go
 
b/plugins/bitbucket/models/migrationscripts/20221014_add_RepoId_CommitSha_field_pipeline_tables.go
new file mode 100644
index 00000000..9d520fb1
--- /dev/null
+++ 
b/plugins/bitbucket/models/migrationscripts/20221014_add_RepoId_CommitSha_field_pipeline_tables.go
@@ -0,0 +1,68 @@
+/*
+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 (
+       "context"
+       "time"
+
+       "github.com/apache/incubator-devlake/errors"
+       "github.com/apache/incubator-devlake/models/migrationscripts/archived"
+       "gorm.io/gorm"
+)
+
+type Task20221014 struct {
+       ConnectionId        uint64 `gorm:"primaryKey"`
+       BitbucketId         string `gorm:"primaryKey"`
+       Status              string `gorm:"type:varchar(100)"`
+       Result              string `gorm:"type:varchar(100)"`
+       RefName             string `gorm:"type:varchar(255)"`
+       RepoId              string `gorm:"type:varchar(255)"`
+       CommitSha           string `gorm:"type:varchar(255)"`
+       WebUrl              string `gorm:"type:varchar(255)"`
+       DurationInSeconds   uint64
+       BitbucketCreatedOn  *time.Time
+       BitbucketCompleteOn *time.Time
+       archived.NoPKModel
+}
+
+func (Task20221014) TableName() string {
+       return "_tool_bitbucket_pipelines"
+}
+
+type addRepoIdAndCommitShaField struct{}
+
+func (*addRepoIdAndCommitShaField) Up(ctx context.Context, db *gorm.DB) 
errors.Error {
+       err := db.Migrator().AddColumn(Task20221014{}, "repo_id")
+       if err != nil {
+               return errors.Convert(err)
+       }
+       err = db.Migrator().AddColumn(Task20221014{}, "commit_sha")
+       if err != nil {
+               return errors.Convert(err)
+       }
+       return nil
+}
+
+func (*addRepoIdAndCommitShaField) Version() uint64 {
+       return 20221014114623
+}
+
+func (*addRepoIdAndCommitShaField) Name() string {
+       return "add column `repo_id` and `commit_sha` at 
_tool_bitbucket_pipelines"
+}
diff --git a/plugins/bitbucket/models/migrationscripts/register.go 
b/plugins/bitbucket/models/migrationscripts/register.go
index 1fac9090..758a4e73 100644
--- a/plugins/bitbucket/models/migrationscripts/register.go
+++ b/plugins/bitbucket/models/migrationscripts/register.go
@@ -27,5 +27,6 @@ func All() []migration.Script {
                new(addInitTables),
                new(addPipeline20220914),
                new(addDeployment20221013),
+               new(addRepoIdAndCommitShaField),
        }
 }
diff --git a/plugins/bitbucket/models/pipeline.go 
b/plugins/bitbucket/models/pipeline.go
index ce48ec6c..eb1c6c29 100644
--- a/plugins/bitbucket/models/pipeline.go
+++ b/plugins/bitbucket/models/pipeline.go
@@ -28,6 +28,8 @@ type BitbucketPipeline struct {
        Status            string `gorm:"type:varchar(100)"`
        Result            string `gorm:"type:varchar(100)"`
        RefName           string `gorm:"type:varchar(255)"`
+       RepoId            string `gorm:"type:varchar(255)"`
+       CommitSha         string `gorm:"type:varchar(255)"`
        WebUrl            string `gorm:"type:varchar(255)"`
        DurationInSeconds uint64
 
diff --git a/plugins/bitbucket/tasks/pipeline_convertor.go 
b/plugins/bitbucket/tasks/pipeline_convertor.go
index 7e75d7ad..68c9f3c6 100644
--- a/plugins/bitbucket/tasks/pipeline_convertor.go
+++ b/plugins/bitbucket/tasks/pipeline_convertor.go
@@ -70,7 +70,15 @@ func ConvertPipelines(taskCtx core.SubTaskContext) 
errors.Error {
                        if bitbucketPipeline.BitbucketCreatedOn != nil {
                                createdAt = 
*bitbucketPipeline.BitbucketCreatedOn
                        }
-
+                       results := make([]interface{}, 0, 2)
+                       domainPipelineCommit := &devops.CiCDPipelineCommit{
+                               PipelineId: 
pipelineIdGen.Generate(data.Options.ConnectionId, 
bitbucketPipeline.BitbucketId),
+                               RepoId: 
didgen.NewDomainIdGenerator(&bitbucketModels.BitbucketRepo{}).
+                                       
Generate(bitbucketPipeline.ConnectionId, bitbucketPipeline.RepoId),
+                               CommitSha: bitbucketPipeline.CommitSha,
+                               Branch:    bitbucketPipeline.RefName,
+                               RepoUrl:   bitbucketPipeline.WebUrl,
+                       }
                        domainPipeline := &devops.CICDPipeline{
                                DomainEntity: domainlayer.DomainEntity{
                                        Id: 
pipelineIdGen.Generate(data.Options.ConnectionId, 
bitbucketPipeline.BitbucketId),
@@ -93,10 +101,8 @@ func ConvertPipelines(taskCtx core.SubTaskContext) 
errors.Error {
                                DurationSec:  
bitbucketPipeline.DurationInSeconds,
                                FinishedDate: 
bitbucketPipeline.BitbucketCompleteOn,
                        }
-
-                       return []interface{}{
-                               domainPipeline,
-                       }, nil
+                       results = append(results, domainPipelineCommit, 
domainPipeline)
+                       return results, nil
                },
        })
 
diff --git a/plugins/bitbucket/tasks/pipeline_extractor.go 
b/plugins/bitbucket/tasks/pipeline_extractor.go
index 26ce73d6..8cb12f6b 100644
--- a/plugins/bitbucket/tasks/pipeline_extractor.go
+++ b/plugins/bitbucket/tasks/pipeline_extractor.go
@@ -114,9 +114,11 @@ func ExtractApiPipelines(taskCtx core.SubTaskContext) 
errors.Error {
                        bitbucketPipeline := &models.BitbucketPipeline{
                                ConnectionId:        data.Options.ConnectionId,
                                BitbucketId:         bitbucketApiPipeline.Uuid,
-                               WebUrl:              
bitbucketApiPipeline.Links.Self.Href,
+                               WebUrl:              
bitbucketApiPipeline.Target.Commit.Links.Html.Href,
                                Status:              
bitbucketApiPipeline.State.Name,
                                RefName:             
bitbucketApiPipeline.Target.RefName,
+                               CommitSha:           
bitbucketApiPipeline.Target.Commit.Hash,
+                               RepoId:              
bitbucketApiPipeline.Repo.FullName,
                                DurationInSeconds:   
bitbucketApiPipeline.DurationInSeconds,
                                BitbucketCreatedOn:  
bitbucketApiPipeline.CreatedOn,
                                BitbucketCompleteOn: 
bitbucketApiPipeline.CompletedOn,

Reply via email to