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

klesh 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 f2e0514a fix: rename pull_request_number to pull_request_key, 
issue_number to … (#2635)
f2e0514a is described below

commit f2e0514acd0180ad68524e42cd33e714af8b78e6
Author: mindlesscloud <[email protected]>
AuthorDate: Wed Aug 3 14:57:20 2022 +0800

    fix: rename pull_request_number to pull_request_key, issue_number to … 
(#2635)
    
    * fix: rename pull_request_number to pull_request_key, issue_number to 
issue_key
    
    * fix: fix e2e test
    
    Co-authored-by: Klesh Wong <[email protected]>
---
 .../domainlayer/crossdomain/pull_request_issue.go  |  8 ++--
 ...20729_rename_columns_of_pull_request_issues.go} | 44 +++++++++++++---------
 models/migrationscripts/register.go                |  1 +
 plugins/gitee/tasks/pr_issue_convertor.go          |  8 ++--
 plugins/github/e2e/pr_enrich_issue_test.go         |  4 +-
 .../e2e/snapshot_tables/pull_request_issues.csv    |  2 +-
 plugins/github/tasks/pr_issue_convertor.go         |  8 ++--
 services/init.go                                   |  6 +--
 8 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/models/domainlayer/crossdomain/pull_request_issue.go 
b/models/domainlayer/crossdomain/pull_request_issue.go
index 35569e76..b680690d 100644
--- a/models/domainlayer/crossdomain/pull_request_issue.go
+++ b/models/domainlayer/crossdomain/pull_request_issue.go
@@ -20,10 +20,10 @@ package crossdomain
 import "github.com/apache/incubator-devlake/models/common"
 
 type PullRequestIssue struct {
-       PullRequestId     string `json:"id" 
gorm:"primaryKey;type:varchar(255);comment:This key is generated based on 
details from the original plugin"` // format: <Plugin>:<Entity>:<PK0>:<PK1>
-       IssueId           string `gorm:"primaryKey;type:varchar(255)"`
-       PullRequestNumber int
-       IssueNumber       int
+       PullRequestId  string `json:"id" 
gorm:"primaryKey;type:varchar(255);comment:This key is generated based on 
details from the original plugin"` // format: <Plugin>:<Entity>:<PK0>:<PK1>
+       IssueId        string `gorm:"primaryKey;type:varchar(255)"`
+       PullRequestKey int
+       IssueKey       int
        common.NoPKModel
 }
 
diff --git a/models/migrationscripts/register.go 
b/models/migrationscripts/202220729_rename_columns_of_pull_request_issues.go
similarity index 51%
copy from models/migrationscripts/register.go
copy to 
models/migrationscripts/202220729_rename_columns_of_pull_request_issues.go
index 47591a18..dc587d52 100644
--- a/models/migrationscripts/register.go
+++ b/models/migrationscripts/202220729_rename_columns_of_pull_request_issues.go
@@ -17,22 +17,32 @@ limitations under the License.
 
 package migrationscripts
 
-import "github.com/apache/incubator-devlake/migration"
-
-// All return all the migration scripts of framework
-func All() []migration.Script {
-       return []migration.Script{
-               new(addFrameTables),
-               new(renameStepToStage),
-               new(addSubtasksField),
-               new(updateBlueprintMode),
-               new(renameTasksToPlan),
-               new(addDomainTables),
-               new(addTypeField),
-               new(commitfileComponent),
-               new(removeNotes),
-               new(addProjectMapping),
-               new(addNoPKModelToCommitParent),
-               new(addSubtasksTable),
+import (
+       "context"
+       "github.com/apache/incubator-devlake/models/migrationscripts/archived"
+       "gorm.io/gorm"
+)
+
+type renameColumnsOfPullRequestIssue struct{}
+
+func (*renameColumnsOfPullRequestIssue) Up(ctx context.Context, db *gorm.DB) 
error {
+
+       err := db.Migrator().RenameColumn(&archived.PullRequestIssue{}, 
"pull_request_number", "pull_request_key")
+       if err != nil {
+               return err
        }
+       err = db.Migrator().RenameColumn(&archived.PullRequestIssue{}, 
"issue_number", "issue_key")
+       if err != nil {
+               return err
+       }
+
+       return nil
+}
+
+func (*renameColumnsOfPullRequestIssue) Version() uint64 {
+       return 20220729165805
+}
+
+func (*renameColumnsOfPullRequestIssue) Name() string {
+       return "rename pull_request_number to pull_request_key, issue_number to 
issue_key"
 }
diff --git a/models/migrationscripts/register.go 
b/models/migrationscripts/register.go
index 47591a18..54ff6793 100644
--- a/models/migrationscripts/register.go
+++ b/models/migrationscripts/register.go
@@ -32,6 +32,7 @@ func All() []migration.Script {
                new(commitfileComponent),
                new(removeNotes),
                new(addProjectMapping),
+               new(renameColumnsOfPullRequestIssue),
                new(addNoPKModelToCommitParent),
                new(addSubtasksTable),
        }
diff --git a/plugins/gitee/tasks/pr_issue_convertor.go 
b/plugins/gitee/tasks/pr_issue_convertor.go
index a0dced8a..9081569e 100644
--- a/plugins/gitee/tasks/pr_issue_convertor.go
+++ b/plugins/gitee/tasks/pr_issue_convertor.go
@@ -65,10 +65,10 @@ func ConvertPullRequestIssues(taskCtx core.SubTaskContext) 
error {
                        giteePrIssue := inputRow.(*models.GiteePullRequestIssue)
                        issueNum, _ := strconv.Atoi(giteePrIssue.IssueNumber)
                        pullRequestIssue := &crossdomain.PullRequestIssue{
-                               PullRequestId:     
prIdGen.Generate(data.Options.ConnectionId, giteePrIssue.PullRequestId),
-                               IssueId:           
issueIdGen.Generate(data.Options.ConnectionId, giteePrIssue.IssueId),
-                               IssueNumber:       issueNum,
-                               PullRequestNumber: 
giteePrIssue.PullRequestNumber,
+                               PullRequestId:  
prIdGen.Generate(data.Options.ConnectionId, giteePrIssue.PullRequestId),
+                               IssueId:        
issueIdGen.Generate(data.Options.ConnectionId, giteePrIssue.IssueId),
+                               IssueKey:       issueNum,
+                               PullRequestKey: giteePrIssue.PullRequestNumber,
                        }
                        return []interface{}{
                                pullRequestIssue,
diff --git a/plugins/github/e2e/pr_enrich_issue_test.go 
b/plugins/github/e2e/pr_enrich_issue_test.go
index 577ee812..b5b6458c 100644
--- a/plugins/github/e2e/pr_enrich_issue_test.go
+++ b/plugins/github/e2e/pr_enrich_issue_test.go
@@ -86,8 +86,8 @@ func TestPrEnrichIssueDataFlow(t *testing.T) {
                []string{
                        "pull_request_id",
                        "issue_id",
-                       "pull_request_number",
-                       "issue_number",
+                       "pull_request_key",
+                       "issue_key",
                        "_raw_data_params",
                        "_raw_data_table",
                        "_raw_data_id",
diff --git a/plugins/github/e2e/snapshot_tables/pull_request_issues.csv 
b/plugins/github/e2e/snapshot_tables/pull_request_issues.csv
index 306e0163..c6713ed4 100644
--- a/plugins/github/e2e/snapshot_tables/pull_request_issues.csv
+++ b/plugins/github/e2e/snapshot_tables/pull_request_issues.csv
@@ -1,2 +1,2 @@
-pull_request_id,issue_id,pull_request_number,issue_number,_raw_data_params,_raw_data_table,_raw_data_id,_raw_data_remark
+pull_request_id,issue_id,pull_request_key,issue_key,_raw_data_params,_raw_data_table,_raw_data_id,_raw_data_remark
 
github:GithubPullRequest:1:246250598,github:GithubIssue:1:401277739,23,22,"{""ConnectionId"":1,""Owner"":""panjf2000"",""Repo"":""ants""}",_raw_github_api_pull_requests,255,
diff --git a/plugins/github/tasks/pr_issue_convertor.go 
b/plugins/github/tasks/pr_issue_convertor.go
index 898ad383..0a09ff4b 100644
--- a/plugins/github/tasks/pr_issue_convertor.go
+++ b/plugins/github/tasks/pr_issue_convertor.go
@@ -70,10 +70,10 @@ func ConvertPullRequestIssues(taskCtx core.SubTaskContext) 
error {
                Convert: func(inputRow interface{}) ([]interface{}, error) {
                        githubPrIssue := inputRow.(*githubModels.GithubPrIssue)
                        pullRequestIssue := &crossdomain.PullRequestIssue{
-                               PullRequestId:     
prIdGen.Generate(data.Options.ConnectionId, githubPrIssue.PullRequestId),
-                               IssueId:           
issueIdGen.Generate(data.Options.ConnectionId, githubPrIssue.IssueId),
-                               IssueNumber:       githubPrIssue.IssueNumber,
-                               PullRequestNumber: 
githubPrIssue.PullRequestNumber,
+                               PullRequestId:  
prIdGen.Generate(data.Options.ConnectionId, githubPrIssue.PullRequestId),
+                               IssueId:        
issueIdGen.Generate(data.Options.ConnectionId, githubPrIssue.IssueId),
+                               IssueKey:       githubPrIssue.IssueNumber,
+                               PullRequestKey: githubPrIssue.PullRequestNumber,
                        }
                        return []interface{}{
                                pullRequestIssue,
diff --git a/services/init.go b/services/init.go
index be3610db..963eae69 100644
--- a/services/init.go
+++ b/services/init.go
@@ -19,15 +19,13 @@ package services
 
 import (
        "context"
-
-       "github.com/apache/incubator-devlake/models/migrationscripts"
-       "github.com/apache/incubator-devlake/plugins/core"
-
        "time"
 
        "github.com/apache/incubator-devlake/config"
        "github.com/apache/incubator-devlake/logger"
        "github.com/apache/incubator-devlake/migration"
+       "github.com/apache/incubator-devlake/models/migrationscripts"
+       "github.com/apache/incubator-devlake/plugins/core"
        "github.com/apache/incubator-devlake/runner"
        "github.com/robfig/cron/v3"
        "github.com/spf13/viper"

Reply via email to