From 2a602560de1f5a162f8deb9e3a26056ee320cfc1 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Thu, 8 Sep 2022 15:13:38 -0400 Subject: [PATCH 1/3] Higher fidelity imports --- modules/migration/comment.go | 2 ++ services/migrations/gitea_uploader.go | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/migration/comment.go b/modules/migration/comment.go index 0447689b74cd6..2ba064af8638d 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 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{} // 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..31d63cde3f08d 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -462,15 +462,28 @@ 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: + // TODO: add label to issue + case issues_model.CommentTypeAssignees: + // TODO: add assignee to issue + case issues_model.CommentTypeChangeTitle: + // TODO: change issue title + default: + } + if err := g.remapUser(comment, &cm); err != nil { return err } From 22709c77baa2324081cca04b41f04be2ee866b82 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Thu, 8 Sep 2022 20:27:38 -0400 Subject: [PATCH 2/3] use meta information from yaml --- services/migrations/gitea_uploader.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index 31d63cde3f08d..0d4004a2d72a9 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -476,11 +476,16 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error { switch issues_model.CommentType(comment.CommentType) { case issues_model.CommentTypeLabel: - // TODO: add label to issue + 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: - // TODO: add assignee to issue + cm.AssigneeID = comment.Meta["AssigneeID"].(int64) + if comment.Meta["RemovedAssigneeID"] != nil { + cm.RemovedAssignee = true + } case issues_model.CommentTypeChangeTitle: - // TODO: change issue title + cm.OldTitle = comment.Meta["OldTitle"].(string) + cm.NewTitle = comment.Meta["NewTitle"].(string) default: } From 234293f5f35f6763cad963231eb2d61fa56528e6 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 26 Sep 2022 20:30:38 -0400 Subject: [PATCH 3/3] nil check --- modules/migration/comment.go | 4 ++-- services/migrations/gitea_uploader.go | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/migration/comment.go b/modules/migration/comment.go index 2ba064af8638d..fa24d81390495 100644 --- a/modules/migration/comment.go +++ b/modules/migration/comment.go @@ -18,7 +18,7 @@ type Commentable interface { type Comment struct { IssueIndex int64 `yaml:"issue_index"` Index int64 - CommentType int64 + CommentType int64 `yaml:"comment_type"` PosterID int64 `yaml:"poster_id"` PosterName string `yaml:"poster_name"` PosterEmail string `yaml:"poster_email"` @@ -26,7 +26,7 @@ type Comment struct { Updated time.Time Content string Reactions []*Reaction - Meta map[string]interface{} // see models/issues/comment.go for fields in Comment struct + 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 0d4004a2d72a9..1ae3718dc5257 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -484,8 +484,12 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error { cm.RemovedAssignee = true } case issues_model.CommentTypeChangeTitle: - cm.OldTitle = comment.Meta["OldTitle"].(string) - cm.NewTitle = comment.Meta["NewTitle"].(string) + 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: }