Skip to content

Commit 1f72656

Browse files
authored
Migration not fail on notmigrated reactions (#13507)
* Refactor: dedub code * skip Reactions with Invalid ID
1 parent 5a32224 commit 1f72656

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

modules/migrations/gitea_downloader.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,45 +326,44 @@ func (g *GiteaDownloader) GetAsset(_ string, relID, id int64) (io.ReadCloser, er
326326
}
327327

328328
func (g *GiteaDownloader) getIssueReactions(index int64) ([]*base.Reaction, error) {
329-
var reactions []*base.Reaction
330329
if err := g.client.CheckServerVersionConstraint(">=1.11"); err != nil {
331330
log.Info("GiteaDownloader: instance to old, skip getIssueReactions")
332-
return reactions, nil
331+
return []*base.Reaction{}, nil
333332
}
334333
rl, _, err := g.client.GetIssueReactions(g.repoOwner, g.repoName, index)
335334
if err != nil {
336335
return nil, err
337336
}
338337

339-
for _, reaction := range rl {
340-
reactions = append(reactions, &base.Reaction{
341-
UserID: reaction.User.ID,
342-
UserName: reaction.User.UserName,
343-
Content: reaction.Reaction,
344-
})
345-
}
346-
return reactions, nil
338+
return g.convertReactions(rl), nil
347339
}
348340

349341
func (g *GiteaDownloader) getCommentReactions(commentID int64) ([]*base.Reaction, error) {
350-
var reactions []*base.Reaction
351342
if err := g.client.CheckServerVersionConstraint(">=1.11"); err != nil {
352343
log.Info("GiteaDownloader: instance to old, skip getCommentReactions")
353-
return reactions, nil
344+
return []*base.Reaction{}, nil
354345
}
355346
rl, _, err := g.client.GetIssueCommentReactions(g.repoOwner, g.repoName, commentID)
356347
if err != nil {
357348
return nil, err
358349
}
359350

351+
return g.convertReactions(rl), nil
352+
}
353+
354+
func (g *GiteaDownloader) convertReactions(rl []*gitea_sdk.Reaction) []*base.Reaction {
355+
var reactions []*base.Reaction
360356
for i := range rl {
357+
if rl[i].User.ID <= 0 {
358+
continue
359+
}
361360
reactions = append(reactions, &base.Reaction{
362361
UserID: rl[i].User.ID,
363362
UserName: rl[i].User.UserName,
364363
Content: rl[i].Reaction,
365364
})
366365
}
367-
return reactions, nil
366+
return reactions
368367
}
369368

370369
// GetIssues returns issues according start and limit

0 commit comments

Comments
 (0)