summaryrefslogtreecommitdiffstats
path: root/models/review.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-19 21:39:57 +0800
committerGitHub <noreply@github.com>2021-11-19 21:39:57 +0800
commitfc3d0826096943b979717ed46c9a4cfd86e06106 (patch)
tree3143882ccf4dea3a8bf2a0de9c8da9a4efec26ce /models/review.go
parent7a0347315995b25bcb2dca4786504fb699b5f004 (diff)
downloadgitea-fc3d0826096943b979717ed46c9a4cfd86e06106.tar.gz
gitea-fc3d0826096943b979717ed46c9a4cfd86e06106.zip
Move attachment into models/repo/ (#17650)
* Move attachment into models/repo/ * Fix test * Fix bug
Diffstat (limited to 'models/review.go')
-rw-r--r--models/review.go57
1 files changed, 31 insertions, 26 deletions
diff --git a/models/review.go b/models/review.go
index ab275ecb26..62172bac01 100644
--- a/models/review.go
+++ b/models/review.go
@@ -359,11 +359,12 @@ func IsContentEmptyErr(err error) bool {
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content, commitID string, stale bool, attachmentUUIDs []string) (*Review, *Comment, error) {
- sess := db.NewSession(db.DefaultContext)
- defer sess.Close()
- if err := sess.Begin(); err != nil {
+ ctx, committer, err := db.TxContext()
+ if err != nil {
return nil, nil, err
}
+ defer committer.Close()
+ sess := db.GetEngine(ctx)
official := false
@@ -429,7 +430,7 @@ func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content, comm
}
}
- comm, err := createComment(sess, &CreateCommentOptions{
+ comm, err := createComment(ctx, &CreateCommentOptions{
Type: CommentTypeReview,
Doer: doer,
Content: review.Content,
@@ -464,7 +465,7 @@ func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content, comm
}
comm.Review = review
- return review, comm, sess.Commit()
+ return review, comm, committer.Commit()
}
// GetReviewersByIssueID gets the latest review of each reviewer for a pull request
@@ -631,11 +632,12 @@ func InsertReviews(reviews []*Review) error {
// AddReviewRequest add a review request from one reviewer
func AddReviewRequest(issue *Issue, reviewer, doer *User) (*Comment, error) {
- sess := db.NewSession(db.DefaultContext)
- defer sess.Close()
- if err := sess.Begin(); err != nil {
+ ctx, committer, err := db.TxContext()
+ if err != nil {
return nil, err
}
+ defer committer.Close()
+ sess := db.GetEngine(ctx)
review, err := getReviewByIssueIDAndUserID(sess, issue.ID, reviewer.ID)
if err != nil && !IsErrReviewNotExist(err) {
@@ -667,7 +669,7 @@ func AddReviewRequest(issue *Issue, reviewer, doer *User) (*Comment, error) {
return nil, err
}
- comment, err := createComment(sess, &CreateCommentOptions{
+ comment, err := createComment(ctx, &CreateCommentOptions{
Type: CommentTypeReviewRequest,
Doer: doer,
Repo: issue.Repo,
@@ -680,16 +682,17 @@ func AddReviewRequest(issue *Issue, reviewer, doer *User) (*Comment, error) {
return nil, err
}
- return comment, sess.Commit()
+ return comment, committer.Commit()
}
// RemoveReviewRequest remove a review request from one reviewer
func RemoveReviewRequest(issue *Issue, reviewer, doer *User) (*Comment, error) {
- sess := db.NewSession(db.DefaultContext)
- defer sess.Close()
- if err := sess.Begin(); err != nil {
+ ctx, committer, err := db.TxContext()
+ if err != nil {
return nil, err
}
+ defer committer.Close()
+ sess := db.GetEngine(ctx)
review, err := getReviewByIssueIDAndUserID(sess, issue.ID, reviewer.ID)
if err != nil && !IsErrReviewNotExist(err) {
@@ -721,7 +724,7 @@ func RemoveReviewRequest(issue *Issue, reviewer, doer *User) (*Comment, error) {
}
}
- comment, err := createComment(sess, &CreateCommentOptions{
+ comment, err := createComment(ctx, &CreateCommentOptions{
Type: CommentTypeReviewRequest,
Doer: doer,
Repo: issue.Repo,
@@ -733,16 +736,17 @@ func RemoveReviewRequest(issue *Issue, reviewer, doer *User) (*Comment, error) {
return nil, err
}
- return comment, sess.Commit()
+ return comment, committer.Commit()
}
// AddTeamReviewRequest add a review request from one team
func AddTeamReviewRequest(issue *Issue, reviewer *Team, doer *User) (*Comment, error) {
- sess := db.NewSession(db.DefaultContext)
- defer sess.Close()
- if err := sess.Begin(); err != nil {
+ ctx, committer, err := db.TxContext()
+ if err != nil {
return nil, err
}
+ defer committer.Close()
+ sess := db.GetEngine(ctx)
review, err := getTeamReviewerByIssueIDAndTeamID(sess, issue.ID, reviewer.ID)
if err != nil && !IsErrReviewNotExist(err) {
@@ -779,7 +783,7 @@ func AddTeamReviewRequest(issue *Issue, reviewer *Team, doer *User) (*Comment, e
}
}
- comment, err := createComment(sess, &CreateCommentOptions{
+ comment, err := createComment(ctx, &CreateCommentOptions{
Type: CommentTypeReviewRequest,
Doer: doer,
Repo: issue.Repo,
@@ -792,16 +796,17 @@ func AddTeamReviewRequest(issue *Issue, reviewer *Team, doer *User) (*Comment, e
return nil, fmt.Errorf("createComment(): %v", err)
}
- return comment, sess.Commit()
+ return comment, committer.Commit()
}
// RemoveTeamReviewRequest remove a review request from one team
func RemoveTeamReviewRequest(issue *Issue, reviewer *Team, doer *User) (*Comment, error) {
- sess := db.NewSession(db.DefaultContext)
- defer sess.Close()
- if err := sess.Begin(); err != nil {
+ ctx, committer, err := db.TxContext()
+ if err != nil {
return nil, err
}
+ defer committer.Close()
+ sess := db.GetEngine(ctx)
review, err := getTeamReviewerByIssueIDAndTeamID(sess, issue.ID, reviewer.ID)
if err != nil && !IsErrReviewNotExist(err) {
@@ -836,10 +841,10 @@ func RemoveTeamReviewRequest(issue *Issue, reviewer *Team, doer *User) (*Comment
}
if doer == nil {
- return nil, sess.Commit()
+ return nil, committer.Commit()
}
- comment, err := createComment(sess, &CreateCommentOptions{
+ comment, err := createComment(ctx, &CreateCommentOptions{
Type: CommentTypeReviewRequest,
Doer: doer,
Repo: issue.Repo,
@@ -851,7 +856,7 @@ func RemoveTeamReviewRequest(issue *Issue, reviewer *Team, doer *User) (*Comment
return nil, fmt.Errorf("createComment(): %v", err)
}
- return comment, sess.Commit()
+ return comment, committer.Commit()
}
// MarkConversation Add or remove Conversation mark for a code comment