forked from forgejo/forgejo
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
This commit is contained in:
parent
4e566df1c6
commit
2b3e931cde
18 changed files with 329 additions and 101 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue