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

lynwee pushed a commit to branch release-v1.0
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/release-v1.0 by this push:
     new 483c93e6b feat: bitbucket add merge by field (#7756) (#7789)
483c93e6b is described below

commit 483c93e6b89aa4e54392feed5f2fa344eda874aa
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Jul 25 23:41:20 2024 +0800

    feat: bitbucket add merge by field (#7756) (#7789)
    
    * feat: bitbucket add merge by field
    
    * feat: bitbucket add merge by field
    
    Co-authored-by: abeizn <[email protected]>
---
 ...{register.go => 20240717_add_merge_by_to_pr.go} | 49 +++++++++++++---------
 .../bitbucket/models/migrationscripts/register.go  |  1 +
 backend/plugins/bitbucket/models/pr.go             |  5 ++-
 backend/plugins/bitbucket/tasks/pr_collector.go    |  1 +
 backend/plugins/bitbucket/tasks/pr_convertor.go    |  4 ++
 backend/plugins/bitbucket/tasks/pr_extractor.go    |  7 +++-
 6 files changed, 45 insertions(+), 22 deletions(-)

diff --git a/backend/plugins/bitbucket/models/migrationscripts/register.go 
b/backend/plugins/bitbucket/models/migrationscripts/20240717_add_merge_by_to_pr.go
similarity index 50%
copy from backend/plugins/bitbucket/models/migrationscripts/register.go
copy to 
backend/plugins/bitbucket/models/migrationscripts/20240717_add_merge_by_to_pr.go
index 8a5a7026e..caeb94855 100644
--- a/backend/plugins/bitbucket/models/migrationscripts/register.go
+++ 
b/backend/plugins/bitbucket/models/migrationscripts/20240717_add_merge_by_to_pr.go
@@ -18,27 +18,36 @@ 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),
-               new(addBuildNumberToPipelines),
-               new(reCreatBitBucketPipelineSteps),
+var _ plugin.MigrationScript = (*addMergedByToPr)(nil)
+
+type pr20240710 struct {
+       MergedByName string `gorm:"type:varchar(100)"`
+       MergedById   string `gorm:"type:varchar(100)"`
+}
+
+func (pr20240710) TableName() string {
+       return "_tool_bitbucket_pull_requests"
+}
+
+type addMergedByToPr struct{}
+
+func (*addMergedByToPr) Up(basicRes context.BasicRes) errors.Error {
+       db := basicRes.GetDal()
+       if err := db.AutoMigrate(&pr20240710{}); err != nil {
+               return err
        }
+       return nil
+}
+
+func (*addMergedByToPr) Version() uint64 {
+       return 20240717142100
+}
+
+func (*addMergedByToPr) Name() string {
+       return "add merged by to _tool_bitbucket_pull_requests"
 }
diff --git a/backend/plugins/bitbucket/models/migrationscripts/register.go 
b/backend/plugins/bitbucket/models/migrationscripts/register.go
index 8a5a7026e..a197be735 100644
--- a/backend/plugins/bitbucket/models/migrationscripts/register.go
+++ b/backend/plugins/bitbucket/models/migrationscripts/register.go
@@ -40,5 +40,6 @@ func All() []plugin.MigrationScript {
                new(addRawParamTableForScope),
                new(addBuildNumberToPipelines),
                new(reCreatBitBucketPipelineSteps),
+               new(addMergedByToPr),
        }
 }
