Skip to content
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
39 changes: 39 additions & 0 deletions models/domainlayer/crossdomain/account.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 crossdomain

import (
"time"

"github.com/apache/incubator-devlake/models/domainlayer"
)

type Account struct {
domainlayer.DomainEntity
Email string `gorm:"type:varchar(255)"`
FullName string `gorm:"type:varchar(255)"`
UserName string `gorm:"type:varchar(255)"`
AvatarUrl string `gorm:"type:varchar(255)"`
Organization string `gorm:"type:varchar(255)"`
CreatedDate *time.Time
Status int
}

func (Account) TableName() string {
return "accounts"
}
32 changes: 32 additions & 0 deletions models/domainlayer/crossdomain/team.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
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 crossdomain

import "github.com/apache/incubator-devlake/models/domainlayer"

type Team struct {
domainlayer.DomainEntity
Name string `gorm:"type:varchar(255)"`
Alias string `gorm:"type:varchar(255)"`
ParentId string `gorm:"type:varchar(255)"`
SortingIndex int
}

func (Team) TableName() string {
return "teams"
}
27 changes: 27 additions & 0 deletions models/domainlayer/crossdomain/team_user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
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 crossdomain

type TeamUser struct {
TeamId string `gorm:"primaryKey;type:varchar(255)"`
UserId string `gorm:"primaryKey;type:varchar(255)"`
}

