diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-01-24 01:28:15 +0800 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2020-01-23 19:28:15 +0200 |
commit | f6067a8465e7762aea1561106cfee291409a0fd6 (patch) | |
tree | 35c97d4117acfe52dce32c9242e4c9a656c4bc6c /modules/migrations/migrate.go | |
parent | bfdfa9a8b32ae331f98137169693ba1d71c25b09 (diff) | |
download | gitea-f6067a8465e7762aea1561106cfee291409a0fd6.tar.gz gitea-f6067a8465e7762aea1561106cfee291409a0fd6.zip |
Migrate reviews when migrating repository from github (#9463)
* fix typo
* Migrate reviews when migrating repository from github
* fix lint
* Added test and migration when external user login
* fix test
* fix commented state
* Some improvements
* fix bug when get pull request and ref original author on code comments
* Fix migrated line; Added comment for review
* Don't load all pull requests attributes
* Fix typo
* wrong change copy head
* fix tests
* fix reactions
* Fix test
* fix fmt
* fix review comment reactions
Diffstat (limited to 'modules/migrations/migrate.go')
-rw-r--r-- | modules/migrations/migrate.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/modules/migrations/migrate.go b/modules/migrations/migrate.go index fb143f7e29..3b3e318f69 100644 --- a/modules/migrations/migrate.go +++ b/modules/migrations/migrate.go @@ -181,7 +181,10 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts } } - var commentBatchSize = uploader.MaxBatchInsertSize("comment") + var ( + commentBatchSize = uploader.MaxBatchInsertSize("comment") + reviewBatchSize = uploader.MaxBatchInsertSize("review") + ) if opts.Issues { log.Trace("migrating issues and comments") @@ -248,6 +251,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts continue } + // plain comments var allComments = make([]*base.Comment, 0, commentBatchSize) for _, pr := range prs { comments, err := downloader.GetComments(pr.Number) @@ -270,6 +274,29 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts } } + // migrate reviews + var allReviews = make([]*base.Review, 0, reviewBatchSize) + for _, pr := range prs { + reviews, err := downloader.GetReviews(pr.Number) + if err != nil { + return err + } + + allReviews = append(allReviews, reviews...) + + if len(allReviews) >= reviewBatchSize { + if err := uploader.CreateReviews(allReviews[:reviewBatchSize]...); err != nil { + return err + } + allReviews = allReviews[reviewBatchSize:] + } + } + if len(allReviews) > 0 { + if err := uploader.CreateReviews(allReviews...); err != nil { + return err + } + } + if len(prs) < prBatchSize { break } |