Skip to content

Commit

Permalink
fix: gitlab pr reviewers and assignees id (#7588)
Browse files Browse the repository at this point in the history
  • Loading branch information
abeizn committed Jun 7, 2024
1 parent 9e47910 commit 15c4c09
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

type PullRequestAssignee 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>
AssigneeId int `gorm:"primaryKey"`
AssigneeId string `gorm:"primaryKey;type:varchar(255);"`
Name string `gorm:"type:varchar(255)"`
UserName string `gorm:"type:varchar(255)"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

type PullRequestReviewer 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>
ReviewerId int `gorm:"primaryKey"`
ReviewerId string `gorm:"primaryKey;type:varchar(255);"`
Name string `gorm:"type:varchar(255)"`
UserName string `gorm:"type:varchar(255)"`

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
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/models/migrationscripts/archived"
"github.com/apache/incubator-devlake/helpers/migrationhelper"
)

type modifyPrAssigneeAndReviewerId struct{}

func (u *modifyPrAssigneeAndReviewerId) Up(basicRes context.BasicRes) errors.Error {
db := basicRes.GetDal()
err := db.DropTables(&archived.PullRequestAssignee{}, &archived.PullRequestReviewer{})
if err != nil {
return err
}
return migrationhelper.AutoMigrateTables(
basicRes,
&archived.PullRequestAssignee{},
&archived.PullRequestReviewer{},
)
}

func (*modifyPrAssigneeAndReviewerId) Version() uint64 {
return 20250607000041
}

func (*modifyPrAssigneeAndReviewerId) Name() string {
return "modify pull_request_reviewers and pull_request_assignees id columns"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package archived

type PullRequestAssignee 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>
AssigneeId int `gorm:"primaryKey"`
AssigneeId string `gorm:"primaryKey;type:varchar(255);"`
Name string `gorm:"type:varchar(255)"`
UserName string `gorm:"type:varchar(255)"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package archived

type PullRequestReviewer 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>
ReviewerId int `gorm:"primaryKey"`
ReviewerId string `gorm:"primaryKey;type:varchar(255);"`
Name string `gorm:"type:varchar(255)"`
UserName string `gorm:"type:varchar(255)"`

Expand Down
1 change: 1 addition & 0 deletions backend/core/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,6 @@ func All() []plugin.MigrationScript {
new(modifyCicdDeploymentCommitsRepoUrlLength),
new(modifyCicdPipelineCommitsRepoUrlLength),
new(addPrAssigneeAndReviewer),
new(modifyPrAssigneeAndReviewerId),
}
}
3 changes: 2 additions & 1 deletion backend/plugins/gitlab/tasks/mr_assignee_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func ConvertMrAssignees(taskCtx plugin.SubTaskContext) errors.Error {
defer cursor.Close()

mrIdGen := didgen.NewDomainIdGenerator(&models.GitlabMergeRequest{})
accountIdGen := didgen.NewDomainIdGenerator(&models.GitlabAccount{})

converter, err := helper.NewDataConverter(helper.DataConverterArgs{
RawDataSubTaskArgs: *rawDataSubTaskArgs,
Expand All @@ -73,7 +74,7 @@ func ConvertMrAssignees(taskCtx plugin.SubTaskContext) errors.Error {
mrAssignee := inputRow.(*models.GitlabAssignee)
domainPrAssigne := &code.PullRequestAssignee{
PullRequestId: mrIdGen.Generate(data.Options.ConnectionId, mrAssignee.MergeRequestId),
AssigneeId: mrAssignee.AssigneeId,
AssigneeId: accountIdGen.Generate(data.Options.ConnectionId, mrAssignee.AssigneeId),
Name: mrAssignee.Name,
UserName: mrAssignee.Username,
}
Expand Down
3 changes: 2 additions & 1 deletion backend/plugins/gitlab/tasks/mr_reviewer_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func ConvertMrReviewers(taskCtx plugin.SubTaskContext) errors.Error {
defer cursor.Close()

mrIdGen := didgen.NewDomainIdGenerator(&models.GitlabMergeRequest{})
accountIdGen := didgen.NewDomainIdGenerator(&models.GitlabAccount{})

converter, err := helper.NewDataConverter(helper.DataConverterArgs{
RawDataSubTaskArgs: *rawDataSubTaskArgs,
Expand All @@ -73,7 +74,7 @@ func ConvertMrReviewers(taskCtx plugin.SubTaskContext) errors.Error {
mrReviewer := inputRow.(*models.GitlabReviewer)
domainPrReviewer := &code.PullRequestReviewer{
PullRequestId: mrIdGen.Generate(data.Options.ConnectionId, mrReviewer.MergeRequestId),
ReviewerId: mrReviewer.ReviewerId,
ReviewerId: accountIdGen.Generate(data.Options.ConnectionId, mrReviewer.ReviewerId),
Name: mrReviewer.Name,
UserName: mrReviewer.Username,
}
Expand Down

0 comments on commit 15c4c09

Please sign in to comment.