Skip to content

Commit cf6d398

Browse files
authored
Resolve TODO: Enable pagination on GiteaDownloader.GetComments() & update another TODO (#16963)
* Update TODO in migrations * Resolve TODO: enable pagination on GiteaDownloader.GetComments()
1 parent a807031 commit cf6d398

File tree

2 files changed

+37
-41
lines changed

2 files changed

+37
-41
lines changed

modules/migrations/gitea_downloader.go

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -459,49 +459,48 @@ func (g *GiteaDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, err
459459
func (g *GiteaDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) {
460460
var allComments = make([]*base.Comment, 0, g.maxPerPage)
461461

462-
// for i := 1; ; i++ {
463-
// make sure gitea can shutdown gracefully
464-
select {
465-
case <-g.ctx.Done():
466-
return nil, false, nil
467-
default:
468-
}
469-
470-
comments, _, err := g.client.ListIssueComments(g.repoOwner, g.repoName, opts.Context.ForeignID(), gitea_sdk.ListIssueCommentOptions{ListOptions: gitea_sdk.ListOptions{
471-
// PageSize: g.maxPerPage,
472-
// Page: i,
473-
}})
474-
if err != nil {
475-
return nil, false, fmt.Errorf("error while listing comments for issue #%d. Error: %v", opts.Context.ForeignID(), err)
476-
}
462+
for i := 1; ; i++ {
463+
// make sure gitea can shutdown gracefully
464+
select {
465+
case <-g.ctx.Done():
466+
return nil, false, nil
467+
default:
468+
}
477469

478-
for _, comment := range comments {
479-
reactions, err := g.getCommentReactions(comment.ID)
470+
comments, _, err := g.client.ListIssueComments(g.repoOwner, g.repoName, opts.Context.ForeignID(), gitea_sdk.ListIssueCommentOptions{ListOptions: gitea_sdk.ListOptions{
471+
PageSize: g.maxPerPage,
472+
Page: i,
473+
}})
480474
if err != nil {
481-
log.Warn("Unable to load comment reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", opts.Context.ForeignID(), comment.ID, g.repoOwner, g.repoName, err)
482-
if err2 := models.CreateRepositoryNotice(
483-
fmt.Sprintf("Unable to load reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", opts.Context.ForeignID(), comment.ID, g.repoOwner, g.repoName, err)); err2 != nil {
484-
log.Error("create repository notice failed: ", err2)
475+
return nil, false, fmt.Errorf("error while listing comments for issue #%d. Error: %v", opts.Context.ForeignID(), err)
476+
}
477+
478+
for _, comment := range comments {
479+
reactions, err := g.getCommentReactions(comment.ID)
480+
if err != nil {
481+
log.Warn("Unable to load comment reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", opts.Context.ForeignID(), comment.ID, g.repoOwner, g.repoName, err)
482+
if err2 := models.CreateRepositoryNotice(
483+
fmt.Sprintf("Unable to load reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", opts.Context.ForeignID(), comment.ID, g.repoOwner, g.repoName, err)); err2 != nil {
484+
log.Error("create repository notice failed: ", err2)
485+
}
485486
}
487+
488+
allComments = append(allComments, &base.Comment{
489+
IssueIndex: opts.Context.LocalID(),
490+
PosterID: comment.Poster.ID,
491+
PosterName: comment.Poster.UserName,
492+
PosterEmail: comment.Poster.Email,
493+
Content: comment.Body,
494+
Created: comment.Created,
495+
Updated: comment.Updated,
496+
Reactions: reactions,
497+
})
486498
}
487499

488-
allComments = append(allComments, &base.Comment{
489-
IssueIndex: opts.Context.LocalID(),
490-
PosterID: comment.Poster.ID,
491-
PosterName: comment.Poster.UserName,
492-
PosterEmail: comment.Poster.Email,
493-
Content: comment.Body,
494-
Created: comment.Created,
495-
Updated: comment.Updated,
496-
Reactions: reactions,
497-
})
500+
if !g.pagination || len(comments) < g.maxPerPage {
501+
break
502+
}
498503
}
499-
500-
// TODO enable pagination vor (gitea >= 1.14) when it got implemented
501-
// if !g.pagination || len(comments) < g.maxPerPage {
502-
// break
503-
// }
504-
//}
505504
return allComments, true, nil
506505
}
507506

modules/migrations/migrate.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,7 @@ func Init() error {
475475
return nil
476476
}
477477

478-
// isIPPrivate reports whether ip is a private address, according to
479-
// RFC 1918 (IPv4 addresses) and RFC 4193 (IPv6 addresses).
480-
// from https://github.com/golang/go/pull/42793
481-
// TODO remove if https://github.com/golang/go/issues/29146 got resolved
478+
// TODO: replace with `ip.IsPrivate()` if min go version is bumped to 1.17
482479
func isIPPrivate(ip net.IP) bool {
483480
if ip4 := ip.To4(); ip4 != nil {
484481
return ip4[0] == 10 ||

0 commit comments

Comments
 (0)