diff --git a/modules/migration/comment.go b/modules/migration/comment.go index 0447689b74cd6..fa24d81390495 100644 --- a/modules/migration/comment.go +++ b/modules/migration/comment.go @@ -18,6 +18,7 @@ type Commentable interface { type Comment struct { IssueIndex int64 `yaml:"issue_index"` Index int64 + CommentType int64 `yaml:"comment_type"` PosterID int64 `yaml:"poster_id"` PosterName string `yaml:"poster_name"` PosterEmail string `yaml:"poster_email"` @@ -25,6 +26,7 @@ type Comment struct { Updated time.Time Content string Reactions []*Reaction + Meta map[string]interface{} `yaml:"meta,omitempty"` // see models/issues/comment.go for fields in Comment struct } // GetExternalName ExternalUserMigrated interface diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index 5bf77e6332146..1ae3718dc5257 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -462,15 +462,37 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error { if comment.Updated.IsZero() { comment.Updated = comment.Created } - + if comment.CommentType == 0 { + // if type field is missing, then assume a normal comment + comment.CommentType = int64(issues_model.CommentTypeComment) + } cm := issues_model.Comment{ IssueID: issue.ID, - Type: issues_model.CommentTypeComment, + Type: issues_model.CommentType(comment.CommentType), Content: comment.Content, CreatedUnix: timeutil.TimeStamp(comment.Created.Unix()), UpdatedUnix: timeutil.TimeStamp(comment.Updated.Unix()), } + switch issues_model.CommentType(comment.CommentType) { + case issues_model.CommentTypeLabel: + cm.LabelID = comment.Meta["LabelID"].(int64) + // Note: if you want to add a label, you'll need to set content to value "1" + case issues_model.CommentTypeAssignees: + cm.AssigneeID = comment.Meta["AssigneeID"].(int64) + if comment.Meta["RemovedAssigneeID"] != nil { + cm.RemovedAssignee = true + } + case issues_model.CommentTypeChangeTitle: + if comment.Meta["OldTitle"] != nil { + cm.OldTitle = fmt.Sprintf("%s", comment.Meta["OldTitle"]) + } + if comment.Meta["NewTitle"] != nil { + cm.NewTitle = fmt.Sprintf("%s", comment.Meta["NewTitle"]) + } + default: + } + if err := g.remapUser(comment, &cm); err != nil { return err }