diff --git a/backend/plugins/bitbucket/models/pr.go 
b/backend/plugins/bitbucket/models/pr.go
index b256b54b4..33ddc24ba 100644
--- a/backend/plugins/bitbucket/models/pr.go
+++ b/backend/plugins/bitbucket/models/pr.go
@@ -18,8 +18,9 @@ limitations under the License.
 package models
 
 import (
-       "github.com/apache/incubator-devlake/core/models/common"
        "time"
+
+       "github.com/apache/incubator-devlake/core/models/common"
 )
 
 type BitbucketPullRequest struct {
@@ -49,6 +50,8 @@ type BitbucketPullRequest struct {
        Url                string `gorm:"type:varchar(255)"`
        AuthorName         string `gorm:"type:varchar(255)"`
        AuthorId           string `gorm:"type:varchar(255)"`
+       MergedByName       string `gorm:"type:varchar(100)"`
+       MergedById         string `gorm:"type:varchar(100)"`
        common.NoPKModel
 }
 
diff --git a/backend/plugins/bitbucket/tasks/pr_collector.go 
b/backend/plugins/bitbucket/tasks/pr_collector.go
index 9ab2b4eac..efa6890e1 100644
--- a/backend/plugins/bitbucket/tasks/pr_collector.go
+++ b/backend/plugins/bitbucket/tasks/pr_collector.go
@@ -49,6 +49,7 @@ func CollectApiPullRequests(taskCtx plugin.SubTaskContext) 
errors.Error {
                UrlTemplate: "repositories/{{ .Params.FullName }}/pullrequests",
                Query: GetQueryCreatedAndUpdated(
                        
`values.id,values.comment_count,values.type,values.state,values.title,values.description,`+
+                               
`values.closed_by.display_name,values.closed_by.account_id,`+
                                
`values.merge_commit.hash,values.merge_commit.date,values.links.html,values.author,values.created_on,values.updated_on,`+
                                
`values.destination.branch.name,values.destination.commit.hash,values.destination.repository.full_name,`+
                                
`values.source.branch.name,values.source.commit.hash,values.source.repository.full_name,`+
diff --git a/backend/plugins/bitbucket/tasks/pr_convertor.go 
b/backend/plugins/bitbucket/tasks/pr_convertor.go
index ed12d0e12..4a54008f0 100644
--- a/backend/plugins/bitbucket/tasks/pr_convertor.go
+++ b/backend/plugins/bitbucket/tasks/pr_convertor.go
@@ -86,6 +86,7 @@ func ConvertPullRequests(taskCtx plugin.SubTaskContext) 
errors.Error {
                                BaseCommitSha:  pr.BaseCommitSha,
                                HeadRef:        pr.HeadRef,
                                HeadCommitSha:  pr.HeadCommitSha,
+                               MergedByName:   pr.MergedByName,
                        }
                        switch pr.State {
                        case "OPEN":
@@ -97,6 +98,9 @@ func ConvertPullRequests(taskCtx plugin.SubTaskContext) 
errors.Error {
                        default:
                                domainPr.Status = pr.State
                        }
+                       if pr.MergedById != "" && pr.State == "MERGED" {
+                               domainPr.MergedById = 
domainUserIdGen.Generate(data.Options.ConnectionId, pr.MergedById)
+                       }
 
                        return []interface{}{
                                domainPr,
diff --git a/backend/plugins/bitbucket/tasks/pr_extractor.go 
b/backend/plugins/bitbucket/tasks/pr_extractor.go
index 855104c80..9cca3a0ce 100644
--- a/backend/plugins/bitbucket/tasks/pr_extractor.go
+++ b/backend/plugins/bitbucket/tasks/pr_extractor.go
@@ -55,7 +55,7 @@ type BitbucketApiPullRequest struct {
                        Href string `json:"href"`
                } `json:"html"`
        } `json:"links"`
-       //ClosedBy           *BitbucketAccountResponse `json:"closed_by"`
+       ClosedBy           *BitbucketAccountResponse `json:"closed_by"`
        Author             *BitbucketAccountResponse `json:"author"`
        BitbucketCreatedAt time.Time                 `json:"created_on"`
        BitbucketUpdatedAt time.Time                 `json:"updated_on"`
@@ -154,5 +154,10 @@ func convertBitbucketPullRequest(pull 
*BitbucketApiPullRequest, connId uint64, r
                bitbucketPull.HeadRef = pull.HeadRef.Branch.Name
                bitbucketPull.HeadCommitSha = pull.HeadRef.Commit.Hash
        }
+       if pull.ClosedBy != nil {
+               bitbucketPull.MergedByName = pull.ClosedBy.DisplayName
+               bitbucketPull.MergedById = pull.ClosedBy.AccountId
+       }
+
        return bitbucketPull, nil
 }

Reply via email to