You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ly...@apache.org on 2024/05/23 09:53:44 UTC
(incubator-devlake) 01/01: feat(pull_request_issues): change issue_key's type to varchar
This is an automated email from the ASF dual-hosted git repository.
lynwee pushed a commit to branch update-pull_request_issues
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit b156931106eb8caf70ee5079acf2af3a8c6725b2
Author: d4x1 <15...@qq.com>
AuthorDate: Thu May 23 17:53:28 2024 +0800
feat(pull_request_issues): change issue_key's type to varchar
---
.../domainlayer/crossdomain/pull_request_issue.go | 2 +-
...update_issue_key_type_in_pull_request_issues.go | 49 ++++++++++++++++++++++
backend/core/models/migrationscripts/register.go | 1 +
backend/plugins/gitee/tasks/pr_issue_convertor.go | 3 +-
backend/plugins/github/tasks/pr_issue_convertor.go | 3 +-
5 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/backend/core/models/domainlayer/crossdomain/pull_request_issue.go b/backend/core/models/domainlayer/crossdomain/pull_request_issue.go
index 33ee68b4a..a336b4c5d 100644
--- a/backend/core/models/domainlayer/crossdomain/pull_request_issue.go
+++ b/backend/core/models/domainlayer/crossdomain/pull_request_issue.go
@@ -25,7 +25,7 @@ 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)"`
PullRequestKey int
- IssueKey int
+ IssueKey string `gorm:"type:varchar(255)"`
common.NoPKModel
}
diff --git a/backend/core/models/migrationscripts/20240523_update_issue_key_type_in_pull_request_issues.go b/backend/core/models/migrationscripts/20240523_update_issue_key_type_in_pull_request_issues.go
new file mode 100644
index 000000000..f0399d537
--- /dev/null
+++ b/backend/core/models/migrationscripts/20240523_update_issue_key_type_in_pull_request_issues.go
@@ -0,0 +1,49 @@
+/*
+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 (
+ "github.com/apache/incubator-devlake/core/context"
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/core/plugin"
+ "github.com/apache/incubator-devlake/helpers/migrationhelper"
+)
+
+var _ plugin.MigrationScript = (*addCommitShaToCicdRelease)(nil)
+
+type pullRequestIssues20240523 struct {
+ IssueKey string `gorm:"type:varchar(255)"`
+}
+
+func (pullRequestIssues20240523) TableName() string {
+ return "pull_request_issues"
+}
+
+type updateIssueKeyType struct{}
+
+func (*updateIssueKeyType) Up(basicRes context.BasicRes) errors.Error {
+ return migrationhelper.AutoMigrateTables(basicRes, &pullRequestIssues20240523{})
+}
+
+func (*updateIssueKeyType) Version() uint64 {
+ return 20240523174200
+}
+
+func (*updateIssueKeyType) Name() string {
+ return "update issue_key's type in pull_request_issues"
+}
diff --git a/backend/core/models/migrationscripts/register.go b/backend/core/models/migrationscripts/register.go
index 8618db1aa..5e1efde06 100644
--- a/backend/core/models/migrationscripts/register.go
+++ b/backend/core/models/migrationscripts/register.go
@@ -115,5 +115,6 @@ func All() []plugin.MigrationScript {
new(addSubtaskStates),
new(addCicdRelease),
new(addCommitShaToCicdRelease),
+ new(updateIssueKeyType),
}
}
diff --git a/backend/plugins/gitee/tasks/pr_issue_convertor.go b/backend/plugins/gitee/tasks/pr_issue_convertor.go
index 6da1a0387..962d36652 100644
--- a/backend/plugins/gitee/tasks/pr_issue_convertor.go
+++ b/backend/plugins/gitee/tasks/pr_issue_convertor.go
@@ -25,6 +25,7 @@ import (
"github.com/apache/incubator-devlake/core/plugin"
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/plugins/gitee/models"
+ "github.com/spf13/cast"
"reflect"
"strconv"
)
@@ -66,7 +67,7 @@ func ConvertPullRequestIssues(taskCtx plugin.SubTaskContext) errors.Error {
pullRequestIssue := &crossdomain.PullRequestIssue{
PullRequestId: prIdGen.Generate(data.Options.ConnectionId, giteePrIssue.PullRequestId),
IssueId: issueIdGen.Generate(data.Options.ConnectionId, giteePrIssue.IssueId),
- IssueKey: issueNum,
+ IssueKey: cast.ToString(issueNum),
PullRequestKey: giteePrIssue.PullRequestNumber,
}
return []interface{}{
diff --git a/backend/plugins/github/tasks/pr_issue_convertor.go b/backend/plugins/github/tasks/pr_issue_convertor.go
index a0cafb1ff..979a8b128 100644
--- a/backend/plugins/github/tasks/pr_issue_convertor.go
+++ b/backend/plugins/github/tasks/pr_issue_convertor.go
@@ -18,6 +18,7 @@ limitations under the License.
package tasks
import (
+ "github.com/spf13/cast"
"reflect"
"github.com/apache/incubator-devlake/core/dal"
@@ -80,7 +81,7 @@ func ConvertPullRequestIssues(taskCtx plugin.SubTaskContext) errors.Error {
pullRequestIssue := &crossdomain.PullRequestIssue{
PullRequestId: prIdGen.Generate(data.Options.ConnectionId, githubPrIssue.PullRequestId),
IssueId: issueIdGen.Generate(data.Options.ConnectionId, githubPrIssue.IssueId),
- IssueKey: githubPrIssue.IssueNumber,
+ IssueKey: cast.ToString(githubPrIssue.IssueNumber),
PullRequestKey: githubPrIssue.PullRequestNumber,
}
return []interface{}{