func (TeamUser) TableName() string {
return "team_users"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package user
package crossdomain

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

type User struct {
domainlayer.DomainEntity
Name string `gorm:"type:varchar(255)"`
Email string `gorm:"type:varchar(255)"`
AvatarUrl string `gorm:"type:varchar(255)"`
Timezone string `gorm:"type:varchar(255)"`
Email string `gorm:"type:varchar(255)"`
Name string `gorm:"type:varchar(255)"`
}

func (User) TableName() string {
Expand Down
27 changes: 27 additions & 0 deletions models/domainlayer/crossdomain/user_account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
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 crossdomain

type UserAccount struct {
UserId string `gorm:"primaryKey;type:varchar(255)"`
AccountId string `gorm:"primaryKey;type:varchar(255)"`
}

func (UserAccount) TableName() string {
return "user_accounts"
}
4 changes: 3 additions & 1 deletion models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func All() []migration.Script {
new(updateSchemas20220602), new(updateSchemas20220612), new(updateSchemas20220613),
new(updateSchemas20220614), new(updateSchemas2022061402), new(updateSchemas20220616),
new(blueprintNormalMode),
new(UpdateSchemas20220630), new(UpdateSchemas20220704),
new(UpdateSchemas20220630),
new(UpdateSchemas20220704),
new(UpdateSchemas20220705),
}
}
104 changes: 104 additions & 0 deletions models/migrationscripts/updateSchemas20220705.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
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 (
"context"
"time"

"github.com/apache/incubator-devlake/models/migrationscripts/archived"
"gorm.io/gorm"
)

type User struct {
archived.DomainEntity
Email string `gorm:"type:varchar(255)"`
Name string `gorm:"type:varchar(255)"`
}

type Account struct {
archived.DomainEntity
Email string `gorm:"type:varchar(255)"`
FullName string `gorm:"type:varchar(255)"`
UserName string `gorm:"type:varchar(255)"`
AvatarUrl string `gorm:"type:varchar(255)"`
Organization string `gorm:"type:varchar(255)"`
CreatedDate *time.Time
Status int
}

type UserAccount struct {
UserId string `gorm:"primaryKey;type:varchar(255)"`
AccountId string `gorm:"primaryKey;type:varchar(255)"`
}

type Team struct {
archived.DomainEntity
Name string `gorm:"type:varchar(255)"`
Alias string `gorm:"type:varchar(255)"`
ParentId string `gorm:"type:varchar(255)"`
SortingIndex int
}

type TeamUser struct {
TeamId string `gorm:"primaryKey;type:varchar(255)"`
UserId string `gorm:"primaryKey;type:varchar(255)"`
}

type UpdateSchemas20220705 struct {
}

func (u *UpdateSchemas20220705) Up(ctx context.Context, db *gorm.DB) error {
err := db.Migrator().RenameTable("users", "accounts")
if err != nil {
return err
}
err = db.Migrator().DropColumn(&Account{}, "timezone")
if err != nil {
return err
}
err = db.Migrator().AutoMigrate(&User{})
if err != nil {
return err
}
err = db.Migrator().AutoMigrate(&Account{})
if err != nil {
return err
}
err = db.Migrator().AutoMigrate(&UserAccount{})
if err != nil {
return err
}
err = db.Migrator().AutoMigrate(&Team{})
if err != nil {
return err
}
err = db.Migrator().AutoMigrate(&TeamUser{})
if err != nil {
return err
}
return nil
}

func (*UpdateSchemas20220705) Version() uint64 {
return 20220705141638
}

func (*UpdateSchemas20220705) Name() string {
return "rename users to accounts, create users, user_accounts, teams, team_users"
}
10 changes: 5 additions & 5 deletions plugins/gitee/tasks/account_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ limitations under the License.
package tasks

import (
"github.com/apache/incubator-devlake/models/domainlayer/crossdomain"
"reflect"

"github.com/apache/incubator-devlake/plugins/core/dal"

"github.com/apache/incubator-devlake/models/domainlayer"
"github.com/apache/incubator-devlake/models/domainlayer/didgen"
"github.com/apache/incubator-devlake/models/domainlayer/user"
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/gitee/models"
"github.com/apache/incubator-devlake/plugins/helper"
Expand All @@ -47,17 +47,17 @@ func ConvertAccounts(taskCtx core.SubTaskContext) error {
}
defer cursor.Close()

userIdGen := didgen.NewDomainIdGenerator(&models.GiteeAccount{})
accountIdGen := didgen.NewDomainIdGenerator(&models.GiteeAccount{})

converter, err := helper.NewDataConverter(helper.DataConverterArgs{
InputRowType: reflect.TypeOf(models.GiteeAccount{}),
Input: cursor,
RawDataSubTaskArgs: *rawDataSubTaskArgs,
Convert: func(inputRow interface{}) ([]interface{}, error) {
GiteeAccount := inputRow.(*models.GiteeAccount)
domainUser := &user.User{
DomainEntity: domainlayer.DomainEntity{Id: userIdGen.Generate(data.Options.ConnectionId, GiteeAccount.Id)},
Name: GiteeAccount.Login,
domainUser := &crossdomain.Account{
DomainEntity: domainlayer.DomainEntity{Id: accountIdGen.Generate(data.Options.ConnectionId, GiteeAccount.Id)},
UserName: GiteeAccount.Login,
AvatarUrl: GiteeAccount.AvatarUrl,
}
return []interface{}{
Expand Down
6 changes: 3 additions & 3 deletions plugins/gitee/tasks/commit_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func ConvertCommits(taskCtx core.SubTaskContext) error {
}
defer cursor.Close()

userDidGen := didgen.NewDomainIdGenerator(&models.GiteeAccount{})
accountIdGen := didgen.NewDomainIdGenerator(&models.GiteeAccount{})
repoDidGen := didgen.NewDomainIdGenerator(&models.GiteeRepo{})
domainRepoId := repoDidGen.Generate(data.Options.ConnectionId, repoId)

Expand All @@ -74,14 +74,14 @@ func ConvertCommits(taskCtx core.SubTaskContext) error {
commit.Message = giteeCommit.Message
commit.Additions = giteeCommit.Additions
commit.Deletions = giteeCommit.Deletions
commit.AuthorId = userDidGen.Generate(data.Options.ConnectionId, giteeCommit.AuthorId)
commit.AuthorId = accountIdGen.Generate(data.Options.ConnectionId, giteeCommit.AuthorId)
commit.AuthorName = giteeCommit.AuthorName
commit.AuthorEmail = giteeCommit.AuthorEmail
commit.AuthoredDate = giteeCommit.AuthoredDate
commit.CommitterName = giteeCommit.CommitterName
commit.CommitterEmail = giteeCommit.CommitterEmail
commit.CommittedDate = giteeCommit.CommittedDate
commit.CommitterId = userDidGen.Generate(data.Options.ConnectionId, giteeCommit.CommitterId)
commit.CommitterId = accountIdGen.Generate(data.Options.ConnectionId, giteeCommit.CommitterId)

// convert repo / commits relationship
repoCommit := &code.RepoCommit{
Expand Down
4 changes: 2 additions & 2 deletions plugins/gitee/tasks/issue_comment_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func ConvertIssueComments(taskCtx core.SubTaskContext) error {
defer cursor.Close()

issueIdGen := didgen.NewDomainIdGenerator(&models.GiteeIssue{})
userIdGen := didgen.NewDomainIdGenerator(&models.GiteeAccount{})
accountIdGen := didgen.NewDomainIdGenerator(&models.GiteeAccount{})

converter, err := helper.NewDataConverter(helper.DataConverterArgs{
InputRowType: reflect.TypeOf(models.GiteeIssueComment{}),
Expand All @@ -68,7 +68,7 @@ func ConvertIssueComments(taskCtx core.SubTaskContext) error {
},
IssueId: issueIdGen.Generate(data.Options.ConnectionId, giteeIssueComment.IssueId),
Body: giteeIssueComment.Body,
UserId: userIdGen.Generate(data.Options.ConnectionId, giteeIssueComment.AuthorUserId),
UserId: accountIdGen.Generate(data.Options.ConnectionId, giteeIssueComment.AuthorUserId),
CreatedDate: giteeIssueComment.GiteeCreatedAt,
}
return []interface{}{
Expand Down
6 changes: 3 additions & 3 deletions plugins/gitee/tasks/issue_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func ConvertIssues(taskCtx core.SubTaskContext) error {
defer cursor.Close()

issueIdGen := didgen.NewDomainIdGenerator(&giteeModels.GiteeIssue{})
userIdGen := didgen.NewDomainIdGenerator(&giteeModels.GiteeAccount{})
accountIdGen := didgen.NewDomainIdGenerator(&giteeModels.GiteeAccount{})
boardIdGen := didgen.NewDomainIdGenerator(&giteeModels.GiteeRepo{})

converter, err := helper.NewDataConverter(helper.DataConverterArgs{
Expand All @@ -71,9 +71,9 @@ func ConvertIssues(taskCtx core.SubTaskContext) error {
Description: issue.Body,
Priority: issue.Priority,
Type: issue.Type,
AssigneeId: userIdGen.Generate(data.Options.ConnectionId, issue.AssigneeId),
AssigneeId: accountIdGen.Generate(data.Options.ConnectionId, issue.AssigneeId),
AssigneeName: issue.AssigneeName,
CreatorId: userIdGen.Generate(data.Options.ConnectionId, issue.AuthorId),
CreatorId: accountIdGen.Generate(data.Options.ConnectionId, issue.AuthorId),
CreatorName: issue.AuthorName,
LeadTimeMinutes: issue.LeadTimeMinutes,
Url: issue.Url,
Expand Down
4 changes: 2 additions & 2 deletions plugins/gitee/tasks/pr_comment_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func ConvertPullRequestComments(taskCtx core.SubTaskContext) error {
defer cursor.Close()

prIdGen := didgen.NewDomainIdGenerator(&models.GiteePullRequest{})
userIdGen := didgen.NewDomainIdGenerator(&models.GiteeAccount{})
accountIdGen := didgen.NewDomainIdGenerator(&models.GiteeAccount{})

converter, err := helper.NewDataConverter(helper.DataConverterArgs{
InputRowType: reflect.TypeOf(models.GiteePullRequestComment{}),
Expand All @@ -68,7 +68,7 @@ func ConvertPullRequestComments(taskCtx core.SubTaskContext) error {
},
PullRequestId: prIdGen.Generate(data.Options.ConnectionId, giteePullRequestComment.PullRequestId),
Body: giteePullRequestComment.Body,
UserId: userIdGen.Generate(data.Options.ConnectionId, giteePullRequestComment.AuthorUserId),
UserId: accountIdGen.Generate(data.Options.ConnectionId, giteePullRequestComment.AuthorUserId),
CreatedDate: giteePullRequestComment.GiteeCreatedAt,
CommitSha: "",
Position: 0,
Expand Down
Loading