diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-01-15 19:14:07 +0800 |
---|---|---|
committer | Antoine GIRARD <sapk@users.noreply.github.com> | 2020-01-15 12:14:07 +0100 |
commit | 2b3e931cde3e3d70b69202164f35fc6f2c609ade (patch) | |
tree | dd519a5741642dde99433028d0e7d0e9da7b67c9 /modules/migrations/gitea.go | |
parent | 4e566df1c694e47908e59a6db163e5a98d144b83 (diff) | |
download | gitea-2b3e931cde3e3d70b69202164f35fc6f2c609ade.tar.gz gitea-2b3e931cde3e3d70b69202164f35fc6f2c609ade.zip |
Migrate reactions when migrating repository from github (#9599)
* Migrate reactions when migrating repository from github
* fix missed sleep
* fix tests
* update reactions when external user binding
* Fix test
* fix tests
* change the copy head
* fix test
* fix migrator add/delete reaction
Diffstat (limited to 'modules/migrations/gitea.go')
-rw-r--r-- | modules/migrations/gitea.go | 90 |
1 files changed, 84 insertions, 6 deletions
diff --git a/modules/migrations/gitea.go b/modules/migrations/gitea.go index 0cffd60e84..82664d0d1a 100644 --- a/modules/migrations/gitea.go +++ b/modules/migrations/gitea.go @@ -361,7 +361,32 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error { if issue.Closed != nil { is.ClosedUnix = timeutil.TimeStamp(issue.Closed.Unix()) } - // TODO: add reactions + // add reactions + for _, reaction := range issue.Reactions { + userid, ok := g.userMap[reaction.UserID] + if !ok && tp != "" { + var err error + userid, err = models.GetUserIDByExternalUserID(tp, fmt.Sprintf("%v", reaction.UserID)) + if err != nil { + log.Error("GetUserIDByExternalUserID: %v", err) + } + if userid > 0 { + g.userMap[reaction.UserID] = userid + } + } + var res = models.Reaction{ + Type: reaction.Content, + CreatedUnix: timeutil.TimeStampNow(), + } + if userid > 0 { + res.UserID = userid + } else { + res.UserID = g.doer.ID + res.OriginalAuthorID = reaction.UserID + res.OriginalAuthor = reaction.UserName + } + is.Reactions = append(is.Reactions, &res) + } iss = append(iss, &is) } @@ -420,9 +445,34 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error { cm.OriginalAuthorID = comment.PosterID } - cms = append(cms, &cm) + // add reactions + for _, reaction := range comment.Reactions { + userid, ok := g.userMap[reaction.UserID] + if !ok && tp != "" { + var err error + userid, err = models.GetUserIDByExternalUserID(tp, fmt.Sprintf("%v", reaction.UserID)) + if err != nil { + log.Error("GetUserIDByExternalUserID: %v", err) + } + if userid > 0 { + g.userMap[reaction.UserID] = userid + } + } + var res = models.Reaction{ + Type: reaction.Content, + CreatedUnix: timeutil.TimeStampNow(), + } + if userid > 0 { + res.UserID = userid + } else { + res.UserID = g.doer.ID + res.OriginalAuthorID = reaction.UserID + res.OriginalAuthor = reaction.UserName + } + cm.Reactions = append(cm.Reactions, &res) + } - // TODO: Reactions + cms = append(cms, &cm) } return models.InsertIssueComments(cms) @@ -581,10 +631,12 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR UpdatedUnix: timeutil.TimeStamp(pr.Updated.Unix()), } + tp := g.gitServiceType.Name() + userid, ok := g.userMap[pr.PosterID] - if !ok { + if !ok && tp != "" { var err error - userid, err = models.GetUserIDByExternalUserID("github", fmt.Sprintf("%v", pr.PosterID)) + userid, err = models.GetUserIDByExternalUserID(tp, fmt.Sprintf("%v", pr.PosterID)) if err != nil { log.Error("GetUserIDByExternalUserID: %v", err) } @@ -601,6 +653,33 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR issue.OriginalAuthorID = pr.PosterID } + // add reactions + for _, reaction := range pr.Reactions { + userid, ok := g.userMap[reaction.UserID] + if !ok && tp != "" { + var err error + userid, err = models.GetUserIDByExternalUserID(tp, fmt.Sprintf("%v", reaction.UserID)) + if err != nil { + log.Error("GetUserIDByExternalUserID: %v", err) + } + if userid > 0 { + g.userMap[reaction.UserID] = userid + } + } + var res = models.Reaction{ + Type: reaction.Content, + CreatedUnix: timeutil.TimeStampNow(), + } + if userid > 0 { + res.UserID = userid + } else { + res.UserID = g.doer.ID + res.OriginalAuthorID = reaction.UserID + res.OriginalAuthor = reaction.UserName + } + issue.Reactions = append(issue.Reactions, &res) + } + var pullRequest = models.PullRequest{ HeadRepoID: g.repo.ID, HeadBranch: head, @@ -622,7 +701,6 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR pullRequest.MergerID = g.doer.ID } - // TODO: reactions // TODO: assignees return &pullRequest, nil |