fix code review on mssql (#5502)
This commit is contained in:
parent
8a64e67456
commit
284b0e12cb
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
"github.com/go-xorm/core"
|
||||||
"github.com/go-xorm/xorm"
|
"github.com/go-xorm/xorm"
|
||||||
|
|
||||||
"github.com/go-xorm/builder"
|
"github.com/go-xorm/builder"
|
||||||
|
@ -266,13 +267,24 @@ type PullReviewersWithType struct {
|
||||||
// GetReviewersByPullID gets all reviewers for a pull request with the statuses
|
// GetReviewersByPullID gets all reviewers for a pull request with the statuses
|
||||||
func GetReviewersByPullID(pullID int64) (issueReviewers []*PullReviewersWithType, err error) {
|
func GetReviewersByPullID(pullID int64) (issueReviewers []*PullReviewersWithType, err error) {
|
||||||
irs := []*PullReviewersWithType{}
|
irs := []*PullReviewersWithType{}
|
||||||
err = x.Select("`user`.*, review.type, max(review.updated_unix) as review_updated_unix").
|
if x.Dialect().DBType() == core.MSSQL {
|
||||||
Table("review").
|
err = x.SQL(`SELECT [user].*, review.type, review.review_updated_unix FROM
|
||||||
Join("INNER", "`user`", "review.reviewer_id = `user`.id").
|
(SELECT review.id, review.type, review.reviewer_id, max(review.updated_unix) as review_updated_unix
|
||||||
Where("review.issue_id = ? AND (review.type = ? OR review.type = ?)", pullID, ReviewTypeApprove, ReviewTypeReject).
|
FROM review WHERE review.issue_id=? AND (review.type = ? OR review.type = ?)
|
||||||
GroupBy("`user`.id, review.type").
|
GROUP BY review.id, review.type, review.reviewer_id) as review
|
||||||
OrderBy("review_updated_unix DESC").
|
INNER JOIN [user] ON review.reviewer_id = [user].id ORDER BY review_updated_unix DESC`,
|
||||||
Find(&irs)
|
pullID, ReviewTypeApprove, ReviewTypeReject).
|
||||||
|
Find(&irs)
|
||||||
|
} else {
|
||||||
|
err = x.Select("`user`.*, review.type, max(review.updated_unix) as review_updated_unix").
|
||||||
|
Table("review").
|
||||||
|
Join("INNER", "`user`", "review.reviewer_id = `user`.id").
|
||||||
|
Where("review.issue_id = ? AND (review.type = ? OR review.type = ?)",
|
||||||
|
pullID, ReviewTypeApprove, ReviewTypeReject).
|
||||||
|
GroupBy("`user`.id, review.type").
|
||||||
|
OrderBy("review_updated_unix DESC").
|
||||||
|
Find(&irs)
|
||||||
|
}
|
||||||
|
|
||||||
// We need to group our results by user id _and_ review type, otherwise the query fails when using postgresql.
|
// We need to group our results by user id _and_ review type, otherwise the query fails when using postgresql.
|
||||||
// But becaus we're doing this, we need to manually filter out multiple reviews of different types by the
|
// But becaus we're doing this, we need to manually filter out multiple reviews of different types by the
|
||||||
|
|
Loading…
Reference in New Issue