You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by wa...@apache.org on 2023/04/17 10:44:32 UTC

[incubator-devlake] branch main updated: fix: bitbucket pr_commits/pr_commits have the incorrect FK to pr (#4939)

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

warren 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 bd76b6cc4 fix: bitbucket pr_commits/pr_commits have the incorrect FK to pr (#4939)
bd76b6cc4 is described below

commit bd76b6cc4aa8a705f19fb87d8fadd1a6e1e1a77b
Author: Klesh Wong <zh...@merico.dev>
AuthorDate: Mon Apr 17 18:44:25 2023 +0800

    fix: bitbucket pr_commits/pr_commits have the incorrect FK to pr (#4939)
    
    * refactor: simplify renameCicdPipelineRepoToRepoUrl
    
    * fix: bitbucket pr_commits/pr_commits have the incorrect FK to pr
---
 ...230406_rename_cicd_pipeline_commits_repo_url.go |   7 +-
 backend/plugins/bitbucket/e2e/comment_test.go      |   4 +-
 .../_tool_bitbucket_pull_request_comments.csv      |  38 +++----
 .../migrationscripts/20230417_add_repo_id_to_pr.go | 114 +++++++++++++++++++++
 .../bitbucket/models/migrationscripts/register.go  |   1 +
 backend/plugins/bitbucket/models/pr_comment.go     |   6 +-
 backend/plugins/bitbucket/models/pr_commit.go      |   3 +-
 .../bitbucket/tasks/pr_comment_convertor.go        |  22 ++--
 .../bitbucket/tasks/pr_comment_extractor.go        |   1 +
 .../plugins/bitbucket/tasks/pr_commit_convertor.go |  14 ++-
 .../plugins/bitbucket/tasks/pr_commit_extractor.go |   8 +-
 11 files changed, 166 insertions(+), 52 deletions(-)

diff --git a/backend/core/models/migrationscripts/20230406_rename_cicd_pipeline_commits_repo_url.go b/backend/core/models/migrationscripts/20230406_rename_cicd_pipeline_commits_repo_url.go
index 4cb45b7f8..83b8ca732 100644
--- a/backend/core/models/migrationscripts/20230406_rename_cicd_pipeline_commits_repo_url.go
+++ b/backend/core/models/migrationscripts/20230406_rename_cicd_pipeline_commits_repo_url.go
@@ -28,12 +28,7 @@ var _ plugin.MigrationScript = (*renameCicdPipelineRepoToRepoUrl)(nil)
 type renameCicdPipelineRepoToRepoUrl struct{}
 
 func (*renameCicdPipelineRepoToRepoUrl) Up(basicRes context.BasicRes) errors.Error {
-	db := basicRes.GetDal()
-	err := db.RenameColumn("cicd_pipeline_commits", "repo", "repo_url")
-	if err != nil {
-		return err
-	}
-	return nil
+	return basicRes.GetDal().RenameColumn("cicd_pipeline_commits", "repo", "repo_url")
 }
 
 func (*renameCicdPipelineRepoToRepoUrl) Version() uint64 {
diff --git a/backend/plugins/bitbucket/e2e/comment_test.go b/backend/plugins/bitbucket/e2e/comment_test.go
index 526c7360f..83fbe2a35 100644
--- a/backend/plugins/bitbucket/e2e/comment_test.go
+++ b/backend/plugins/bitbucket/e2e/comment_test.go
@@ -18,13 +18,14 @@ limitations under the License.
 package e2e
 
 import (
+	"testing"
+
 	"github.com/apache/incubator-devlake/core/models/domainlayer/code"
 	"github.com/apache/incubator-devlake/core/models/domainlayer/ticket"
 	"github.com/apache/incubator-devlake/helpers/e2ehelper"
 	"github.com/apache/incubator-devlake/plugins/bitbucket/impl"
 	"github.com/apache/incubator-devlake/plugins/bitbucket/models"
 	"github.com/apache/incubator-devlake/plugins/bitbucket/tasks"
-	"testing"
 )
 
 func TestCommentDataFlow(t *testing.T) {
@@ -71,6 +72,7 @@ func TestCommentDataFlow(t *testing.T) {
 		e2ehelper.ColumnWithRawData(
 			"connection_id",
 			"bitbucket_id",
+			"repo_id",
 			"pull_request_id",
 			"author_name",
 			"author_id",
diff --git a/backend/plugins/bitbucket/e2e/snapshot_tables/_tool_bitbucket_pull_request_comments.csv b/backend/plugins/bitbucket/e2e/snapshot_tables/_tool_bitbucket_pull_request_comments.csv
index 1cc00f41b..aaf3268d9 100644
--- a/backend/plugins/bitbucket/e2e/snapshot_tables/_tool_bitbucket_pull_request_comments.csv
+++ b/backend/plugins/bitbucket/e2e/snapshot_tables/_tool_bitbucket_pull_request_comments.csv
@@ -1,19 +1,19 @@
-connection_id,bitbucket_id,pull_request_id,author_name,author_id,type,_raw_data_params,_raw_data_table,_raw_data_id,_raw_data_remark
-1,323119643,54,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,14,
-1,323119662,54,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,15,
-1,323119730,57,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,17,
-1,323119743,57,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,18,
-1,323119784,51,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,12,
-1,323119790,51,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,13,
-1,323119842,42,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,8,
-1,323119856,42,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,9,
-1,323119897,54,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,16,
-1,323119960,38,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,4,
-1,323119980,38,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,5,
-1,323120091,44,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,10,
-1,323120101,44,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,11,
-1,323120140,40,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,6,
-1,323120196,41,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,7,
-1,323120278,31,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,1,
-1,323120296,31,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,2,
-1,323120311,31,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,3,
+connection_id,bitbucket_id,repo_id,pull_request_id,author_name,author_id,type,_raw_data_params,_raw_data_table,_raw_data_id,_raw_data_remark
+1,323119643,likyh/likyhphp,54,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,14,
+1,323119662,likyh/likyhphp,54,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,15,
+1,323119730,likyh/likyhphp,57,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,17,
+1,323119743,likyh/likyhphp,57,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,18,
+1,323119784,likyh/likyhphp,51,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,12,
+1,323119790,likyh/likyhphp,51,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,13,
+1,323119842,likyh/likyhphp,42,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,8,
+1,323119856,likyh/likyhphp,42,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,9,
+1,323119897,likyh/likyhphp,54,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,16,
+1,323119960,likyh/likyhphp,38,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,4,
+1,323119980,likyh/likyhphp,38,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,5,
+1,323120091,likyh/likyhphp,44,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,10,
+1,323120101,likyh/likyhphp,44,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,11,
+1,323120140,likyh/likyhphp,40,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,6,
+1,323120196,likyh/likyhphp,41,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,7,
+1,323120278,likyh/likyhphp,31,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,1,
+1,323120296,likyh/likyhphp,31,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,2,
+1,323120311,likyh/likyhphp,31,teoiaoe,62abf394192edb006fa0e8cf,pullrequest_comment,"{""ConnectionId"":1,""FullName"":""likyh/likyhphp""}",_raw_bitbucket_api_pull_request_comments,3,
\ No newline at end of file
diff --git a/backend/plugins/bitbucket/models/migrationscripts/20230417_add_repo_id_to_pr.go b/backend/plugins/bitbucket/models/migrationscripts/20230417_add_repo_id_to_pr.go
new file mode 100644
index 000000000..0bf034a4c
--- /dev/null
+++ b/backend/plugins/bitbucket/models/migrationscripts/20230417_add_repo_id_to_pr.go
@@ -0,0 +1,114 @@
+/*
+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 (
+	"time"
+
+	"github.com/apache/incubator-devlake/core/context"
+	"github.com/apache/incubator-devlake/core/errors"
+	"github.com/apache/incubator-devlake/core/models/migrationscripts/archived"
+	"github.com/apache/incubator-devlake/helpers/migrationhelper"
+)
+
+type addRepoIdToPr struct{}
+
+type pr20230417 struct {
+	ConnectionId       uint64 `gorm:"primaryKey"`
+	RepoId             string `gorm:"primaryKey;type:varchar(255)"` // repo_id should be a part of the primary key
+	BitbucketId        int    `gorm:"primaryKey"`
+	Number             int    `gorm:"index"`
+	BaseRepoId         string
+	HeadRepoId         string
+	State              string `gorm:"type:varchar(255)"`
+	Title              string
+	Description        string
+	BitbucketCreatedAt time.Time
+	BitbucketUpdatedAt time.Time `gorm:"index"`
+	ClosedAt           *time.Time
+	CommentCount       int
+	Commits            int
+	MergedAt           *time.Time
+	Body               string
+	Type               string `gorm:"type:varchar(255)"`
+	Component          string `gorm:"type:varchar(255)"`
+	MergeCommitSha     string `gorm:"type:varchar(40)"`
+	HeadRef            string `gorm:"type:varchar(255)"`
+	BaseRef            string `gorm:"type:varchar(255)"`
+	BaseCommitSha      string `gorm:"type:varchar(255)"`
+	HeadCommitSha      string `gorm:"type:varchar(255)"`
+	Url                string `gorm:"type:varchar(255)"`
+	AuthorName         string `gorm:"type:varchar(255)"`
+	AuthorId           string `gorm:"type:varchar(255)"`
+	archived.NoPKModel
+}
+
+func (pr20230417) TableName() string {
+	return "_tool_bitbucket_pull_requests"
+}
+
+type prComment20230417 struct {
+	ConnectionId       uint64 `gorm:"primaryKey"`
+	BitbucketId        int    `gorm:"primaryKey"`
+	RepoId             string `gorm:"index:pr"` // PullRequestId is not unique across multiple repos of a connection
+	PullRequestId      int    `gorm:"index:pr"`
+	AuthorId           string `gorm:"type:varchar(255)"`
+	AuthorName         string `gorm:"type:varchar(255)"`
+	BitbucketCreatedAt time.Time
+	BitbucketUpdatedAt *time.Time
+	Type               string `gorm:"comment:if type=null, it is normal comment,if type=diffNote,it is diff comment"`
+	Body               string
+	archived.NoPKModel
+}
+
+func (prComment20230417) TableName() string {
+	return "_tool_bitbucket_pull_request_comments"
+}
+
+type prCommit20230417 struct {
+	ConnectionId  uint64 `gorm:"primaryKey"`
+	RepoId        string `gorm:"primaryKey"` // PullRequestId is not unique across multiple repos of a connection
+	PullRequestId int    `gorm:"primaryKey;autoIncrement:false"`
+	CommitSha     string `gorm:"primaryKey;type:varchar(40)"`
+	archived.NoPKModel
+}
+
+func (prCommit20230417) TableName() string {
+	return "_tool_bitbucket_pull_request_commits"
+}
+
+func (u *addRepoIdToPr) Up(basicRes context.BasicRes) errors.Error {
+	tables := []interface{}{
+		&pr20230417{},
+		&prComment20230417{},
+		&prCommit20230417{},
+	}
+	err := basicRes.GetDal().DropTables(tables...)
+	if err != nil {
+		return err
+	}
+	return migrationhelper.AutoMigrateTables(basicRes, tables...)
+}
+
+func (*addRepoIdToPr) Version() uint64 {
+	return 20230417150357
+}
+
+func (*addRepoIdToPr) Name() string {
+	return "add repo_id to pr as part of the primary key"
+}
diff --git a/backend/plugins/bitbucket/models/migrationscripts/register.go b/backend/plugins/bitbucket/models/migrationscripts/register.go
index 3618ed65a..854e23f79 100644
--- a/backend/plugins/bitbucket/models/migrationscripts/register.go
+++ b/backend/plugins/bitbucket/models/migrationscripts/register.go
@@ -34,5 +34,6 @@ func All() []plugin.MigrationScript {
 		new(addConnectionIdToTransformationRule),
 		new(addTypeEnvToPipelineAndStep),
 		new(addRepoIdField20230411),
+		new(addRepoIdToPr),
 	}
 }
diff --git a/backend/plugins/bitbucket/models/pr_comment.go b/backend/plugins/bitbucket/models/pr_comment.go
index cea6acd5f..ce2b8372b 100644
--- a/backend/plugins/bitbucket/models/pr_comment.go
+++ b/backend/plugins/bitbucket/models/pr_comment.go
@@ -18,14 +18,16 @@ 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 BitbucketPrComment struct {
 	ConnectionId       uint64 `gorm:"primaryKey"`
 	BitbucketId        int    `gorm:"primaryKey"`
-	PullRequestId      int    `gorm:"index"`
+	RepoId             string `gorm:"index:pr"` // PullRequestId is not unique across multiple repos of a connection
+	PullRequestId      int    `gorm:"index:pr"`
 	AuthorId           string `gorm:"type:varchar(255)"`
 	AuthorName         string `gorm:"type:varchar(255)"`
 	BitbucketCreatedAt time.Time
diff --git a/backend/plugins/bitbucket/models/pr_commit.go b/backend/plugins/bitbucket/models/pr_commit.go
index 4da235beb..74327a32f 100644
--- a/backend/plugins/bitbucket/models/pr_commit.go
+++ b/backend/plugins/bitbucket/models/pr_commit.go
@@ -23,8 +23,9 @@ import (
 
 type BitbucketPrCommit struct {
 	ConnectionId  uint64 `gorm:"primaryKey"`
-	CommitSha     string `gorm:"primaryKey;type:varchar(40)"`
+	RepoId        string `gorm:"primaryKey"` // PullRequestId is not unique across multiple repos of a connection
 	PullRequestId int    `gorm:"primaryKey;autoIncrement:false"`
+	CommitSha     string `gorm:"primaryKey;type:varchar(40)"`
 	common.NoPKModel
 }
 
diff --git a/backend/plugins/bitbucket/tasks/pr_comment_convertor.go b/backend/plugins/bitbucket/tasks/pr_comment_convertor.go
index 66cf0a785..c42c7d6ed 100644
--- a/backend/plugins/bitbucket/tasks/pr_comment_convertor.go
+++ b/backend/plugins/bitbucket/tasks/pr_comment_convertor.go
@@ -18,6 +18,8 @@ limitations under the License.
 package tasks
 
 import (
+	"reflect"
+
 	"github.com/apache/incubator-devlake/core/dal"
 	"github.com/apache/incubator-devlake/core/errors"
 	"github.com/apache/incubator-devlake/core/models/domainlayer"
@@ -26,7 +28,6 @@ import (
 	plugin "github.com/apache/incubator-devlake/core/plugin"
 	"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
 	"github.com/apache/incubator-devlake/plugins/bitbucket/models"
-	"reflect"
 )
 
 var ConvertPrCommentsMeta = plugin.SubTaskMeta{
@@ -40,13 +41,10 @@ var ConvertPrCommentsMeta = plugin.SubTaskMeta{
 func ConvertPullRequestComments(taskCtx plugin.SubTaskContext) errors.Error {
 	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_PULL_REQUEST_COMMENTS_TABLE)
 	db := taskCtx.GetDal()
-	repoId := data.Options.FullName
 
 	cursor, err := db.Cursor(
 		dal.From(&models.BitbucketPrComment{}),
-		dal.Join("left join _tool_bitbucket_pull_requests "+
-			"on _tool_bitbucket_pull_requests.bitbucket_id = _tool_bitbucket_pull_request_comments.pull_request_id"),
-		dal.Where("repo_id = ? and _tool_bitbucket_pull_requests.connection_id = ?", repoId, data.Options.ConnectionId),
+		dal.Where("connection_id = ? AND repo_id = ?", data.Options.ConnectionId, data.Options.FullName),
 	)
 	if err != nil {
 		return err
@@ -62,16 +60,16 @@ func ConvertPullRequestComments(taskCtx plugin.SubTaskContext) errors.Error {
 		Input:              cursor,
 		RawDataSubTaskArgs: *rawDataSubTaskArgs,
 		Convert: func(inputRow interface{}) ([]interface{}, errors.Error) {
-			bitbucketPullRequestComment := inputRow.(*models.BitbucketPrComment)
+			prComment := inputRow.(*models.BitbucketPrComment)
 			domainPrComment := &code.PullRequestComment{
 				DomainEntity: domainlayer.DomainEntity{
-					Id: domainIdGeneratorComment.Generate(data.Options.ConnectionId, bitbucketPullRequestComment.BitbucketId),
+					Id: domainIdGeneratorComment.Generate(prComment.ConnectionId, prComment.BitbucketId),
 				},
-				PullRequestId: prIdGen.Generate(data.Options.ConnectionId, data.Options.FullName, bitbucketPullRequestComment.PullRequestId),
-				AccountId:     accountIdGen.Generate(data.Options.ConnectionId, bitbucketPullRequestComment.AuthorId),
-				CreatedDate:   bitbucketPullRequestComment.CreatedAt,
-				Body:          bitbucketPullRequestComment.Body,
-				Type:          bitbucketPullRequestComment.Type,
+				PullRequestId: prIdGen.Generate(prComment.ConnectionId, prComment.RepoId, prComment.PullRequestId),
+				AccountId:     accountIdGen.Generate(prComment.ConnectionId, prComment.AuthorId),
+				CreatedDate:   prComment.CreatedAt,
+				Body:          prComment.Body,
+				Type:          prComment.Type,
 				CommitSha:     "",
 				Position:      0,
 			}
diff --git a/backend/plugins/bitbucket/tasks/pr_comment_extractor.go b/backend/plugins/bitbucket/tasks/pr_comment_extractor.go
index 8042191d7..9b1784c72 100644
--- a/backend/plugins/bitbucket/tasks/pr_comment_extractor.go
+++ b/backend/plugins/bitbucket/tasks/pr_comment_extractor.go
@@ -64,6 +64,7 @@ func ExtractApiPullRequestsComments(taskCtx plugin.SubTaskContext) errors.Error
 
 			toolprComment, err := convertPullRequestComment(prComment)
 			toolprComment.ConnectionId = data.Options.ConnectionId
+			toolprComment.RepoId = data.Options.FullName
 			if err != nil {
 				return nil, err
 			}
diff --git a/backend/plugins/bitbucket/tasks/pr_commit_convertor.go b/backend/plugins/bitbucket/tasks/pr_commit_convertor.go
index cdf6d72c7..dfde587ff 100644
--- a/backend/plugins/bitbucket/tasks/pr_commit_convertor.go
+++ b/backend/plugins/bitbucket/tasks/pr_commit_convertor.go
@@ -18,13 +18,14 @@ limitations under the License.
 package tasks
 
 import (
+	"reflect"
+
 	"github.com/apache/incubator-devlake/core/dal"
 	"github.com/apache/incubator-devlake/core/errors"
 	"github.com/apache/incubator-devlake/core/models/domainlayer/code"
 	"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
 	"github.com/apache/incubator-devlake/core/plugin"
 	helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
-	"reflect"
 
 	bitbucketModels "github.com/apache/incubator-devlake/plugins/bitbucket/models"
 )
@@ -40,15 +41,12 @@ var ConvertPrCommitsMeta = plugin.SubTaskMeta{
 func ConvertPullRequestCommits(taskCtx plugin.SubTaskContext) (err errors.Error) {
 	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_PULL_REQUEST_COMMITS_TABLE)
 	db := taskCtx.GetDal()
-	repoId := data.Options.FullName
 
 	pullIdGen := didgen.NewDomainIdGenerator(&bitbucketModels.BitbucketPullRequest{})
 
 	cursor, err := db.Cursor(
 		dal.From(&bitbucketModels.BitbucketPrCommit{}),
-		dal.Join(`left join _tool_bitbucket_pull_requests on _tool_bitbucket_pull_requests.bitbucket_id = _tool_bitbucket_pull_request_commits.pull_request_id`),
-		dal.Where("_tool_bitbucket_pull_requests.repo_id = ? and _tool_bitbucket_pull_requests.connection_id = ?", repoId, data.Options.ConnectionId),
-		dal.Orderby("pull_request_id ASC"),
+		dal.Where("connection_id = ? AND repo_id = ?", data.Options.ConnectionId, data.Options.FullName),
 	)
 	if err != nil {
 		return err
@@ -60,10 +58,10 @@ func ConvertPullRequestCommits(taskCtx plugin.SubTaskContext) (err errors.Error)
 		Input:              cursor,
 		RawDataSubTaskArgs: *rawDataSubTaskArgs,
 		Convert: func(inputRow interface{}) ([]interface{}, errors.Error) {
-			bitbucketPullRequestCommit := inputRow.(*bitbucketModels.BitbucketPrCommit)
+			prCommit := inputRow.(*bitbucketModels.BitbucketPrCommit)
 			domainPrCommit := &code.PullRequestCommit{
-				CommitSha:     bitbucketPullRequestCommit.CommitSha,
-				PullRequestId: pullIdGen.Generate(data.Options.ConnectionId, data.Options.FullName, bitbucketPullRequestCommit.PullRequestId),
+				CommitSha:     prCommit.CommitSha,
+				PullRequestId: pullIdGen.Generate(prCommit.ConnectionId, prCommit.RepoId, prCommit.PullRequestId),
 			}
 			return []interface{}{
 				domainPrCommit,
diff --git a/backend/plugins/bitbucket/tasks/pr_commit_extractor.go b/backend/plugins/bitbucket/tasks/pr_commit_extractor.go
index 4abd76966..7c6f6de7d 100644
--- a/backend/plugins/bitbucket/tasks/pr_commit_extractor.go
+++ b/backend/plugins/bitbucket/tasks/pr_commit_extractor.go
@@ -19,11 +19,12 @@ package tasks
 
 import (
 	"encoding/json"
+	"strings"
+	"time"
+
 	"github.com/apache/incubator-devlake/core/errors"
 	"github.com/apache/incubator-devlake/core/plugin"
 	helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
-	"strings"
-	"time"
 
 	"github.com/apache/incubator-devlake/plugins/bitbucket/models"
 )
@@ -89,8 +90,9 @@ func ExtractApiPullRequestCommits(taskCtx plugin.SubTaskContext) errors.Error {
 
 			bitbucketPullRequestCommit := &models.BitbucketPrCommit{
 				ConnectionId:  data.Options.ConnectionId,
-				CommitSha:     apiPullRequestCommit.Hash,
+				RepoId:        repoId,
 				PullRequestId: pull.BitbucketId,
+				CommitSha:     apiPullRequestCommit.Hash,
 			}
 			if err != nil {
 				return nil, err