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
This commit is contained in:
Lunny Xiao
2020-01-24 01:28:15 +08:00
committed by Lauris BH
parent bfdfa9a8b3
commit f6067a8465
18 changed files with 567 additions and 32 deletions

View File

@ -45,13 +45,15 @@ func (rt ReviewType) Icon() string {
// Review represents collection of code comments giving feedback for a PR
type Review struct {
ID int64 `xorm:"pk autoincr"`
Type ReviewType
Reviewer *User `xorm:"-"`
ReviewerID int64 `xorm:"index"`
Issue *Issue `xorm:"-"`
IssueID int64 `xorm:"index"`
Content string `xorm:"TEXT"`
ID int64 `xorm:"pk autoincr"`
Type ReviewType
Reviewer *User `xorm:"-"`
ReviewerID int64 `xorm:"index"`
OriginalAuthor string
OriginalAuthorID int64
Issue *Issue `xorm:"-"`
IssueID int64 `xorm:"index"`
Content string `xorm:"TEXT"`
// Official is a review made by an assigned approver (counts towards approval)
Official bool `xorm:"NOT NULL DEFAULT false"`
CommitID string `xorm:"VARCHAR(40)"`
@ -62,6 +64,8 @@ type Review struct {
// CodeComments are the initial code comments of the review
CodeComments CodeComments `xorm:"-"`
Comments []*Comment `xorm:"-"`
}
func (r *Review) loadCodeComments(e Engine) (err error) {
@ -398,3 +402,43 @@ func MarkReviewsAsNotStale(issueID int64, commitID string) (err error) {
return
}
// InsertReviews inserts review and review comments
func InsertReviews(reviews []*Review) error {
sess := x.NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}
for _, review := range reviews {
if _, err := sess.NoAutoTime().Insert(review); err != nil {
return err
}
if _, err := sess.NoAutoTime().Insert(&Comment{
Type: CommentTypeReview,
Content: review.Content,
PosterID: review.ReviewerID,
OriginalAuthor: review.OriginalAuthor,
OriginalAuthorID: review.OriginalAuthorID,
IssueID: review.IssueID,
ReviewID: review.ID,
CreatedUnix: review.CreatedUnix,
UpdatedUnix: review.UpdatedUnix,
}); err != nil {
return err
}
for _, c := range review.Comments {
c.ReviewID = review.ID
}
if _, err := sess.NoAutoTime().Insert(review.Comments); err != nil {
return err
}
}
return sess.Commit()
}