From b156931106eb8caf70ee5079acf2af3a8c6725b2 Mon Sep 17 00:00:00 2001 From: d4x1 <1507509064@qq.com> Date: Thu, 23 May 2024 17:53:28 +0800 Subject: [PATCH] feat(pull_request_issues): change issue_key's type to varchar --- .../crossdomain/pull_request_issue.go | 2 +- ...e_issue_key_type_in_pull_request_issues.go | 49 +++++++++++++++++++ .../core/models/migrationscripts/register.go | 1 + .../plugins/gitee/tasks/pr_issue_convertor.go | 3 +- .../github/tasks/pr_issue_convertor.go | 3 +- 5 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 backend/core/models/migrationscripts/20240523_update_issue_key_type_in_pull_request_issues.go diff --git a/backend/core/models/domainlayer/crossdomain/pull_request_issue.go b/backend/core/models/domainlayer/crossdomain/pull_request_issue.go index 33ee68b4a51..a336b4c5d23 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: ::: 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 00000000000..f0399d537b4 --- /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 8618db1aa8c..5e1efde0633 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 6da1a038719..962d3665204 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 a0cafb1ff93..979a8b128f3 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{}{