mirror of https://github.com/go-gitea/gitea
Add OriginalID to reviews and review comments
This commit is contained in:
parent
f7e94224d6
commit
328fdafdca
|
@ -111,6 +111,7 @@ type Review struct {
|
|||
ReviewerTeam *organization.Team `xorm:"-"`
|
||||
OriginalAuthor string
|
||||
OriginalAuthorID int64
|
||||
OriginalID int64
|
||||
Issue *Issue `xorm:"-"`
|
||||
IssueID int64 `xorm:"index"`
|
||||
Content string `xorm:"TEXT"`
|
||||
|
@ -557,7 +558,7 @@ func UpsertReviews(reviews []*Review) error {
|
|||
sess := db.GetEngine(ctx)
|
||||
|
||||
for _, review := range reviews {
|
||||
exists, err := sess.Where("issue_id = ? AND created_unix", review.IssueID, review.CreatedUnix).Exist(&Review{})
|
||||
exists, err := sess.Where("original_id = ?", review.OriginalID).Exist(&Review{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -581,12 +582,12 @@ func UpsertReviews(reviews []*Review) error {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if _, err = sess.NoAutoTime().Where("issue_id = ? AND created_unix = ?", review.IssueID, review.CreatedUnix).Update(review); err != nil {
|
||||
if _, err = sess.NoAutoTime().Where("original_id = ?", review.OriginalID).Update(review); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get id of the review
|
||||
if err = sess.NoAutoTime().Where("issue_id = ? AND created_unix = ?", review.IssueID, review.CreatedUnix).Find(review); err != nil {
|
||||
if err = sess.NoAutoTime().Where("original_id = ?", review.OriginalID).Find(review); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -601,7 +602,7 @@ func UpsertReviews(reviews []*Review) error {
|
|||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := sess.NoAutoTime().Where("review_id = ? AND created_unix = ?", review.ID, comment.CreatedUnix).Update(comment); err != nil {
|
||||
if _, err := sess.NoAutoTime().Where("original_id = ?", comment.OriginalID).Update(comment); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -622,7 +623,7 @@ func UpsertReviews(reviews []*Review) error {
|
|||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := sess.NoAutoTime().Where("review_id = ? AND created_unix = ?", review.ID, comment.CreatedUnix).Update(comment); err != nil {
|
||||
if _, err := sess.NoAutoTime().Where("original_id = ?", comment.OriginalID).Update(comment); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -635,7 +636,7 @@ func UpsertReviews(reviews []*Review) error {
|
|||
}
|
||||
|
||||
func existsCommentByReviewIDAndCreatedUnix(sess db.Engine, comment *Comment) (bool, error) {
|
||||
return sess.Where("review_id = ? AND created_unix = ?", comment.ReviewID, comment.CreatedUnix).Exist(&Comment{})
|
||||
return sess.Where("original_id = ?", comment.OriginalID).Exist(&Comment{})
|
||||
}
|
||||
|
||||
func generateCommentFromReview(review *Review) *Comment {
|
||||
|
@ -649,6 +650,7 @@ func generateCommentFromReview(review *Review) *Comment {
|
|||
ReviewID: review.ID,
|
||||
CreatedUnix: review.CreatedUnix,
|
||||
UpdatedUnix: review.UpdatedUnix,
|
||||
OriginalID: review.OriginalID,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -366,7 +366,7 @@ func UpsertIssueComments(comments []*issues_model.Comment) error {
|
|||
}
|
||||
|
||||
for issueID := range issueIDs {
|
||||
if _, err := db.Exec(ctx, "UPDATE issue set num_comments = (SELECT count(*) FROM comment WHERE issue_id = ? AND `type`=?) WHERE id = ?",
|
||||
if _, err := db.Exec(ctx, "UPDATE issue SET num_comments = (SELECT count(*) FROM comment WHERE issue_id = ? AND `type`=?) WHERE id = ?",
|
||||
issueID, issues_model.CommentTypeComment, issueID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ type Review struct {
|
|||
CreatedAt time.Time `yaml:"created_at"`
|
||||
State string // PENDING, APPROVED, REQUEST_CHANGES, or COMMENT
|
||||
Comments []*ReviewComment
|
||||
OriginalID int64
|
||||
}
|
||||
|
||||
// GetExternalName ExternalUserMigrated interface
|
||||
|
@ -52,16 +53,17 @@ func (r *Review) GetExternalID() int64 { return r.ReviewerID }
|
|||
|
||||
// ReviewComment represents a review comment
|
||||
type ReviewComment struct {
|
||||
ID int64
|
||||
InReplyTo int64 `yaml:"in_reply_to"`
|
||||
Content string
|
||||
TreePath string `yaml:"tree_path"`
|
||||
DiffHunk string `yaml:"diff_hunk"`
|
||||
Position int
|
||||
Line int
|
||||
CommitID string `yaml:"commit_id"`
|
||||
PosterID int64 `yaml:"poster_id"`
|
||||
Reactions []*Reaction
|
||||
CreatedAt time.Time `yaml:"created_at"`
|
||||
UpdatedAt time.Time `yaml:"updated_at"`
|
||||
ID int64
|
||||
InReplyTo int64 `yaml:"in_reply_to"`
|
||||
Content string
|
||||
TreePath string `yaml:"tree_path"`
|
||||
DiffHunk string `yaml:"diff_hunk"`
|
||||
Position int
|
||||
Line int
|
||||
CommitID string `yaml:"commit_id"`
|
||||
PosterID int64 `yaml:"poster_id"`
|
||||
Reactions []*Reaction
|
||||
CreatedAt time.Time `yaml:"created_at"`
|
||||
UpdatedAt time.Time `yaml:"updated_at"`
|
||||
OriginalID int64
|
||||
}
|
||||
|
|
|
@ -883,6 +883,7 @@ func (g *GiteaLocalUploader) prepareReviews(reviews ...*base.Review) ([]*issues_
|
|||
Official: review.Official,
|
||||
CreatedUnix: timeutil.TimeStamp(review.CreatedAt.Unix()),
|
||||
UpdatedUnix: timeutil.TimeStamp(review.CreatedAt.Unix()),
|
||||
OriginalID: review.OriginalID,
|
||||
}
|
||||
|
||||
if err := g.remapUser(review, &cm); err != nil {
|
||||
|
@ -902,7 +903,7 @@ func (g *GiteaLocalUploader) prepareReviews(reviews ...*base.Review) ([]*issues_
|
|||
g.prCache[issue.ID] = pr
|
||||
}
|
||||
if pr.MergeBase == "" {
|
||||
// No mergebase -> no basis for any patches
|
||||
// No merge base -> no basis for any patches
|
||||
log.Warn("PR #%d in %s/%s: does not have a merge base, all review comments will be ignored", pr.Index, g.repoOwner, g.repoName)
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -596,6 +596,7 @@ func (g *GithubDownloaderV3) convertGithubReview(r *github.PullRequestReview) *b
|
|||
Content: r.GetBody(),
|
||||
CreatedAt: r.GetSubmittedAt().Time,
|
||||
State: r.GetState(),
|
||||
OriginalID: r.GetID(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -629,17 +630,18 @@ func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullReques
|
|||
}
|
||||
|
||||
rcs = append(rcs, &base.ReviewComment{
|
||||
ID: c.GetID(),
|
||||
InReplyTo: c.GetInReplyTo(),
|
||||
Content: c.GetBody(),
|
||||
TreePath: c.GetPath(),
|
||||
DiffHunk: c.GetDiffHunk(),
|
||||
Position: c.GetPosition(),
|
||||
CommitID: c.GetCommitID(),
|
||||
PosterID: c.GetUser().GetID(),
|
||||
Reactions: reactions,
|
||||
CreatedAt: c.GetCreatedAt().Time,
|
||||
UpdatedAt: c.GetUpdatedAt().Time,
|
||||
ID: c.GetID(),
|
||||
InReplyTo: c.GetInReplyTo(),
|
||||
Content: c.GetBody(),
|
||||
TreePath: c.GetPath(),
|
||||
DiffHunk: c.GetDiffHunk(),
|
||||
Position: c.GetPosition(),
|
||||
CommitID: c.GetCommitID(),
|
||||
PosterID: c.GetUser().GetID(),
|
||||
Reactions: reactions,
|
||||
CreatedAt: c.GetCreatedAt().Time,
|
||||
UpdatedAt: c.GetUpdatedAt().Time,
|
||||
OriginalID: c.GetID(),
|
||||
})
|
||||
}
|
||||
return rcs, nil
|
||||
|
|
Loading…
Reference in New Issue