Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add assignees and reviewers to pull_request_x table #7556

Merged
merged 5 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions backend/core/models/domainlayer/code/pull_request_assignees.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
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 code

import (
"github.com/apache/incubator-devlake/core/models/common"
)

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

common.NoPKModel
}

func (PullRequestAssignee) TableName() string {
return "pull_request_assignees"
}
35 changes: 35 additions & 0 deletions backend/core/models/domainlayer/code/pull_request_reviewers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
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 code

import (
"github.com/apache/incubator-devlake/core/models/common"
)

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

common.NoPKModel
}

func (PullRequestReviewer) TableName() string {
return "pull_request_reviewers"
}
2 changes: 2 additions & 0 deletions backend/core/models/domainlayer/domaininfo/domaininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func GetDomainTablesInfo() []dal.Tabler {
&code.PullRequestComment{},
&code.PullRequestCommit{},
&code.PullRequestLabel{},
&code.PullRequestReviewer{},
&code.PullRequestAssignee{},
&code.Ref{},
&code.CommitsDiff{},
&code.RefCommit{},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
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 addPrAssigneeAndReviewer struct{}

func (u *addPrAssigneeAndReviewer) Up(basicRes context.BasicRes) errors.Error {
return migrationhelper.AutoMigrateTables(
basicRes,
&archived.PullRequestAssignee{},
&archived.PullRequestReviewer{},
)
}

func (*addPrAssigneeAndReviewer) Version() uint64 {
return 20250531000041
}

func (*addPrAssigneeAndReviewer) Name() string {
return "add pull_request_reviewers and pull_request_assignees tables"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
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 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"`
Name string `gorm:"type:varchar(255)"`
UserName string `gorm:"type:varchar(255)"`

NoPKModel
}

func (PullRequestAssignee) TableName() string {
return "pull_request_assignees"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
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 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"`
Name string `gorm:"type:varchar(255)"`
UserName string `gorm:"type:varchar(255)"`

NoPKModel
}

func (PullRequestReviewer) TableName() string {
return "pull_request_reviewers"
}
1 change: 1 addition & 0 deletions backend/core/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,6 @@ func All() []plugin.MigrationScript {
new(updatePluginOptionInProjectMetricSetting),
new(modifyCicdDeploymentCommitsRepoUrlLength),
new(modifyCicdPipelineCommitsRepoUrlLength),
new(addPrAssigneeAndReviewer),
}
}
2 changes: 2 additions & 0 deletions backend/plugins/gitlab/e2e/mr_commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func TestGitlabMrCommitDataFlow(t *testing.T) {
// verify extraction
dataflowTester.FlushTabler(&models.GitlabMergeRequest{})
dataflowTester.FlushTabler(&models.GitlabMrLabel{})
dataflowTester.FlushTabler(&models.GitlabAssignee{})
dataflowTester.FlushTabler(&models.GitlabReviewer{})
dataflowTester.Subtask(tasks.ExtractApiMergeRequestsMeta, taskData)
dataflowTester.VerifyTable(
models.GitlabMergeRequest{},
Expand Down
1 change: 1 addition & 0 deletions backend/plugins/gitlab/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (p Gitlab) GetTablesInfo() []dal.Tabler {
&models.GitlabProject{},
&models.GitlabProjectCommit{},
&models.GitlabReviewer{},
&models.GitlabAssignee{},
&models.GitlabTag{},
&models.GitlabIssueAssignee{},
&models.GitlabScopeConfig{},
Expand Down
39 changes: 39 additions & 0 deletions backend/plugins/gitlab/models/assignee.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
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 models

import (
"github.com/apache/incubator-devlake/core/models/common"
)

type GitlabAssignee struct {
ConnectionId uint64 `gorm:"primaryKey"`
AssigneeId int `gorm:"primaryKey"`
MergeRequestId int `gorm:"index"`
ProjectId int `gorm:"index"`
Name string `gorm:"type:varchar(255)"`
Username string `gorm:"type:varchar(255)"`
State string `gorm:"type:varchar(255)"`
AvatarUrl string `gorm:"type:varchar(255)"`
WebUrl string `gorm:"type:varchar(255)"`
common.NoPKModel
}

func (GitlabAssignee) TableName() string {
return "_tool_gitlab_assignees"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
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/helpers/migrationhelper"
"github.com/apache/incubator-devlake/plugins/gitlab/models/migrationscripts/archived"
)

type addGitlabAssignee struct{}

func (*addGitlabAssignee) Up(baseRes context.BasicRes) errors.Error {
err := baseRes.GetDal().DropTables(archived.GitlabAssignee{})
if err != nil {
return err
}

err = migrationhelper.AutoMigrateTables(
baseRes,
&archived.GitlabAssignee{},
&archived.GitlabReviewer{},
)
if err != nil {
return err
}

return nil
}

func (*addGitlabAssignee) Version() uint64 {
return 20240531110339
}

func (*addGitlabAssignee) Name() string {
return "add _tool_gitlab_assignees table"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
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 archived

import (
"github.com/apache/incubator-devlake/core/models/migrationscripts/archived"
)

type GitlabAssignee struct {
ConnectionId uint64 `gorm:"primaryKey"`
AssigneeId int `gorm:"primaryKey"`
MergeRequestId int `gorm:"index"`
ProjectId int `gorm:"index"`
Name string `gorm:"type:varchar(255)"`
Username string `gorm:"type:varchar(255)"`
State string `gorm:"type:varchar(255)"`
AvatarUrl string `gorm:"type:varchar(255)"`
WebUrl string `gorm:"type:varchar(255)"`
archived.NoPKModel
}

func (GitlabAssignee) TableName() string {
return "_tool_gitlab_assignees"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import (
)

type GitlabReviewer struct {
ConnectionId uint64 `gorm:"primaryKey"`

GitlabId int `gorm:"primaryKey"`
ConnectionId uint64 `gorm:"primaryKey"`
ReviewerId int `gorm:"primaryKey"`
MergeRequestId int `gorm:"index"`
ProjectId int `gorm:"index"`
Name string `gorm:"type:varchar(255)"`
Expand Down
1 change: 1 addition & 0 deletions backend/plugins/gitlab/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ func All() []plugin.MigrationScript {
new(addTimeToGitlabPipelineProject),
new(modifyDeploymentCommitTitle),
new(addWebUrlToGitlabPipelineProject),
new(addGitlabAssignee),
}
}
5 changes: 2 additions & 3 deletions backend/plugins/gitlab/models/reviewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import (
)

type GitlabReviewer struct {
ConnectionId uint64 `gorm:"primaryKey"`

GitlabId int `gorm:"primaryKey"`
ConnectionId uint64 `gorm:"primaryKey"`
ReviewerId int `gorm:"primaryKey"`
MergeRequestId int `gorm:"index"`
ProjectId int `gorm:"index"`
Name string `gorm:"type:varchar(255)"`
Expand Down
Loading
Loading