@ -334,11 +334,7 @@ func IsOfficialReviewerTeam(ctx context.Context, issue *Issue, team *organizatio
// CreateReview creates a new review based on opts
func CreateReview ( ctx context . Context , opts CreateReviewOptions ) ( * Review , error ) {
ctx , committer , err := db . TxContext ( ctx )
if err != nil {
return nil , err
}
defer committer . Close ( )
return db . WithTx2 ( ctx , func ( ctx context . Context ) ( * Review , error ) {
sess := db . GetEngine ( ctx )
review := & Review {
@ -381,7 +377,8 @@ func CreateReview(ctx context.Context, opts CreateReviewOptions) (*Review, error
if _ , err := sess . Insert ( review ) ; err != nil {
return nil , err
}
return review , committer . Commit ( )
return review , nil
} )
}
// GetCurrentReview returns the current pending review of reviewer for given issue
@ -605,11 +602,7 @@ func DismissReview(ctx context.Context, review *Review, isDismiss bool) (err err
// InsertReviews inserts review and review comments
func InsertReviews ( ctx context . Context , reviews [ ] * Review ) error {
ctx , committer , err := db . TxContext ( ctx )
if err != nil {
return err
}
defer committer . Close ( )
return db . WithTx ( ctx , func ( ctx context . Context ) error {
sess := db . GetEngine ( ctx )
for _ , review := range reviews {
@ -645,17 +638,13 @@ func InsertReviews(ctx context.Context, reviews []*Review) error {
return err
}
}
return committer . Commit ( )
return nil
} )
}
// AddReviewRequest add a review request from one reviewer
func AddReviewRequest ( ctx context . Context , issue * Issue , reviewer , doer * user_model . User ) ( * Comment , error ) {
ctx , committer , err := db . TxContext ( ctx )
if err != nil {
return nil , err
}
defer committer . Close ( )
return db . WithTx2 ( ctx , func ( ctx context . Context ) ( * Comment , error ) {
sess := db . GetEngine ( ctx )
review , err := GetReviewByIssueIDAndUserID ( ctx , issue . ID , reviewer . ID )
@ -666,7 +655,7 @@ func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_mo
if review != nil {
// skip it when reviewer has been request to review
if review . Type == ReviewTypeRequest {
return nil , committer . Commit ( ) // still commit the transaction, or committer.Close() will rollback it, even if it's a reused transaction.
return nil , nil // still commit the transaction, or committer.Close() will rollback it, even if it's a reused transaction.
}
if issue . IsClosed {
@ -721,17 +710,13 @@ func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_mo
// func caller use the created comment to retrieve created review too.
comment . Review = review
return comment , committer . Commit ( )
return comment , nil
} )
}
// RemoveReviewRequest remove a review request from one reviewer
func RemoveReviewRequest ( ctx context . Context , issue * Issue , reviewer , doer * user_model . User ) ( * Comment , error ) {
ctx , committer , err := db . TxContext ( ctx )
if err != nil {
return nil , err
}
defer committer . Close ( )
return db . WithTx2 ( ctx , func ( ctx context . Context ) ( * Comment , error ) {
review , err := GetReviewByIssueIDAndUserID ( ctx , issue . ID , reviewer . ID )
if err != nil && ! IsErrReviewNotExist ( err ) {
return nil , err
@ -754,7 +739,7 @@ func RemoveReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user
}
}
comment , err := CreateComment ( ctx , & CreateCommentOptions {
return CreateComment ( ctx , & CreateCommentOptions {
Type : CommentTypeReviewRequest ,
Doer : doer ,
Repo : issue . Repo ,
@ -762,11 +747,7 @@ func RemoveReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user
RemovedAssignee : true , // Use RemovedAssignee as !isRequest
AssigneeID : reviewer . ID , // Use AssigneeID as reviewer ID
} )
if err != nil {
return nil , err
}
return comment , committer . Commit ( )
} )
}
// Recalculate the latest official review for reviewer
@ -787,12 +768,7 @@ func restoreLatestOfficialReview(ctx context.Context, issueID, reviewerID int64)
// AddTeamReviewRequest add a review request from one team
func AddTeamReviewRequest ( ctx context . Context , issue * Issue , reviewer * organization . Team , doer * user_model . User ) ( * Comment , error ) {
ctx , committer , err := db . TxContext ( ctx )
if err != nil {
return nil , err
}
defer committer . Close ( )
return db . WithTx2 ( ctx , func ( ctx context . Context ) ( * Comment , error ) {
review , err := GetTeamReviewerByIssueIDAndTeamID ( ctx , issue . ID , reviewer . ID )
if err != nil && ! IsErrReviewNotExist ( err ) {
return nil , err
@ -841,17 +817,13 @@ func AddTeamReviewRequest(ctx context.Context, issue *Issue, reviewer *organizat
return nil , fmt . Errorf ( "CreateComment(): %w" , err )
}
return comment , committer . Commit ( )
return comment , nil
} )
}
// RemoveTeamReviewRequest remove a review request from one team
func RemoveTeamReviewRequest ( ctx context . Context , issue * Issue , reviewer * organization . Team , doer * user_model . User ) ( * Comment , error ) {
ctx , committer , err := db . TxContext ( ctx )
if err != nil {
return nil , err
}
defer committer . Close ( )
return db . WithTx2 ( ctx , func ( ctx context . Context ) ( * Comment , error ) {
review , err := GetTeamReviewerByIssueIDAndTeamID ( ctx , issue . ID , reviewer . ID )
if err != nil && ! IsErrReviewNotExist ( err ) {
return nil , err
@ -885,7 +857,7 @@ func RemoveTeamReviewRequest(ctx context.Context, issue *Issue, reviewer *organi
}
if doer == nil {
return nil , committer . Commit ( )
return nil , nil
}
comment , err := CreateComment ( ctx , & CreateCommentOptions {
@ -900,7 +872,8 @@ func RemoveTeamReviewRequest(ctx context.Context, issue *Issue, reviewer *organi
return nil , fmt . Errorf ( "CreateComment(): %w" , err )
}
return comment , committer . Commit ( )
return comment , nil
} )
}
// MarkConversation Add or remove Conversation mark for a code comment
@ -966,12 +939,7 @@ func CanMarkConversation(ctx context.Context, issue *Issue, doer *user_model.Use
// DeleteReview delete a review and it's code comments
func DeleteReview ( ctx context . Context , r * Review ) error {
ctx , committer , err := db . TxContext ( ctx )
if err != nil {
return err
}
defer committer . Close ( )
return db . WithTx ( ctx , func ( ctx context . Context ) error {
if r . ID == 0 {
return errors . New ( "review is not allowed to be 0" )
}
@ -1019,8 +987,8 @@ func DeleteReview(ctx context.Context, r *Review) error {
return err
}
}
return committer . Commit ( )
return nil
} )
}
// GetCodeCommentsCount return count of CodeComments a Review has